Overview
This is a small, functional Blink agent:chat handler - your message and its response become part of the chat’s history. Subsequent invocations access the history via the messages parameter.
Chat Loop
Thechat handler is called in a loop, continuing as long as:
- The agent’s last response contains tool calls
- All tool calls have completed (output available or errored)
- No tool calls are pending approval
Chat Handler
chat handler is invoked whenever:
- A user sends a message
- The model makes tool calls (automatically loops)
- External services trigger a chat via webhooks
messages- Array of all messages in the conversationid- Unique chat identifierabortSignal- For cancellation support
chat handler can return responses using the ai SDK, the OpenAI SDK, the Anthropic SDK, the xAI SDK, or the Google SDK.
Chat Management
Blink automatically manages chat state when you use it via the web UI, but for more advanced use cases, you can manage chats manually.Creating Chats
- Unique for each conversation context
- JSON-serializable
Sending Messages
- interrupt - Stop current processing, handle immediately
- enqueue - Queue message, process after current chat finishes
- append - Add to history without triggering processing
Webhooks
Blink agents can handle webhooks from external services by defining arequest event handler:
Storage API
Blink agents can persist data across invocations using the key-value storageagent.store API:
- OAuth tokens
- User preferences
- Cache data
- Chat associations
- Rate limiting counters
Tool Approvals
Blink agents can require manual approval for destructive operations using theagent.tools.withApproval API: