feat(agents): add max_tool_calls budget to ChatAgent - #4289
anupamkr1708 wants to merge 3 commits into
Conversation
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Advanced Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
I investigated the current CI failures. The PR Label Automation job is failing with a 403 The pytest-related jobs are currently failing during test collection with ImportError: cannot import name 'FastMCP' from 'mcp.server', before the affected tests execute. I have since checked the base branch locally; the direct FastMCP import succeeds there, although the corresponding app test cannot be reproduced locally because that environment is missing gradio. So I have not yet confirmed that this CI dependency/import failure is pre-existing. The feature validation remains green locally: 17 focused I’ll continue checking the failing jobs against the base branch to confirm whether the dependency/import failure is pre-existing. |
|
I also addressed the mypy failure reported by CI in the new regression test. The ChatCompletion helper now uses the typed Choice model with a Literal finish-reason type, matching the existing test conventions. The focused max_tool_calls tests, related regression tests, Ruff/pre-commit checks, and scoped mypy check are passing locally. The PR has been updated with follow-up commit 82b2b0b. |
Summary
Adds an optional
max_tool_callsbudget toChatAgent, independent ofmax_iteration, to limit cumulative internal tool executions within asingle
step()orastep()call.Changes
max_tool_calls: Optional[int] = NonetoChatAgent.None.boolvalues explicitly.each new
step()/astep()call.response, so a batch cannot execute more calls than allowed.
tool-role rejection messages for calls beyond the remainingbudget, preserving OpenAI-compatible message history.
continue to a final textual response.
max_tool_callswhen cloning aChatAgent.max_tool_callsindependent frommax_iteration.Tests
Added focused coverage for:
max_iteration.Validation performed locally:
python -m pytest test/agents/test_chat_agent_max_tool_calls.py -q— 17 passedpython -m pytest test/agents/test_chat_agent_clone.py -q— 3 passedpython -m pytest test/agents/test_chat_agent_tool_log.py -q— 24 passedruff check --no-fix camel/agents/chat_agent.py— passedgit diff --cached --check— passedStreaming tool-execution paths are intentionally unchanged in this PR.
Fixes #4278