fix(agent base): fixed many iterations and tool calls#27
Conversation
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (12)
📝 WalkthroughWalkthroughThis PR refactors the agent core infrastructure by extracting complex orchestration logic from agent_base.py into five new specialized modules (invoke_loop, parsing, prompts, schema_utils, structured_output). The main invoke method now delegates to an external run_invoke_loop function, reducing agent_base.py from 1244 to 12 lines of implementation logic. Version bumped to 2.9.1-dev across configuration files. Changes
Sequence Diagram(s)sequenceDiagram
actor User
participant Agent as AgentBase
participant InvokeLoop as run_invoke_loop()
participant Model as LLM Model
participant Tools as Tool Executor
participant Parser as Parsing Utils
participant SchemaUtils as Schema Utils
User->>Agent: invoke(messages, config)
Agent->>InvokeLoop: run_invoke_loop(self, messages, config)
InvokeLoop->>InvokeLoop: Build system prompt + append messages
loop Iterative Invocation
InvokeLoop->>Model: Invoke with messages
Model-->>InvokeLoop: Response (may include tool_calls)
InvokeLoop->>Parser: Extract tool calls from response
Parser-->>InvokeLoop: tool_name, tool_input
alt Tool Call Detected
InvokeLoop->>Tools: Execute tool(tool_name, input)
Tools-->>InvokeLoop: tool_result
InvokeLoop->>InvokeLoop: Append tool result to messages
else No Tool Call
InvokeLoop->>InvokeLoop: Check finish reason
alt UNKNOWN Finish Reason
InvokeLoop->>InvokeLoop: Retry with continuation prompt
else Finished
InvokeLoop->>InvokeLoop: Exit loop
end
end
end
InvokeLoop->>Parser: parse_structured_from_messages()
Parser->>SchemaUtils: get_effective_output_schema()
SchemaUtils-->>Parser: effective_schema
Parser->>Parser: Parse structured response against schema
Parser-->>InvokeLoop: structured_response
InvokeLoop-->>Agent: {messages, structured_response}
Agent-->>User: AgentOutput
Estimated code review effort🎯 4 (Complex) | ⏱️ ~75 minutes Possibly related PRs
Poem
✨ Finishing Touches
🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 Pylint (4.0.5)src/core/agents/core/invoke_loop.py************* Module .pylintrc ... [truncated 12725 characters] ... "W0212" src/core/agents/core/agent_base.py************* Module .pylintrc ... [truncated 3105 characters] ... ] src/core/agents/core/prompts.py************* Module .pylintrc ... [truncated 321 characters] ... 116"
Tip Try Coding Plans. Let us write the prompt for your AI agent so you can ship faster (with fewer bugs). 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 |
Summary by CodeRabbit
Chores
New Features