SDK How-To Guides
Practical, task-focused guides for common SDK operations.
Getting Started
Section titled “Getting Started”- Open a Conversation - Use
sdk.Open()to get started - Send Messages - Send messages with
Send()andStream()
Tools & Functions
Section titled “Tools & Functions”- Register Tools - Add tools with
OnTool() - HTTP Tools - External API calls with
OnToolHTTP() - Client-Side Tools - Device tools with
OnClientTool()
Integrations
Section titled “Integrations”- Configure MCP Servers - Connect MCP tool servers with
NewMCPServer()andWithMCPServer() - Connect A2A Agents - Register remote A2A agents with
NewA2AAgent()andWithA2AAgent()
Declarative Configuration
Section titled “Declarative Configuration”- Use RuntimeConfig - Configure the SDK declaratively with a YAML file
- Exec Tools - Bind tools to external subprocesses in any language
- Exec Hooks - Add external hooks (provider, tool, session) via subprocesses
Variables & Templates
Section titled “Variables & Templates”- Manage Variables - Use
SetVar()andGetVar()
Context Management
Section titled “Context Management”- Manage Context - Configure token budgets and relevance-based truncation
Media Processing
Section titled “Media Processing”- Preprocess Images - Automatically resize and optimize images before sending to LLM providers
Evaluation
Section titled “Evaluation”- Run Evals - Evaluate conversations with
sdk.Evaluate()
Observability
Section titled “Observability”- Monitor Events - Subscribe to events with
hooks.On()
Quick Reference
Section titled “Quick Reference”Open a Conversation
Section titled “Open a Conversation”conv, err := sdk.Open("./app.pack.json", "assistant")if err != nil { log.Fatal(err)}defer conv.Close()Send Message
Section titled “Send Message”resp, err := conv.Send(ctx, "Hello!")fmt.Println(resp.Text())Stream Response
Section titled “Stream Response”for chunk := range conv.Stream(ctx, "Tell me a story") { if chunk.Type == sdk.ChunkDone { break } fmt.Print(chunk.Text)}Register Tool
Section titled “Register Tool”conv.OnTool("get_time", func(args map[string]any) (any, error) { return time.Now().Format(time.RFC3339), nil})Set Variables
Section titled “Set Variables”conv.SetVar("user_name", "Alice")conv.SetVars(map[string]any{ "role": "admin", "language": "en",})Subscribe to Events
Section titled “Subscribe to Events”hooks.On(conv, events.EventProviderCallCompleted, func(e *events.Event) { log.Printf("Provider call completed: %s", e.Type)})By Use Case
Section titled “By Use Case”Building a Chatbot
Section titled “Building a Chatbot”Adding Function Calling
Section titled “Adding Function Calling”- Register Tools
- HTTP Tools (for external APIs)
- Configure MCP Servers (for MCP tools)
Connecting External Agents
Section titled “Connecting External Agents”Declarative Setup
Section titled “Declarative Setup”- Use RuntimeConfig (replace boilerplate with YAML)
- Exec Tools (tools in Python, Node.js, etc.)
- Exec Hooks (external guardrails and audit)
Building Safe AI Agents
Section titled “Building Safe AI Agents”- Register Tools (see Async Tools section for HITL)
- Exec Hooks (external guardrails)
- Monitor Events
Evaluating Conversation Quality
Section titled “Evaluating Conversation Quality”See Also
Section titled “See Also”- Tutorials - Step-by-step learning
- Reference Documentation - API reference
- Examples - Working code examples