mirror of
https://github.com/mark3labs/kit.git
synced 2026-06-14 03:30:26 +00:00
ef8628eecc
The spawner closure in generate() called m.Subagent() without setting OnEvent, so child events (tool calls, text streaming, reasoning deltas) were silently discarded. Wire OnEvent to re-emit on the parent's bus, matching the behavior already present in the extension SpawnSubagent path.
KIT SDK
The KIT SDK allows you to use KIT programmatically from Go applications without spawning OS processes.
Installation
go get github.com/mark3labs/kit
Basic Usage
package main
import (
"context"
"fmt"
"log"
kit "github.com/mark3labs/kit/pkg/kit"
)
func main() {
ctx := context.Background()
// Create Kit instance with default configuration
host, err := kit.New(ctx, nil)
if err != nil {
log.Fatal(err)
}
defer host.Close()
// Send a prompt
response, err := host.Prompt(ctx, "What is 2+2?")
if err != nil {
log.Fatal(err)
}
fmt.Println(response)
}
Configuration
The SDK behaves identically to the CLI:
- Loads configuration from
~/.kit.ymlby default - Creates default configuration if none exists
- Respects all environment variables (
KIT_*) - Uses the same defaults as the CLI
Options
You can override specific settings:
host, err := kit.New(ctx, &kit.Options{
Model: "ollama/llama3", // Override model
SystemPrompt: "You are a helpful bot", // Override system prompt
ConfigFile: "/path/to/config.yml", // Use specific config file
MaxSteps: 10, // Override max steps
Streaming: true, // Enable streaming
Quiet: true, // Suppress debug output
})
Advanced Usage
With Tool Callbacks
Monitor tool execution in real-time:
response, err := host.PromptWithCallbacks(
ctx,
"List files in the current directory",
func(name, args string) {
fmt.Printf("Calling tool: %s\n", name)
},
func(name, args, result string, isError bool) {
if isError {
fmt.Printf("Tool %s failed: %s\n", name, result)
} else {
fmt.Printf("Tool %s succeeded\n", name)
}
},
func(chunk string) {
fmt.Print(chunk) // Stream output
},
)
Session Management
Maintain conversation context:
// First message
host.Prompt(ctx, "My name is Alice")
// Second message (remembers context)
response, _ := host.Prompt(ctx, "What's my name?")
// Response: "Your name is Alice"
// Save session
host.SaveSession("./session.json")
// Load session later
host.LoadSession("./session.json")
// Clear session
host.ClearSession()
API Reference
Types
Kit- Main SDK typeOptions- Configuration optionsMessage- Conversation messageToolCall- Tool invocation details
Methods
New(ctx, opts)- Create new Kit instancePrompt(ctx, message)- Send message and get responsePromptWithCallbacks(ctx, message, ...)- Send message with progress callbacksLoadSession(path)- Load session from fileSaveSession(path)- Save session to fileClearSession()- Clear conversation historyGetSessionManager()- Get session manager for advanced usageGetModelString()- Get current model stringClose()- Clean up resources
Environment Variables
All CLI environment variables work with the SDK:
KIT_MODEL- Override modelANTHROPIC_API_KEY- Anthropic API keyOPENAI_API_KEY- OpenAI API keyGEMINI_API_KEY- Google API key- etc.
License
Same as KIT CLI