feat: add per-agent loop safeguards for tool-call turns

Introduce three optional per-agent config fields to bound tool-call loop
execution: `max_iterations` (default 15), `streaming_timeout` (default
120s), and `turn_timeout` (default 300s wall-clock).

- Plumb limits from agent config through `_build_agents_table` and
  `_start_agent` into `MultimodalAgentMCPServer` via `request_limits`
- Apply `max_iterations` and `streaming_timeout` to `RequestParams`
- Wrap turn dispatch in `asyncio.wait_for` to enforce `turn_timeout`,
  logging a warning on timeout
- Document the new fields in README
This commit is contained in:
2026-05-27 05:41:08 -04:00
parent ca7d714a31
commit 440f7fb60c
4 changed files with 57 additions and 6 deletions

View File

@@ -75,6 +75,28 @@ agents:
description: "Web search and knowledge graph"
```
### Loop safeguards
Three optional fields bound how long an agent's tool-call loop can run:
| Field | Type | Default | Purpose |
|---|---|---|---|
| `max_iterations` | int | 15 | Maximum tool calls in a single agent turn |
| `streaming_timeout` | float | 120 | Max idle seconds between streaming events |
| `turn_timeout` | float | 300 | Hard wall-clock limit for a full turn (seconds) |
All three are optional. Agents that omit them use the defaults shown above.
```yaml
agents:
research:
module: agents.research
port: 8250
max_iterations: 10 # this agent only needs a few search calls
streaming_timeout: 60 # fail fast on a slow search MCP
turn_timeout: 120 # research turns should not take more than 2 min
```
---
## `fastagent.config.yaml` extensions