feat(agent): add streamed reasoning summary callbacks to runAgent

This commit is contained in:
2026-05-14 22:44:08 +00:00
parent ca56f4c4e8
commit 6fb2b3a61f
5 changed files with 95 additions and 3 deletions
+4 -1
View File
@@ -76,7 +76,7 @@ console.log(result.usage); // { inputTokens, outputTokens, totalTokens, cacheR
-**Parallel tool execution** — multiple tool calls in a single step are executed concurrently
- 🔧 **Auto-retry with backoff** — handles 429/529/503 errors with header-aware retry delays
- 🩹 **Tool call repair** — case-insensitive name matching + invalid tool sink prevents crashes
- 📊 **Token streaming**`onToken` and `onToolCall` callbacks for real-time progress
- 📊 **Token and reasoning streaming**`onToken`, `onReasoning*`, and `onToolCall` callbacks for real-time progress
- 💥 **Context overflow handling** — detects overflow and invokes your `onContextOverflow` callback
## Core API
@@ -98,6 +98,9 @@ The single entry point. Options:
| `messages` | `ModelMessage[]` | `[]` | Conversation history (for multi-turn) |
| `maxRetries` | `number` | `5` | Max retries on rate-limit/server errors |
| `onToken` | `(delta: string) => void` | — | Streaming token callback |
| `onReasoningStart` | `(id: string) => void` | — | Called when a reasoning summary starts |
| `onReasoningDelta` | `(id: string, delta: string) => void` | — | Called for streamed reasoning summary text |
| `onReasoningEnd` | `(id: string, text: string) => void` | — | Called when a reasoning summary completes |
| `onToolCall` | `(name: string) => void` | — | Called when a tool is invoked |
| `onToolResult` | `(name: string, result: unknown) => void` | — | Called when a tool finishes |
| `validateCompletion` | `(result) => string \| void` | — | Return a string to reject and reprompt an incomplete run |