Skip to content
agentkit

go · agents · built on llmkit

Agents that stay inside their budget.

Write a tool as a Go function and agentkit derives its JSON Schema, validates every call, runs the model/tool loop with step, token and time budgets, and streams what happens. Memory, MCP servers and multi-agent handoffs are one option each. Any of llmkit's twelve providers, by model name.

MIT licensed · pure Go 1.27 · two dependencies

main.go
weather := agentkit.Func("weather", "Current weather for a city",
    func(ctx context.Context, in struct{ City string `json:"city"` }) (string, error) {
        return lookup(in.City), nil
    })
agent, _ := agentkit.New("claude-sonnet-4-5",
    agentkit.WithTools(weather),
    agentkit.WithBudget(agentkit.Budget{MaxSteps: 8}))
res, _ := agent.Run(ctx, "Weather in Cape Town?")
// res.Output, res.Steps, res.Usage.TotalTokens

what you get

Small primitives, honest transcripts.

Every tool call gets its result, even when a budget or a cancellation stops the step half way, so transcripts stay valid for every provider.

Typed tools

Func[In, Out] derives the schema from your struct tags, validates arguments before your code runs, and marshals the result. Middleware adds timeouts, approval gates and panic recovery.

Budgets

Steps, tokens, tool calls, handoffs and wall time. A stop returns the partial Result with a typed BudgetError; nothing is lost.

Streaming events

Stream yields text deltas, tool calls, results, retries, compactions and a final result as an iter.Seq2. Break to cancel.

Typed output

Run[T] returns a decoded Go value: JSON-schema output where the provider supports it, a final_answer tool everywhere else.

Memory

Lossless session stores, window and summary compaction that never splits a tool call from its result, and vector recall over any llmkit embedder.

Multi-agent & MCP

Sub-agents as tools, Swarm-style handoffs, bounded Map fan-out — and every tool of an MCP server, via the nested agentkit/mcp module.

usage

Stream it, or ask for a struct.

// Stream events as the run progresses
for e, err := range agent.Stream(ctx, "Plan my week") {
    if err != nil { return err }
    switch e.Kind {
    case agentkit.EventText:     fmt.Print(e.Text)
    case agentkit.EventToolCall: log(e.ToolCall.Name)
    case agentkit.EventFinish:   log(e.Result.StopReason)
    }
}
// Typed final answer
type Forecast struct {
    City  string `json:"city"`
    TempC int    `json:"temp_c"`
}
forecast, res, err := agentkit.Run[Forecast](ctx, agent,
    "Forecast for Cape Town?")
  • Func
  • New
  • Run
  • Stream
  • Run[T]
  • Budget
  • Approve
  • Window
  • Summarize
  • AsTool
  • Handoff
  • Map

install

Add it to your module.

Requires Go 1.27+. The MCP bridge is a separate module you opt into.

go get go get github.com/richardwooding/agentkit
optional go get github.com/richardwooding/agentkit/mcp

Full API on pkg.go.dev · models come from llmkit.