Skip to main content
A simple agent is the most basic type of agent in the HasteKit SDK. It executes in-process without durability, making it perfect for stateless interactions, testing, and simple use cases that don’t require crash recovery or long-running workflows.

Overview

Simple agents provide:
  • System instructions: Define the agent’s behavior and personality
  • LLM integration: Use any supported LLM provider (OpenAI, Anthropic, Gemini, etc.)
  • Tool support: Optional tools for function calling
  • Conversation history: Optional memory across interactions
  • Streaming responses: A live channel of response chunks delivered through the run handle
  • Stop signal: Cancel an in-flight run cleanly via handle.Stop
Unlike durable agents, simple agents execute in-process and don’t persist state between runs across restarts. They’re ideal for stateless applications, quick prototypes, and scenarios where you don’t need crash recovery.

Creating a Simple Agent

To create a simple agent, use hastekit.NewAgent() with AgentConfig:

AgentConfig Fields

Executing an Agent

Execute() is non-blocking — it generates a stream id, subscribes to the broker, and returns an *AgentHandle. There are two valid ways to consume the handle:
  • handle.Result() — drains the chunk channel internally and returns the aggregated AgentOutput. Use this when you only care about the final output.
  • for chunk := range handle.Chunks + handle.Wait() — observe chunks as they arrive (e.g. to forward to a UI or SSE stream), then collect the aggregated output.
Call handle.Stop(ctx) at any point to ask the agent to stop at the next iteration boundary.
Or if you want to consume chunks live:

AgentInput Fields

AgentHandle

Execute() returns a handle:
  • Stop records a stop request on the broker; the agent loop polls it at iteration boundaries and transitions to completed.
  • Wait blocks until the run finishes and returns the aggregated output. Safe to call only after Chunks has been drained.
  • Result drains Chunks internally and returns the aggregated output — equivalent to for range Chunks {}; Wait().
Calling Wait without draining Chunks will deadlock once the broker’s per-subscriber buffer fills, because the agent’s publisher back-pressures. Use Result if you don’t intend to consume chunks yourself.

AgentOutput Structure

handle.Wait() returns the aggregated AgentOutput:

Complete Example

Here’s a complete working example:

Streaming Responses

Streaming is built into the handle — every run delivers chunks on handle.Chunks as they arrive:

Stopping an In-Flight Run

handle.Stop(ctx) records a stop request on the broker. The agent’s loop checks this at every iteration boundary (between LLM calls / tool executions) and transitions cleanly to completed. The chunk stream stays open while the agent winds down — you’ll still see the final run.completed chunk before the channel closes.

Helper Functions

The SDK provides convenient helper functions for creating messages:
  • responses.UserMessage(msg string): Creates a user message from a string

Next Steps