Skip to main content

LangChain

Use graph-tool-call as a retrieval and filtering layer before constructing the LangChain tool set sent to a model. The goal is to keep the LLM's visible tool catalog small while preserving evidence about why each candidate was included.

Use this integration when you already have LangChain tools and want per-query tool filtering without changing downstream tool implementations.

Basic Pattern

from graph_tool_call.langchain import filter_tools

filtered = filter_tools(langchain_tools, "cancel an order", top_k=8)

filter_tools() preserves the original tool objects. The returned objects are the same LangChain tools your agent already knows how to call.

Reusable Toolkit

Build the graph once and filter many times:

from graph_tool_call.langchain import GraphToolkit

toolkit = GraphToolkit(langchain_tools, top_k=8)

def tools_for_turn(user_query: str):
return toolkit.get_tools(user_query)

The underlying toolkit.graph can be inspected, saved, or reused in tests.

LangGraph Agent

For LangGraph ReAct agents:

from graph_tool_call.langchain import create_agent

agent = create_agent(
model,
tools=langchain_tools,
top_k=5,
query_mode="message",
)

query_mode="message" uses the latest user message as the retrieval query. Use query_mode="llm" only when multi-turn references need a generated search query; it adds one LLM call per turn.

Gateway Tools

If your agent framework prefers a small fixed set of tools, expose search as a gateway tool instead of exposing every downstream operation.

from graph_tool_call import create_gateway_tools

gateway_tools = create_gateway_tools(
graph,
top_k=8,
)

The model asks the gateway to search; the application can then present or execute the selected downstream tool according to its own policy.

Choosing A Pattern

PatternUse WhenTradeoff
filter_tools()one-shot filtering before an agent callrebuilds unless a graph is provided
GraphToolkitsame catalog reused across many turnssimple and explicit
create_agent()LangGraph ReAct flow should filter per turnframework-specific
gateway toolsmodel should call search explicitlyrequires extra tool-call step
ControlWhy
top_kLimits visible tool count
score evidenceExplains why candidates were shown
target selector guardPrevents obvious LLM target mismatch
Quality Lab casesCatches regressions before catalog widening
host-side executionKeeps auth and side effects under application control

Common Pitfalls

  • Passing every LangChain tool to the model after retrieval.
  • Dropping score/evidence metadata, making failures hard to debug.
  • Letting the engine own runtime credentials.
  • Treating a search hit as proof that plan and execute are ready.

Validation

poetry run pytest tests/test_langchain_toolkit.py tests/test_langchain_agent.py -q