Skip to content

fix(agent base): fixed many iterations and tool calls#27

Merged
ChrisCoder9000 merged 1 commit intomainfrom
development
Mar 9, 2026
Merged

fix(agent base): fixed many iterations and tool calls#27
ChrisCoder9000 merged 1 commit intomainfrom
development

Conversation

@ChrisCoder9000
Copy link
Copy Markdown
Contributor

@ChrisCoder9000 ChrisCoder9000 commented Mar 9, 2026

Summary by CodeRabbit

  • Chores

    • Updated version to 2.9.1-dev
  • New Features

    • Enhanced agent system with improved tool orchestration and structured response handling
    • Added advanced language model configuration options for optimized processing

@ChrisCoder9000 ChrisCoder9000 merged commit 74481c3 into main Mar 9, 2026
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Mar 9, 2026

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 5ef7de0d-677d-467b-ac86-1a3466a271e7

📥 Commits

Reviewing files that changed from the base of the PR and between 1738711 and e130dff.

⛔ Files ignored due to path filters (1)
  • uv.lock is excluded by !**/*.lock
📒 Files selected for processing (12)
  • README.md
  • pyproject.toml
  • src/core/agents/core/__init__.py
  • src/core/agents/core/agent_base.py
  • src/core/agents/core/invoke_loop.py
  • src/core/agents/core/parsing.py
  • src/core/agents/core/prompts.py
  • src/core/agents/core/schema_utils.py
  • src/core/agents/core/structured_output.py
  • src/core/agents/core/types.py
  • src/core/agents/scout_agent.py
  • src/lib/llm/client_small.py

📝 Walkthrough

Walkthrough

This 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

Cohort / File(s) Summary
Version Bumps
README.md, pyproject.toml
Updated version badge and project version from 2.9.0-dev to 2.9.1-dev.
Core Agent Refactoring
src/core/agents/core/agent_base.py
Replaced 1200+ lines of internal orchestration logic (message normalization, tool invocation, parsing) with single delegation call to run_invoke_loop. Updated output_schema typing and simplified methods like _get_effective_output_schema and invoke to delegate to external functions. Removed legacy tool-call parsing and structured response validation.
New Invoke Loop Module
src/core/agents/core/invoke_loop.py
New 588-line module implementing run_invoke_loop(agent, messages, config) with iterative agent-model interaction, tool call extraction and invocation, thought signature handling, schema-based output parsing, and error retry logic for unknown finish reasons.
New Parsing Utilities
src/core/agents/core/parsing.py
New 509-line module providing 12 functions for message normalization, tool name/call extraction, thought signature extraction, invoke response normalization, and JSON repair utilities. Handles varied response shapes (dicts, objects) across different LLM providers.
New Schema & Output Utilities
src/core/agents/core/schema_utils.py, src/core/agents/core/structured_output.py
Schema utils (146 lines): functions for effective schema resolution, JSON schema derivation, list-field validation, and schema flattening. Structured output (145 lines): JSON parsing with repair, Pydantic model validation, and fallback handling via list-field detection.
New Prompt Building Module
src/core/agents/core/prompts.py
New 67-line module with two functions: format_tool_description (renders tool metadata) and build_system_internal_prompt (constructs system prompts with tools, output schema, and optional thinking instructions).
New Type Definitions
src/core/agents/core/types.py
New 17-line module defining AgentMessage, AgentOutput, and MessagesDict TypedDict structures for consistent agent messaging and response shapes.
Export API Updates
src/core/agents/core/__init__.py
Added explicit imports and exports of AgentBase and parse_structured_from_messages to update the public API surface.
Minor Updates
src/core/agents/scout_agent.py
Last Modified header date change only; no functional changes.
LLM Client Configuration
src/lib/llm/client_small.py
Added thinking_budget: 0 to ChatVertexAI initialization. Introduced dynamic config_kw for JSON generation with conditional ThinkingConfig inclusion and refactored GenerateContentConfig to use dynamic kwargs.

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
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~75 minutes

Possibly related PRs

  • PR #23: Directly conflicts with and modifies the same agent core infrastructure (agent_base.py and package exports), representing concurrent or competing refactoring efforts on the core agent architecture.

Poem

🐰 The rabbit hops through code so grand,
Breaking orchards into smaller lands,
Loops and parsers, schemas bright,
From chaos springs a cleaner light!
Where once lived giants, now small friends,
Orchestrate where logic bends. 🌱

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch development

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
.pylintrc:1:0: F0011: error while parsing the configuration: Source contains parsing errors: '.pylintrc'
[line 18]: 'C0103' (config-parse-error)
[
{
"type": "convention",
"module": "src.core.agents.core.invoke_loop",
"obj": "",
"line": 179,
"column": 0,
"endLine": null,
"endColumn": null,
"path": "src/core/agents/core/invoke_loop.py",
"symbol": "line-too-long",
"message": "Line too long (102/100)",
"message-id": "C0301"
},
{
"type": "convention",
"module": "src.core.agents.core.invoke_loop",
"obj": "",
"line": 195,
"column": 0,
"endLine": null,
"endColumn": null,
"path": "src/core/agents/core/invoke_loop.py",
"symbol": "line-too-long",
"message": "Line too long (147/100)",
"message-id": "C0301"
},
{
"type": "convention",
"module": "src.core.agent

... [truncated 12725 characters] ...

"W0212"
},
{
"type": "refactor",
"module": "src.core.agents.core.invoke_loop",
"obj": "run_invoke_loop",
"line": 20,
"column": 0,
"endLine": 20,
"endColumn": 19,
"path": "src/core/agents/core/invoke_loop.py",
"symbol": "too-many-branches",
"message": "Too many branches (83/12)",
"message-id": "R0912"
},
{
"type": "refactor",
"module": "src.core.agents.core.invoke_loop",
"obj": "run_invoke_loop",
"line": 20,
"column": 0,
"endLine": 20,
"endColumn": 19,
"path": "src/core/agents/core/invoke_loop.py",
"symbol": "too-many-statements",
"message": "Too many statements (269/50)",
"message-id": "R0915"
}
]

src/core/agents/core/agent_base.py

************* Module .pylintrc
.pylintrc:1:0: F0011: error while parsing the configuration: Source contains parsing errors: '.pylintrc'
[line 18]: 'C0103' (config-parse-error)
[
{
"type": "convention",
"module": "src.core.agents.core.agent_base",
"obj": "",
"line": 1,
"column": 0,
"endLine": null,
"endColumn": null,
"path": "src/core/agents/core/agent_base.py",
"symbol": "missing-module-docstring",
"message": "Missing module docstring",
"message-id": "C0114"
},
{
"type": "error",
"module": "src.core.agents.core.agent_base",
"obj": "",
"line": 4,
"column": 0,
"endLine": 4,
"endColumn": 16,
"path": "src/core/agents/core/agent_base.py",
"symbol": "import-error",
"message": "Unable to import 'langsmith'",
"message-id": "E0401"
},
{
"type": "error",
"module": "src.core.agents.core.

... [truncated 3105 characters] ...

},
{
    "type": "refactor",
    "module": "src.core.agents.core.agent_base",
    "obj": "AgentBase",
    "line": 21,
    "column": 0,
    "endLine": 21,
    "endColumn": 15,
    "path": "src/core/agents/core/agent_base.py",
    "symbol": "too-few-public-methods",
    "message": "Too few public methods (1/2)",
    "message-id": "R0903"
},
{
    "type": "warning",
    "module": "src.core.agents.core.agent_base",
    "obj": "",
    "line": 10,
    "column": 0,
    "endLine": 10,
    "endColumn": 51,
    "path": "src/core/agents/core/agent_base.py",
    "symbol": "unused-import",
    "message": "Unused parse_structured_from_messages imported from parsing",
    "message-id": "W0611"
}

]

src/core/agents/core/prompts.py

************* Module .pylintrc
.pylintrc:1:0: F0011: error while parsing the configuration: Source contains parsing errors: '.pylintrc'
[line 18]: 'C0103' (config-parse-error)
[
{
"type": "convention",
"module": "src.core.agents.core.prompts",
"obj": "",
"line": 1,
"column": 0,
"endLine": null,
"endColumn": null,
"path": "src/core/agents/core/prompts.py",
"symbol": "missing-module-docstring",
"message": "Missing module docstring",
"message-id": "C0114"
},
{
"type": "error",
"module": "src.core.agents.core.prompts",
"obj": "",
"line": 4,
"column": 0,
"endLine": 4,
"endColumn": 36,
"path": "src/core/agents/core/prompts.py",
"symbol": "import-error",
"message": "Unable to import 'langchain.tools'",
"message-id": "E0401"
},
{
"type": "convention",
"module": "src.core.agents.core.p

... [truncated 321 characters] ...

116"
},
{
"type": "convention",
"module": "src.core.agents.core.prompts",
"obj": "build_system_internal_prompt",
"line": 23,
"column": 0,
"endLine": 23,
"endColumn": 32,
"path": "src/core/agents/core/prompts.py",
"symbol": "missing-function-docstring",
"message": "Missing function or method docstring",
"message-id": "C0116"
},
{
"type": "warning",
"module": "src.core.agents.core.prompts",
"obj": "",
"line": 2,
"column": 0,
"endLine": 2,
"endColumn": 32,
"path": "src/core/agents/core/prompts.py",
"symbol": "unused-import",
"message": "Unused Optional imported from typing",
"message-id": "W0611"
}
]

  • 6 others

Tip

Try Coding Plans. Let us write the prompt for your AI agent so you can ship faster (with fewer bugs).
Share your feedback on Discord.


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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot mentioned this pull request Mar 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant