marchwarden/researchers/web
Jeff Smith 6ff1a6af3d Enforce token_budget before each iteration (#17)
The loop previously checked the token budget at the *bottom* of each
iteration, after the LLM call and tool work had already happened. By
the time the cap was caught the budget had been exceeded and the
overshoot was unbounded by the iteration's cost.

Move the check to the *top* of the loop so a new iteration is never
started past the budget. Document the policy explicitly: token_budget
is a soft cap on the tool-use loop only; the synthesis call is always
allowed to complete so callers get a structured ResearchResult rather
than a fallback stub. Capping synthesis is a separate, larger design
question (would require splitting the budget between loop and
synthesis up-front).

Verified: token_budget=5000, max_iterations=10 now stops after 2
iterations with budget_exhausted=True and a complete answer with
10 citations.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-08 15:29:22 -06:00
..
__init__.py Initial project structure and scaffolding 2026-04-08 11:57:15 -06:00
__main__.py M1.4: MCP server wrapping web researcher 2026-04-08 14:41:13 -06:00
agent.py Enforce token_budget before each iteration (#17) 2026-04-08 15:29:22 -06:00
models.py Add OpenQuestion to research contract 2026-04-08 14:37:30 -06:00
server.py Fix invalid default model id (#15) 2026-04-08 15:25:19 -06:00
tools.py M1.1: Search and fetch tools with tests 2026-04-08 14:17:18 -06:00
trace.py M1.2: Trace logger with tests 2026-04-08 14:21:10 -06:00