[BUG] Unhandled execption causing dying agents
I typically run VERY long running tasks .... and there should be a option to override the Usage limit.
In a 5-6h run (of one prompt) of it i see like 40ish of these errors.
Error invoking agent 'code-puppy': Traceback (most recent call last):
File "/home/jan/.cache/uv/archive-v0/uMFJW9VaEDSkk-x0S9os3/lib/python3.12/site-packages/code_puppy/tools/agent_tools.py", line 433, in invoke_agent
result = await task
^^^^^^^^^^
File "/home/jan/.cache/uv/archive-v0/uMFJW9VaEDSkk-x0S9os3/lib/python3.12/site-packages/pydantic_ai/agent/abstract.py", line 218, in run
async for node in agent_run:
File "/home/jan/.cache/uv/archive-v0/uMFJW9VaEDSkk-x0S9os3/lib/python3.12/site-packages/pydantic_ai/run.py", line 150, in __anext__
next_node = await self._graph_run.__anext__()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/jan/.cache/uv/archive-v0/uMFJW9VaEDSkk-x0S9os3/lib/python3.12/site-packages/pydantic_graph/graph.py", line 758, in __anext__
return await self.next(self._next_node)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/jan/.cache/uv/archive-v0/uMFJW9VaEDSkk-x0S9os3/lib/python3.12/site-packages/pydantic_graph/graph.py", line 731, in next
self._next_node = await node.run(ctx)
^^^^^^^^^^^^^^^^^^^
File "/home/jan/.cache/uv/archive-v0/uMFJW9VaEDSkk-x0S9os3/lib/python3.12/site-packages/pydantic_ai/_agent_graph.py", line 384, in run
return await self._make_request(ctx)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/jan/.cache/uv/archive-v0/uMFJW9VaEDSkk-x0S9os3/lib/python3.12/site-packages/pydantic_ai/_agent_graph.py", line 425, in _make_request
model_settings, model_request_parameters, message_history, _ = await self._prepare_request(ctx)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/jan/.cache/uv/archive-v0/uMFJW9VaEDSkk-x0S9os3/lib/python3.12/site-packages/pydantic_ai/_agent_graph.py", line 457, in _prepare_request
ctx.deps.usage_limits.check_before_request(usage)
File "/home/jan/.cache/uv/archive-v0/uMFJW9VaEDSkk-x0S9os3/lib/python3.12/site-packages/pydantic_ai/usage.py", line 313, in check_before_request
raise UsageLimitExceeded(f'The next request would exceed the request_limit of {request_limit}')
pydantic_ai.exceptions.UsageLimitExceeded: The next request would exceed the request_limit of 100
~/.code_puppy/puppy.cfg file:
[puppy] message_limit = 1000
Looking at the code, get_message_limit() is used to set the request_limit parameter in UsageLimits.
usage_limits=UsageLimits(request_limit=get_message_limit())
In pydantic_ai, request_limit controls how many LLM API requests (turns/steps) the agent can make in a single run, not the number of messages in the conversation history.
Looking at the docstring in the config:
def get_message_limit(default: int = 100) -> int:
"""
Returns the user-configured message/request limit for the agent.
This controls how many steps/requests the agent can take.
Defaults to 100 if unset or misconfigured.
It says "This controls how many steps/requests the agent can take" - so it is the request limit.
The naming is confusing:
- Config name: message_limit
- But it controls: request_limit (number of LLM API calls/turns)
I agree name is confusing, but upon increasing that default would this get fixed?