Docs/Foundational Primitives/Streaming
Streaming Real-Time Token Responses
AgentCore supports streaming responses token-by-token using modern TypeScript for await...of loops as well as event callbacks. Switch modes (**Gateway**, **Provider**, **Custom**) or select models below to inspect live code updates.
Interactive Streaming Examples
Use agent.stream() to destructure textStream and iterate using for await (const textPart of textStream):
| 1 | import { streamText } from '@bablusingh-dev/agentcore'; |
| 2 | |
| 3 | const { textStream } = streamText({ |
| 4 | model: 'anthropic/claude-3-5-sonnet', |
| 5 | prompt: 'Write a poem about embedding models.', |
| 6 | }); |
| 7 | |
| 8 | for await (const textPart of textStream) { |
| 9 | console.log(textPart); |
| 10 | } |