Files
kit/examples/sdk
Ed Zynda 558fb5214f feat(sdk): expose remaining Fantasy lifecycle callbacks as events and hooks
Closes #19.

SDK events (pkg/kit):
- Add 10 new event types: StepStart, StepFinish, TextStart, TextEnd,
  ReasoningStart, Warnings, Source, StreamFinish, Error, Retry
- Add typed convenience subscribers for all 31 event types (20 previously
  required raw Subscribe + type assertion)
- Add OnPrepareStep hook for intercepting/replacing messages between
  steps within a multi-step turn (composes with existing steering)
- Rename OnStreaming to OnMessageUpdate (deprecated alias kept)

Agent internals (internal/agent):
- Add GenerateCallbacks struct replacing 16 positional callback params
- Add GenerateWithCallbacks method; deprecate GenerateWithLoopAndStreaming
- Wire all Fantasy stream callbacks: OnStepStart, OnTextStart/End,
  OnReasoningStart, OnWarnings, OnSource, OnStreamFinish, OnError,
  OnRetry, OnStepFinish (unified step event)
- Compose PrepareStep with steering channel + consumer hook

Extension system (internal/extensions):
- Add 8 new extension events: StepStart, StepFinish, ReasoningStart,
  Warnings, Source, Error, Retry, PrepareStep
- Bridge SDK events to extension runner with Yaegi-safe types (string
  errors, plain int64 token fields, ContextMessage for PrepareStep)

Docs: update README, SDK skill, www/sdk/callbacks, www/sdk/overview
2026-04-22 20:25:06 +03:00
..
2026-03-23 16:08:25 +03:00

SDK Examples

These examples demonstrate how to use the Kit SDK (pkg/kit) to build agents programmatically in Go.

Examples

basic

Shows core SDK usage: creating a Kit instance, sending prompts, overriding the model, subscribing to events (tool calls, streaming), and session management.

go run ./examples/sdk/basic

scripting

A minimal script-friendly wrapper that takes a prompt from the command line and prints the response — useful for piping and automation.

go run ./examples/sdk/scripting "Explain what this repo does"

crypto-monitor

A background agent that checks Bitcoin and Ethereum prices every 30 minutes and sends desktop notifications via notify-send (dbus). Demonstrates using the SDK for a long-running autonomous task with a single tool.

go run ./examples/sdk/crypto-monitor

# Override the check interval:
CRYPTO_INTERVAL=5m go run ./examples/sdk/crypto-monitor

Getting Started

import kit "github.com/mark3labs/kit/pkg/kit"

host, err := kit.New(ctx, nil)        // uses ~/.kit.yml defaults
defer host.Close()

response, err := host.Prompt(ctx, "Hello!")

See the SDK README for the full API reference.