@@ -43,8 +43,8 @@ console.log(agent.state.messages);
4343
4444## Streaming a Run
4545
46- The ` prompt() ` and ` continue() ` methods return an ` AgentRunHandle ` . Awaiting it
47- runs to completion; treating it as a stream yields lifecycle events.
46+ The ` prompt() ` and ` continue() ` methods return an ` AgentRunHandle ` . A handle
47+ can be consumed exactly once via one of these methods:
4848
4949``` ts
5050const handle = agent .prompt (' Plan a trip to Lisbon.' );
@@ -56,9 +56,12 @@ for await (const event of handle.events()) {
5656}
5757```
5858
59- A handle can be consumed exactly once, in one of these ways:
60-
61- - ` await handle ` — run to completion without observing events.
59+ - ` await handle ` — run to completion without observing events. The handle is
60+ ` PromiseLike<void> ` , so it ` await ` s directly. Equivalent to ` handle.wait() ` .
61+ - ` handle.wait() ` — explicit form of the above. Prefer this when the handle
62+ might be passed through generic wrappers (` Promise.resolve(...) ` ,
63+ ` Promise.all([...]) ` ) where accidental thenable assimilation would consume
64+ it before you intended.
6265- ` handle.events() ` — iterate ` AgentEvent ` s.
6366- ` handle.toReadableStream() ` — wrap events in a ` ReadableStream<AgentEvent> ` .
6467- ` handle.toResponse(init?) ` — wrap events as an SSE ` Response ` , ready to
@@ -139,7 +142,12 @@ Execution:
139142
140143- ` prompt(input, opts?) ` — start a new run from a user message.
141144- ` continue(opts?) ` — resume after a paused decision or after the messages
142- array was edited externally.
145+ array was edited externally. If the most recent pending assistant has
146+ non-` toolResult ` messages appended after it (e.g., a user message
147+ injected while the tool was paused), ` continue() ` throws — use
148+ ` injectDeferralResults() ` + ` prompt() ` from ` agentic-kit ` instead, which
149+ synthesizes stand-in ` toolResult ` s before the new user message so the
150+ transcript stays well-formed for OpenAI / Anthropic.
143151- ` abort() ` — cancel the active run.
144152- ` waitForIdle() ` — resolves when the current run finishes.
145153- ` subscribe(listener) ` — receive ` AgentEvent ` s without consuming the handle.
@@ -148,7 +156,7 @@ Execution:
148156
149157` AgentEvent ` is a discriminated union covering the full lifecycle:
150158
151- - ` agent_start ` , ` agent_end ` (with ` stopReason: 'completed' | 'max_steps' ` )
159+ - ` agent_start ` , ` agent_end ` (with ` stopReason: 'completed' | 'max_steps' | 'aborted' ` )
152160- ` turn_start ` , ` turn_end `
153161- ` message_start ` , ` message_update ` , ` message_end `
154162- ` tool_execution_start ` , ` tool_execution_update ` , ` tool_execution_end `
0 commit comments