Skip to main content

Overview

This is a small, functional Blink agent:
Conversations are organized into chats. When you send a message, the Blink platform invokes the 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

The chat 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
The loop stops when there are no tool calls, a tool is awaiting approval, or an error occurs.

Chat Handler

The chat handler is invoked whenever:
  • A user sends a message
  • The model makes tool calls (automatically loops)
  • External services trigger a chat via webhooks
Parameters:
  • messages - Array of all messages in the conversation
  • id - Unique chat identifier
  • abortSignal - For cancellation support
The 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

Chat keys should be:
  • Unique for each conversation context
  • JSON-serializable

Sending Messages

Behaviors:
  • 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 a request event handler:
You may use it to trigger actions in your agent, such as sending a message to a chat.

Storage API

Blink agents can persist data across invocations using the key-value storage agent.store API:
Use cases:
  • OAuth tokens
  • User preferences
  • Cache data
  • Chat associations
  • Rate limiting counters

Tool Approvals

Blink agents can require manual approval for destructive operations using the agent.tools.withApproval API: