Skip to main content

Mental Model

graph-tool-call is a retrieval and planning engine for large tool catalogs.

It does not replace the LLM. It prepares the tool surface so the LLM sees a smaller, better ranked, and better explained set of choices.

The Core Problem

Large tool catalogs fail for predictable reasons:

  • the LLM receives too many loosely described tools
  • similar operations have weak action and resource metadata
  • request and response schemas are not converted into usable contracts
  • the correct tool is in Top-K but the final target selection drifts
  • missing fields are discovered only after execution starts
  • auth, request, API, and cleanup failures are mixed together
  • successful retries are not fed back into future search

graph-tool-call turns the catalog into inspectable evidence before the LLM acts.

Pipeline

source
-> ingest
-> contract extraction
-> semantic build
-> graph build
-> retrieval
-> target selection
-> plan synthesis
-> runner events
-> trace learning

Each stage creates an artifact that can be stored, inspected, tested, and passed to a product adapter.

Stage Overview

StageWhat HappensMain Artifact
ingestOpenAPI, MCP, and Python sources become toolsToolSchema
contract extractionrequest/response/auth/context fields are extractedmetadata.api_contract
semantic buildaction, resource, module, and result shape are inferredmetadata.ai_metadata
graph buildstructural, contract, manual, and trace edges are mergedgraph artifact
retrievala compact candidate set is ranked for the queryretrieval results
target selectionLLM target is guarded by deterministic evidencetarget_selector
plan synthesisproducers, bindings, and user input slots are orderedPlan
runadapter executes tools and streams structured eventsrunner events
learnscrubbed traces become suggestions after validationlearning state

Artifact Flow

ArtifactWhy It ExistsWhere It Usually Lives
ToolSchemastable tool description and parametersengine memory or adapter storage
metadata.openapioriginal OpenAPI operation evidencecollection artifact
metadata.api_contractconsumes, produces, links, auth fieldscollection artifact
metadata.ai_metadataaction/resource/module/search summarycollection artifact
readiness_reportbuild-time issue codes and readiness scorecollection artifact and UI
retrieval evidencescore breakdown and matched signalsrequest trace or Quality Lab
target_selectorfinal target decision and override reasonplan metadata
Planexecutable ordered steps and bindingsrequest runtime
runner eventsstreamable execution state and failuresSSE/log/Quality Lab
learning suggestionssafe feedback from repeated execution tracescollection-scoped learning block

The same artifact should be useful to a human, a test, and an adapter. If an important decision exists only inside a prompt, it is hard to debug.

Engine vs Adapter

graph-tool-call owns product-neutral logic.

Engine OwnsAdapter Owns
schema normalizationdatabase rows
semantic metadatauser sessions
IO contractsauth profiles
graph edgesHTTP execution
retrieval evidencecookies and runtime headers
target selectionSSE transport
plan synthesis diagnosticsUI workflows
learning suggestionscollection persistence and promotion policy

This boundary keeps the library reusable. XGEN can pass auth profiles and store collection artifacts without putting XGEN-specific DB, cookie, or UI logic into the engine.

Why A Graph

A list of tools hides relationships. A graph makes them explicit:

  • tool A produces a field that tool B consumes
  • several operations share the same primary resource
  • a search operation can produce identifiers for a detail operation
  • a manually curated edge is stronger than a weak name-based edge
  • a repeated successful run can become trace evidence

This matters for planning. The engine can synthesize producer steps because the catalog contains field and edge evidence, not just descriptions.

What The LLM Still Does

The LLM still matters. It can:

  • interpret natural-language intent
  • choose among a compact, ranked candidate set
  • fill natural-language gaps
  • produce a user-facing final response
  • reason over evidence that the engine provides

The engine keeps the LLM away from avoidable catalog noise. The first optimization target is better evidence, not model fine-tuning.

Search To Plan Example

from graph_tool_call import ToolGraph
from graph_tool_call.plan import PathSynthesizer

graph = ToolGraph.from_url(openapi_url)

results = graph.retrieve_with_scores(
"show refund-ready orders",
top_k=8,
)

target = results[0].tool.name
graph_payload = {
"graph": graph.graph.to_dict(),
"tools": {name: tool.to_dict() for name, tool in graph.tools.items()},
}

plan = PathSynthesizer(graph_payload).synthesize(
target=target,
goal="show refund-ready orders",
entities={"siteNo": "1001"},
)

The retrieval result explains why a tool was ranked. The plan explains which fields are already satisfied, which producers are needed, and which values must come from user input or context defaults.

Failure Handling

When a run fails, classify the stage before changing prompts.

SymptomLikely StageFirst Document To Read
expected tool not in Top-KretrievalRetrieval Signals
expected tool in Top-K but final target is wrongtarget selectionTarget Selection
plan asks for an obvious fieldplan synthesisUser Input Slots
execute stops before API callauth preflightAuth Readiness
API returns 400, 401, or 500executeFailure Taxonomy
retry succeeds but future search does not improvelearningTrace Learning Loop

Quality Loop

Quality should be measured as a loop:

  1. build the catalog
  2. inspect readiness and graph evidence
  3. run search cases
  4. run target-selection cases
  5. run plan and execute cases when auth is available
  6. store scrubbed traces
  7. compare learning in shadow mode
  8. promote only validated suggestions

This gives you repeatable evidence instead of relying on a single demo.

Next Steps