Skip to content

add ToolCallLimits capability on PydanticAIBaseAgent via scalar wiring#78

Open
sanzog03 wants to merge 1 commit intofeature/pydantic_ai_base_agentfrom
features/tool_call_limit_capability
Open

add ToolCallLimits capability on PydanticAIBaseAgent via scalar wiring#78
sanzog03 wants to merge 1 commit intofeature/pydantic_ai_base_agentfrom
features/tool_call_limit_capability

Conversation

@sanzog03
Copy link
Copy Markdown
Collaborator

Summary

Fills in PydanticAIBaseAgent._build_capabilities_from_scalars() — Consumers who set max_tool_iterations or max_tool_calls on the config now get a hard runtime cap enforced during the model-request loop and tool-execution
path, with AKD's existing UsageLimitExceeded family of errors surfacing cleanly through pydantic_ai's UnexpectedModelBehavior.

What it does

  • Agents built on PydanticAIBaseAgent respect max_tool_iterations and max_tool_calls from the inherited BaseAgentConfig — the ReAct loop no longer runs unbounded.
  • When a cap is hit, the run raises MaxToolIterationsExceeded / MaxToolCallsExceeded (both subclasses of UsageLimitExceeded), mirroring the semantics the legacy OpenAI-basedBaseAgent already exposes.
  • Subclasses can still extend the capability list by overriding _build_capabilities_from_scalars, calling super(), and appending (the extension pattern is now pinned by a test).
  • No new config fields on PydanticAIBaseAgentConfig — both scalars come in from BaseAgentConfig unchanged.

Files changed

  • New files:
    • akd_ext/agents/_base/pydantic_ai/_capabilities.py — holds ToolCallLimits (Hooks factory, closure state, two conditional lifecycle callbacks).
  • Modified files:
    - akd_ext/agents/_base/pydantic_ai/_base.py — imports ToolCallLimits; _build_capabilities_from_scalars body replaced with the max_tool_iterations / max_tool_calls.
    - tests/agents/test_base_pydantic.py — adds four tests under ToolCallLimits" section; restores one field on _EchoConfig (enable_extra_capability: bool) that the subclass-extension test needs.

Testing

Run the test suite (hermetic; no network, no model keys):

  uv run pytest tests/agents/test_base_pydantic.py -n=3

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