To communicate with agents, you use the A2A protocol client to send messages and receive streaming events. The Agent Stack SDK provides helpers that turn those events into UI updates. This guide shows how to integrateDocumentation Index
Fetch the complete documentation index at: https://agentstack.beeai.dev/llms.txt
Use this file to discover all available pages before exploring further.
@a2a-js/sdk with the Agent Stack SDK helpers, mirroring the same flow used in agentstack-ui.
If you only need the fast path, start with Getting Started.
Prereqs
- Packages installed:
agentstack-sdkand@a2a-js/sdk - Platform base URL and provider ID
- CORS enabled on the server for your frontend origin when running in a browser (or use a same-origin proxy). See Cross-Origin Resource Sharing Configuration.
- User access token (for platform API calls)
- Context token (for A2A requests)
Quick Start recap
- Create a platform API client with the user access token.
- List providers, pick a
providerId, then create acontextandcontextToken. - Create the A2A client with the
contextTokenand start a message stream.
client, context, and contextToken from the quick start. If not, see Getting Started.
Advanced guide
In the next steps, you’ll wire up a full A2A message flow: resolve initial agent demands, start a streaming task, handle UI‑driven updates (like forms), and submit follow‑ups on the same task. The snippets are intentionally minimal but map directly to a real client implementation.1. Read the agent card and resolve demands
Fetch the agent card, inspect demands, and build the initial fulfillments. To keep the rest of this guide working without extra complexity, focus on the most common requirement: LLM access via the platform OpenAI‑compatible proxy. We map each LLM demand key to a model the user picked in your UI, then resolve the metadata that gets attached to your first message.2. Send the initial message stream
Start a task by sending the user prompt that triggers the project brief flow.3. Handle streaming updates and show the form
UsehandleTaskStatusUpdate to detect form requests and capture the task ID so you can continue the same task. Render streamed output from status-update events, and keep message as a fallback.
4. Submit the form and continue the task
Convert the user responses into A2A metadata and send a follow-up message for the same task.5. Render the final output and artifacts
Stream the response and render the final message and any artifacts.6. Cancel a running task
If a user clicks “Stop”, cancel the current task by ID. You’ll still receive a final status update with statecanceled, so update your UI and stop streaming when you see it.
Basic concepts: tasks, status updates, and streaming output
Agent Stack’s A2A streaming is task-based. A singlesendMessageStream call can yield several event shapes, and you should handle all of them:
task: emits the initial Task object. Capturetask.id, and usetask.status(and optionalhistory/artifacts) to seed your UI state.status-update: emits a task status transition. When the agent is streaming, incremental output is typically delivered viaevent.status.message(aMessagepayload attached to the status).artifact-update: emits artifacts as they are generated or updated (useful for streamed files, canvases, or structured outputs).message: emits a standalone Message. This is common for non‑streaming agents and may also appear as a final response.
status-update events (event.status.message). If you only render message events, you may miss streamed output.
Handling failed states
Tasks can fail at any point during streaming. Failed or rejected updates arrive asstatus-update events with event.status.state set to failed or rejected. In those cases:
- Read structured error metadata from the status message (if present).
- Fall back to a generic error message if no metadata is provided.
- Update the UI to a terminal error state and stop streaming.
Common pitfalls
- Wrong token in A2A requests: use the context token for A2A fetches, not the user access token.
- Missing metadata merge: merge agent card fulfillments with user metadata when you send responses.
- Streaming text handling: status updates can include partial text; append incrementally.
- Ignoring status updates: streamed agent output typically arrives via
status-updateevents (inevent.status.message), notmessage. - Node fetch missing: Node < 18 requires a
fetchpolyfill or customfetchpassed to the API client.