Hello World Example
The simplest SDK example - open a conversation and send a message.
What You’ll Learn
Section titled “What You’ll Learn”- Opening a conversation from a pack file with
sdk.Open() - Setting template variables with
SetVar() - Sending messages with
Send() - Multi-turn conversation context
Prerequisites
Section titled “Prerequisites”- Go 1.21+
- OpenAI API key
Running the Example
Section titled “Running the Example”export OPENAI_API_KEY=your-keygo run .Code Overview
Section titled “Code Overview”// Open a conversation from a pack fileconv, err := sdk.Open("./hello.pack.json", "chat")if err != nil { log.Fatal(err)}defer conv.Close()
// Set template variables (substituted in system prompt)conv.SetVar("user_name", "World")
// Send a message and get a responsectx := context.Background()resp, err := conv.Send(ctx, "Say hello!")fmt.Println(resp.Text())
// Context is maintained across turnsresp, _ = conv.Send(ctx, "What's my name?")fmt.Println(resp.Text()) // Remembers "World"Pack File Structure
Section titled “Pack File Structure”The hello.pack.json defines:
- Provider: OpenAI with
gpt-4o-mini - Prompt: A friendly assistant with
{{user_name}}template variable
{ "prompts": { "chat": { "system_template": "You are a friendly assistant. The user's name is {{user_name}}." } }}Key Concepts
Section titled “Key Concepts”- Pack-First Design - All configuration lives in the pack file
- Template Variables - Use
{{variable}}in prompts, set withSetVar() - Conversation Context - Messages are remembered across
Send()calls - Resource Cleanup - Always
defer conv.Close()
Next Steps
Section titled “Next Steps”- Streaming Example - Real-time response streaming
- Tools Example - Function calling
- HITL Example - Human-in-the-loop approval