LangGraph
Route every tool call in a LangGraph graph through AgentShield with GatewayToolNode, or give LangGraph agents typed gateway tools.
AgentShield offers two ways to use LangGraph:
| Approach | Use when |
|---|---|
GatewayToolNode (this page) | Your graph has a tool-execution node that reads tool_calls from the last message |
GatewayTool from the LangChain integration | You build agents with prebuilt LangChain/LangGraph helpers and want typed tools, fixed resources, and approval waiting |
Install
python -m pip install ./sdk/python ./integrations/langgraphAdd the node
from pathlib import Path
from agentshield_langgraph import GatewayToolNode
from agentshield_sdk import Client
client = Client(
gateway="http://127.0.0.1:8081",
agent_id=AGENT_ID,
organization_id=ORGANIZATION_ID,
seed=Path("agent.seed").read_bytes(),
)
graph.add_node("tools", GatewayToolNode(client))The constructor takes only the client. It raises TypeError if the object has no call_tool method, and there is no parameter for a list of Python functions.
How a call is mapped
The node reads state["messages"][-1].tool_calls (dict or attribute style). For each call:
| Tool call field | Sent to the gateway as |
|---|---|
name | tool_name |
args["resource"] | resource (required; removed from arguments) |
args["operation"] | operation (optional; defaults to the tool name; removed from arguments) |
remaining args | arguments |
The call then goes through client.call_tool, so execute runs only after allow.
# A model tool call like this…
{"name": "http.request", "id": "call_1",
"args": {"operation": "http.get",
"resource": "https://api.github.com/repos/octo/hello",
"headers": {"Accept": "application/json"}}}
# …becomes authorize(tool_name="http.request", operation="http.get",
# resource="https://api.github.com/repos/octo/hello",
# arguments={"headers": {"Accept": "application/json"}})What the node returns
The node returns {"messages": [...]} with one tool message per call:
{"role": "tool", "tool_call_id": "call_1", "name": "http.request",
"status": "success", "content": "{\"adapter\":\"http.request\",\"decision_id\":…,\"result\":{…}}"}| Outcome | status | content |
|---|---|---|
allow and executed | success | The execute result, including analysis and warning when flagged |
deny | error | {"outcome":"deny","decision_id":…,"reason":…} |
require_approval | error | {"outcome":"require_approval","decision_id":…,"reason":…} |
| Gateway error | error | {"error": code, "message": …} |
The node does not wait for approval; it reports the held call immediately. Use GatewayTool with approval_timeout if your agent should wait.
Validation errors
The node raises ValueError before contacting the gateway when the state has no messages, the last message has no tool calls, a call has no name, args is not an object, or resource is missing or empty.
Security notes
- Because tools are names, a model can request any tool name. That is safe: the gateway decides, and a name with no adapter returns
501. Keep policies tight so unexpected operations are denied. - Tell the model which
operationvalues exist through your tool descriptions; unknown operations are denied by default.
Implementation references
Was this page helpful?
TypeScript SDK
The @agentshield/sdk client for Node.js. Set it up, call tools, handle decisions, execute approvals, and read content analysis.
LangChain
GatewayTool, a LangChain BaseTool with no local function. Every call goes through AgentShield authorize and execute, with optional waiting for approval.