hastekit.NewHTTPHandler() returns an http.Handler that dispatches to any registered agent, making it compatible with Go’s standard net/http package.
Creating an HTTP Server
Register your agents withhastekit.NewAgent, then serve hastekit.NewHTTPHandler():
Invoking an Agent
Send a POST request tohttp://localhost:8070/?agent=<agent-name> with the request body as agents.AgentInput:
messages key maps to AgentInput.Message, which is a single message object (not an array). It holds a sender_id and the actual messages array of input messages.
Response: Server-Sent Events
The handler streams the run back as an event stream, not a single JSON body. It setsContent-Type: text/event-stream and emits one frame per chunk:
http.Flusher); if it doesn’t, it responds with 500 streaming unsupported. Clients should read the response as an SSE stream and process each data: payload as it arrives.
Request Structure
The request body follows theagents.AgentInput structure:
history.Message (an alias of messages.Message) carries a sender-attributed bundle of provider messages:
namespace- Optional. Namespace for conversation isolationthread_id- Optional. Thread to continue (or empty to start a new one)previous_message_id- Optional. Previous message ID for conversation historymessages- Required. A single message bundle (history.Message) with asender_idand themessagesarray of input messagesrun_context- Optional. Additional context for the executionstream_id- Optional. Broker channel id; the server generates one if empty. The HTTP handler streams chunks back as Server-Sent Events as the run progresses.shared_session_id- Optional. Conversation ID shared by a parent agent and its sub-agent
Complete Example
Serving over AG-UI
The rawhttp.Handler above is the simplest way to expose an agent, but it speaks the SDK’s own AgentInput shape. For a standards-based option that works with CopilotKit and other off-the-shelf clients — and a ready-made browser chat UI — serve your agents over the AG-UI protocol instead. See Serving Agents over AG-UI.