LangGraph
LangGraph tools are guarded with a shared AgentContext bound to the agent, so
each guard can recover the agent's live mandate from its own prompt — you never
repeat it on the guard.
from kelhe import Kelhe, Mode
from kelhe.adapters.langgraph import guard, AgentContext
from langchain_openai import ChatOpenAI
from langgraph.prebuilt import create_react_agent
from langchain_core.messages import HumanMessage
kelhe = Kelhe(mode=Mode.ENFORCE, risk_threshold=7.0)
def issue_refund(amount: int, customer: str) -> str:
"Issue a refund to a customer."
return f"refunded ${amount} to {customer}"
ctx = AgentContext()
agent = create_react_agent(
ChatOpenAI(model="gpt-4o-mini", temperature=0),
tools=[guard(kelhe, issue_refund, context=ctx)],
prompt="process approved customer refunds",
)
ctx.bind(agent) # bind after creating the agent
agent.invoke({"messages": [HumanMessage(content="Refund $20 for cust_42")]})
Create one AgentContext, pass it to every guard(...) in the graph, and call
ctx.bind(agent) once. The adapter pulls instructions, available tools, graph
state, and history straight off the ToolRuntime at call time.