Skip to Content
AgentShield
Integrations

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:

ApproachUse when
GatewayToolNode (this page)Your graph has a tool-execution node that reads tool_calls from the last message
GatewayTool from the LangChain integrationYou build agents with prebuilt LangChain/LangGraph helpers and want typed tools, fixed resources, and approval waiting

Install

python -m pip install ./sdk/python ./integrations/langgraph

Add 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 fieldSent to the gateway as
nametool_name
args["resource"]resource (required; removed from arguments)
args["operation"]operation (optional; defaults to the tool name; removed from arguments)
remaining argsarguments

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\":{…}}"}
Outcomestatuscontent
allow and executedsuccessThe execute result, including analysis and warning when flagged
denyerror{"outcome":"deny","decision_id":…,"reason":…}
require_approvalerror{"outcome":"require_approval","decision_id":…,"reason":…}
Gateway errorerror{"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 operation values exist through your tool descriptions; unknown operations are denied by default.

Was this page helpful?

On this page