Skip to main content
Version: v0 (preview)

AutoGen

Like LangGraph, AutoGen tools are guarded with a shared AgentContext bound to the agent, so the guard reads the agent's current system message and conversation live.

from kelhe import Kelhe, Mode
from kelhe.adapters.autogen import guard, AgentContext
from autogen_agentchat.agents import AssistantAgent
from autogen_ext.models.openai import OpenAIChatCompletionClient

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 = AssistantAgent(
name="billing",
model_client=OpenAIChatCompletionClient(model="gpt-4o-mini"),
system_message="process approved customer refunds",
tools=[guard(kelhe, issue_refund, context=ctx)],
)
ctx.bind(agent)

Create one AgentContext, pass it to each guard(...), and call ctx.bind(agent) once after the agent exists.