Why
Most coding agents follow the same loop:- define tools
- model picks tools
- execute tools
- return tool results
- repeat
session.prompt(...).
Core pattern
Claude tool loop (excerpt)
OpenAI tool loop (excerpt)
Multi-document fan-out
If your orchestration logic already knows which docs to hit, run in parallel:When to use this pattern
- You want custom prompts and full agent control in your app runtime.
- You want to combine document tools with non-document tools (web search, calculators, DB lookups).
- You want transparent orchestration instead of a managed server-side multi-doc agent.