- chat-ui example source
- Local path in this monorepo:
apps/agentstack-sdk-ts/examples/chat-ui
VITE_AGENTSTACK_PROVIDER_ID set manually in .env.
This keeps the core SDK flow easy to follow before you add provider discovery, routing, and richer UI state.
It uses React, TypeScript, and Vite for a clean demonstration and fast local iteration.
The architecture itself is not tied to this stack. You can apply the same API, context token, and A2A streaming flow in other frontend frameworks.
This example assumes the following runtime setup:
- Your Agent Stack server is running and reachable.
- The server has at least one provider/agent available.
VITE_AGENTSTACK_PROVIDER_IDmatches an existing provider in that server.- When running from the Vite dev server (
http://localhost:5173), CORS on the Agent Stack server allows that origin.
What a custom UI needs
Most implementations follow the same core flow:- Create a platform API client
- Create a context and context token
- Create an authenticated A2A client
- Resolve agent card demands into metadata
- Send messages and stream task events
- Add UI flows for forms, approvals, OAuth, errors, and other extension-driven interactions
1. Configure environment and target provider
The example keeps runtime configuration in environment variables and injects the target provider ID directly..env values:
VITE_AGENTSTACK_BASE_URL: URL of your actual Agent Stack server instanceVITE_AGENTSTACK_PROVIDER_ID: provider/agent ID the example will call
2. Create a context and context token
Before sending messages, create a conversation context and a token scoped for agent access:buildApiClient with an authenticated fetch (for example, createAuthenticatedFetch(accessToken)), as shown in Getting Started.
Keep permissions minimal for your use case. See Permissions and Tokens for scope details.
3. Create an authenticated A2A client
Use the context token withcreateAuthenticatedFetch, then pass it to both the transport and card resolver:
4. Resolve agent requirements once per session
Read the agent card and resolve demand fulfillments before the first message:5. Send messages and process stream events
The example sends a user message and reads streamed output from bothstatus-update and message events:
task, artifact-update, cancellation, and failure states, use the patterns in A2A Client Integration and Error Handling.
6. Extend the basic chat loop for production
The example intentionally keeps UI logic minimal. Production apps usually add:handleTaskStatusUpdateto drive form, approval, OAuth, and secret promptsresolveUserMetadatato submit structured user responses- Citation and trajectory rendering from message metadata
- Artifact rendering for files and non-text outputs
- Retry and cancellation controls for long-running tasks
Implementation checklist
- Configure
VITE_AGENTSTACK_BASE_URLandVITE_AGENTSTACK_PROVIDER_ID - Create
contextandcontextToken - Build authenticated A2A client
- Resolve agent card demands to metadata
- Send message stream and render updates
- Handle structured UI interactions and errors
Run the reference example
.env with a valid VITE_AGENTSTACK_BASE_URL and VITE_AGENTSTACK_PROVIDER_ID before starting.
Troubleshooting
-
Missing required environment variables.on startupVITE_AGENTSTACK_BASE_URLorVITE_AGENTSTACK_PROVIDER_IDis missing. Check your.envfile and restartpnpm dev. -
Network errors when creating context/token
VITE_AGENTSTACK_BASE_URLis wrong, unreachable, or points to a different environment. Verify the server URL and that the Agent Stack API is running. -
CORS errors in the browser console
The Agent Stack server must allow the frontend origin (for Vite dev,
http://localhost:5173). Update server CORS settings or use a proxy. -
401/403 responses from platform API endpoints
Your server likely requires user auth. Use
buildApiClientwith authenticated fetch (for example,createAuthenticatedFetch(accessToken)), as shown in Getting Started. -
Context token created, but agent run fails with permission-related errors
The token grants may be too narrow for the provider/agent. Recheck
grant_global_permissionsandgrant_context_permissionsin Step 2. -
Provider not found / invalid provider ID errors
VITE_AGENTSTACK_PROVIDER_IDmust match an existing provider on the target server. Confirm the ID in your Agent Stack instance. - UI shows little or no useful output even though requests succeed This example intentionally aggregates only text parts. Agents that return files, data parts, citations, forms, or artifacts need additional rendering logic (see Agent Responses and A2A Client Integration).