Framework Integrations
Limits checked before each model call and tool call in LangChain, CrewAI, AutoGen, and the OpenAI Agents SDK.
SteerPlane plugs into each framework through its own callbacks or hooks. Every model call and every tool call counts as one step. A call that would go past a limit is refused before it starts, and the refusal ends the run with a SteerPlane error. Cost comes from the token usage the model reports. Policy rules match the tool's name.
These pages describe SDK 1.1.3 or later. Each class accepts agent_name, max_cost_usd, max_steps,
max_runtime_sec, and model, plus denied_actions and the other policy options.
LangChain
SteerPlaneCallbackHandler: a BaseCallbackHandler.CrewAI
SteerPlaneCrewMonitor: CrewAI's call hooks.AutoGen
SteerPlaneAutoGenMonitor: AG2 reply functions and message hooks.OpenAI Agents SDK
SteerPlaneAgentHooks: the SDK's RunHooks.LangChain
pip install "steerplane[langchain]"from steerplane.integrations.langchain import SteerPlaneCallbackHandler
handler = SteerPlaneCallbackHandler(agent_name="research_agent", max_cost_usd=10)
# Pass it on the call, so it reaches both the model and the tools
result = agent.invoke(inputs, config={"callbacks": [handler]})
handler.finish() # finalize the run (status="completed" by default)Pass enforce=False to record only. LangChain then logs a refusal and the agent keeps going.
CrewAI
pip install "steerplane[crewai]"from steerplane.integrations.crewai import SteerPlaneCrewMonitor
monitor = SteerPlaneCrewMonitor(agent_name="crew_run", max_cost_usd=15)
crew = Crew(agents=[...], tasks=[...])
result = monitor.kickoff(crew) # raises the SteerPlane error if a limit stops the crewawait monitor.kickoff_async(crew) is the async version. Needs CrewAI 1.15.35 or newer. If you call crew.kickoff() yourself, put monitor.start() before it and
monitor.finish() after it. CrewAI then raises its own "blocked" error, and the reason is in
monitor.stop_error. CrewAI's hooks apply to the whole process, so run monitored crews one at a time.
AutoGen
pip install "steerplane[autogen]"from steerplane.integrations.autogen import SteerPlaneAutoGenMonitor
monitor = SteerPlaneAutoGenMonitor(agent_name="autogen_group", max_steps=40)
monitor.initiate_chat(user_proxy, assistant, message="Investigate the incident")This uses AG2's classic API (ag2 before 1.0). The newer autogen-agentchat package is a different API
and is not supported. a_initiate_chat is the async version. To run the chat yourself, call
monitor.attach(user_proxy, assistant) and monitor.start() first, and monitor.finish() after it.
OpenAI Agents SDK
pip install "steerplane[openai-agents]"from steerplane.integrations.openai_agents import SteerPlaneAgentHooks
hooks = SteerPlaneAgentHooks(agent_name="oa_agent", max_cost_usd=8)
# Let SteerPlane call the Runner
result = await hooks.run(agent, "Hello!")
# Or call the Runner yourself and pass the hooks
hooks.start()
result = await Runner.run(agent, "Hello!", hooks=hooks.run_hooks)
hooks.finish()Calling the Runner yourself, a stop made before a tool call reaches you wrapped in the Agents SDK's
UserError, with the SteerPlane error as its cause.
What the integrations don't cover
- Calls they aren't passed to. A LangChain handler set only on the model doesn't see tools. An agent
used through
Agent.as_tool()in the OpenAI Agents SDK is a separate run and isn't counted. An AG2 group chat manager's own speaker selection calls aren't counted. - Models that report no token usage. Those calls cost $0 against the cost limit. The step limit still applies.
- Parallel tool calls. Tool calls the model asks for together can all start before the first one is recorded, so a batch can pass the step limit by up to its own size. A denied tool never runs.
- The call that crosses the cost limit. A model call's cost is known only when it returns, so that call has already been paid for. The run stops there.
To limit every call whatever the agent structure, use the gateway.
Loop detection is off by default in these integrations. It matches on action names only, so with it on, a
run calling the same tool over a list is stopped as a loop. Pass detect_loops=True to turn it on. One
handler or monitor is one run, so create a new one for each run. Each integration is lazily imported,
so you only need the framework you actually use installed.