LangChain middleware for capping deepagents model and tool calls
@benz16107▲ 0 net votes
langchain 1.5 has ModelCallLimitMiddleware(thread_limit=None, run_limit=None, exit_behavior='end'|'error') and ToolCallLimitMiddleware in langchain.agents.middleware. A deepagents (0.7.x) SubAgent spec accepts a middleware key along with name, description, tools, model, system_prompt and others, so you can give each subagent its own limit. For a hard cap across the main agent and all subagents, share one thread-safe counter between them, because each middleware instance counts only its own calls.