SDK Reference
Complete reference documentation for the PromptKit SDK API.
Overview
Section titled “Overview”The SDK provides a pack-first API that reduces boilerplate by ~80%.
Core Functions
Section titled “Core Functions”sdk.Open
Section titled “sdk.Open”Opens a conversation from a pack file.
func Open(packPath string, promptName string, opts ...Option) (*Conversation, error)Parameters:
packPath- Path to the .pack.json filepromptName- Name of the prompt from the packopts- Optional configuration options
Returns:
*Conversation- Ready-to-use conversationerror- Error if pack or prompt not found
Example:
conv, err := sdk.Open("./app.pack.json", "assistant")Options
Section titled “Options”WithModel
Section titled “WithModel”Override the model.
sdk.WithModel("gpt-4o")WithUserID
Section titled “WithUserID”Set a pseudonymous user identifier for cross-session correlation (e.g., memory, analytics). PromptKit does not manage user-to-session mapping — that is the operator’s concern.
sdk.WithUserID("virtual-user-abc")WithSessionMetadata
Section titled “WithSessionMetadata”Attach arbitrary key-value metadata to the session. Metadata is persisted in the state store and available to capabilities via CapabilityContext.
sdk.WithSessionMetadata(map[string]any{ "tenant": "acme-corp", "channel": "web-chat",})WithImageFile
Section titled “WithImageFile”Attach an image from a file.
sdk.WithImageFile("/path/to/image.png")WithImageURL
Section titled “WithImageURL”Attach an image from a URL.
sdk.WithImageURL("https://example.com/image.jpg")WithImageData
Section titled “WithImageData”Attach image from raw bytes.
sdk.WithImageData(imageBytes, "image/png")WithDocumentFile
Section titled “WithDocumentFile”Attach a PDF document from a file.
sdk.WithDocumentFile("/path/to/document.pdf")WithDocumentData
Section titled “WithDocumentData”Attach a PDF document from raw bytes.
sdk.WithDocumentData(pdfBytes, "application/pdf")WithProviderHook
Section titled “WithProviderHook”Register a hook that intercepts LLM provider calls (before/after). Multiple hooks execute in order; the first deny short-circuits.
sdk.WithProviderHook(guardrails.NewBannedWordsHook([]string{"hack"}))WithToolHook
Section titled “WithToolHook”Register a hook that intercepts LLM-initiated tool calls (before/after).
sdk.WithToolHook(myToolAuditHook)WithSessionHook
Section titled “WithSessionHook”Register a hook for tracking session lifecycle (start, update, end).
sdk.WithSessionHook(mySessionLogger)WithAudioFile
Section titled “WithAudioFile”Attach an audio file.
sdk.WithAudioFile("/path/to/audio.mp3")WithVideoFile
Section titled “WithVideoFile”Attach a video file.
sdk.WithVideoFile("/path/to/video.mp4")WithRecording
Section titled “WithRecording”Enable session recording by inserting RecordingStages into the pipeline. These stages capture full binary content (images, audio, video) and publish events directly to the EventBus for session replay.
If cfg is nil, default settings are used (audio=true, video=false, images=true). An EventBus is automatically created if none was provided via WithEventBus.
// Use defaultssdk.WithRecording(nil)
// Custom configsdk.WithRecording(&sdk.RecordingConfig{ IncludeAudio: true, IncludeVideo: true, IncludeImages: true,})WithCompaction
Section titled “WithCompaction”Control context compaction in tool loops. Compaction is on by default — the context compactor folds stale tool results between rounds to prevent context overflow. Pass false to disable.
// Disable compaction (default: enabled)sdk.WithCompaction(false)WithMessageLog
Section titled “WithMessageLog”Enable per-round write-through persistence during tool loops. When set, messages are appended to the log after each LLM round for durability:
sdk.WithMessageLog(myMessageLog)The MessageLog interface is defined in runtime/statestore. MemoryStore implements it out of the box.
Conversation Type
Section titled “Conversation Type”Send a message and get a response.
func (c *Conversation) Send(ctx context.Context, message any, opts ...SendOption) (*Response, error)Stream
Section titled “Stream”Stream a response.
func (c *Conversation) Stream(ctx context.Context, message any, opts ...SendOption) <-chan StreamChunkSetVar
Section titled “SetVar”Set a template variable.
func (c *Conversation) SetVar(name, value string)GetVar
Section titled “GetVar”Get a template variable.
func (c *Conversation) GetVar(name string) (string, bool)SetVars
Section titled “SetVars”Set multiple variables.
func (c *Conversation) SetVars(vars map[string]any)OnTool
Section titled “OnTool”Register a tool handler.
func (c *Conversation) OnTool(name string, handler ToolHandler)OnToolCtx
Section titled “OnToolCtx”Register a tool handler with context.
func (c *Conversation) OnToolCtx(name string, handler ToolHandlerCtx)OnTools
Section titled “OnTools”Register multiple tool handlers.
func (c *Conversation) OnTools(handlers map[string]ToolHandler)OnToolAsync
Section titled “OnToolAsync”Register a tool with approval workflow.
func (c *Conversation) OnToolAsync(name string, check func(args map[string]any) tools.PendingResult, execute ToolHandler)OnToolHTTP
Section titled “OnToolHTTP”Register an HTTP tool.
func (c *Conversation) OnToolHTTP(name string, config *tools.HTTPToolConfig)EventBus
Section titled “EventBus”Get the event bus for subscribing to events via the hooks package.
func (c *Conversation) EventBus() events.BusExample:
hooks.On(conv, events.EventProviderCallCompleted, func(e *events.Event) { log.Printf("Provider call completed: %s", e.Type)})Messages
Section titled “Messages”Get conversation history.
func (c *Conversation) Messages(ctx context.Context) []types.MessageClear conversation history.
func (c *Conversation) Clear() errorCreate an isolated copy.
func (c *Conversation) Fork() *ConversationClose the conversation.
func (c *Conversation) Close() errorGet conversation ID.
func (c *Conversation) ID() stringResolveTool
Section titled “ResolveTool”Approve a pending tool.
func (c *Conversation) ResolveTool(id string) (*tools.ToolResolution, error)RejectTool
Section titled “RejectTool”Reject a pending tool.
func (c *Conversation) RejectTool(id string, reason string) (*tools.ToolResolution, error)Response Type
Section titled “Response Type”Get response text.
func (r *Response) Text() stringHasToolCalls
Section titled “HasToolCalls”Check for tool calls.
func (r *Response) HasToolCalls() boolToolCalls
Section titled “ToolCalls”Get tool calls.
func (r *Response) ToolCalls() []types.MessageToolCallPendingTools
Section titled “PendingTools”Get pending approvals.
func (r *Response) PendingTools() []PendingToolStreamChunk Type
Section titled “StreamChunk Type”type StreamChunk struct { Type ChunkType // ChunkText, ChunkToolCall, ChunkMedia, ChunkDone Text string // Text content (for ChunkText) ToolCall *types.MessageToolCall // Tool call (for ChunkToolCall) Media *types.MediaContent // Media content (for ChunkMedia) Message *Response // Complete response (for ChunkDone) Error error // Error if any}ChunkType Constants
Section titled “ChunkType Constants”const ( ChunkText ChunkType = iota // 0 - text content ChunkToolCall // 1 - tool call ChunkMedia // 2 - media content ChunkDone // 3 - streaming complete)Handler Types
Section titled “Handler Types”ToolHandler
Section titled “ToolHandler”type ToolHandler func(args map[string]any) (any, error)ToolHandlerCtx
Section titled “ToolHandlerCtx”type ToolHandlerCtx func(ctx context.Context, args map[string]any) (any, error)Error Types
Section titled “Error Types”var ( ErrConversationClosed = errors.New("conversation is closed") ErrConversationNotFound = errors.New("conversation not found") ErrNoStateStore = errors.New("no state store configured") ErrPromptNotFound = errors.New("prompt not found in pack") ErrPackNotFound = errors.New("pack file not found") ErrProviderNotDetected = errors.New("could not detect provider: no API keys found in environment") ErrToolNotRegistered = errors.New("tool handler not registered") ErrToolNotInPack = errors.New("tool not defined in pack"))Package Import
Section titled “Package Import”import ( "github.com/AltairaLabs/PromptKit/sdk" "github.com/AltairaLabs/PromptKit/sdk/hooks" "github.com/AltairaLabs/PromptKit/sdk/tools"
// Hooks & guardrails rthooks "github.com/AltairaLabs/PromptKit/runtime/hooks" "github.com/AltairaLabs/PromptKit/runtime/hooks/guardrails")Additional References
Section titled “Additional References”Audio & Voice
Section titled “Audio & Voice”- Audio API - VAD mode, ASM mode, turn detection, audio streaming
- TTS API - Text-to-speech services, voices, formats, providers
- Streaming Package - Bidirectional streaming utilities, response collection, audio streaming
Dynamic Variables
Section titled “Dynamic Variables”- Variable Providers - Dynamic variable resolution, built-in providers, custom providers
A2A Server
Section titled “A2A Server”- A2A Server - A2AServer, A2ATaskStore, A2AConversationOpener
Related
Section titled “Related”- ConversationManager - Legacy conversation management