Skip to content

Runtime

Core framework powering all PromptKit tools


The Runtime is the foundational layer that provides:

  • Provider interfaces for implementing custom LLM providers
  • Pipeline architecture for streaming request/response processing
  • Stage system for extensible, composable processing layers
  • Type definitions used across all PromptKit tools
  • Tool execution framework for MCP integration
  • Validation system for input/output checking

The Runtime is for advanced users who want to:

  • Build custom providers for new LLM services
  • Create custom stages for specialized processing
  • Extend validators with domain-specific checks
  • Integrate MCP servers with custom tools
  • Understand internals for contributions
  • Customize pipelines for unique requirements

Note: Most users should use the SDK instead. Use Runtime directly only if you’re extending PromptKit.


package main
import (
"context"
"github.com/AltairaLabs/PromptKit/runtime/pipeline/stage"
"github.com/AltairaLabs/PromptKit/runtime/providers/openai"
)
func main() {
// Create provider
provider := openai.NewOpenAIProvider(
"openai", "gpt-4o-mini", "",
openai.DefaultProviderDefaults(),
false,
)
// Build stage-based pipeline
pipeline := stage.NewPipelineBuilder().
Chain(
stage.NewProviderStage(provider, nil, nil, &stage.ProviderConfig{
MaxTokens: 1500,
Temperature: 0.7,
}),
).
Build()
// Execute
input := make(chan stage.StreamElement, 1)
msg := types.Message{Role: "user"}
msg.AddTextPart("Hello!")
input <- stage.NewMessageElement(msg)
close(input)
output, _ := pipeline.Execute(context.Background(), input)
for elem := range output {
if elem.Text != nil {
fmt.Print(*elem.Text)
}
}
}

Next: Build Your First Pipeline Tutorial


Step-by-step guides for extending Runtime:

  1. First Pipeline - Build your first pipeline
  2. Multi-Turn Conversations - State management
  3. MCP Integration - Add MCP tools
  4. Validation & Guardrails - Content safety
  5. Production Deployment - Deploy pipelines
  6. Advanced Patterns - Complex pipelines

Focused guides for specific Runtime tasks:

Deep dives into Runtime architecture:

Complete API documentation:


Implement custom processing stages:

type Stage interface {
Name() string
Type() StageType
Process(ctx context.Context, input <-chan StreamElement, output chan<- StreamElement) error
}

Streaming request processing flow:

Input → [Stage 1] → [Stage 2] → [Stage N] → Output

Each stage runs in its own goroutine, enabling concurrent streaming.

Different stage behaviors:

TypePatternExample
Transform1:1 or 1:NValidation, enrichment
AccumulateN:1VAD buffering, collection
Generate0:NLLM streaming, TTS
SinkN:0State save, metrics

MCP tool integration:

type Tool interface {
Execute(ctx context.Context, params map[string]interface{}) (interface{}, error)
Schema() *ToolSchema
}

graph TB
subgraph "SDK Layer"
SDK[SDK]
end
subgraph "Runtime Layer"
Pipeline[Pipeline]
Stages[Stages]
Providers[Providers]
Tools[Tool Execution]
Validators[Validators]
end
subgraph "External Services"
OpenAI[OpenAI]
Anthropic[Anthropic]
MCP[MCP Servers]
end
SDK --> Pipeline
Pipeline --> Stages
Stages --> Providers
Stages --> Tools
Stages --> Validators
Providers --> OpenAI
Providers --> Anthropic
Tools --> MCP
style Runtime Layer fill:#f3e5f5

  • Add new provider support
  • Implement new stage types
  • Extend validation system
  • Improve core functionality
  • Build custom providers for internal APIs
  • Create domain-specific stages
  • Integrate proprietary LLM services
  • Implement custom tool execution
  • Bridge PromptKit with existing systems
  • Customize request/response handling
  • Add organization-specific features
  • Extend for compliance requirements

Runtime supports three pipeline configurations:

Standard HTTP-based LLM interactions:

Message → StateStoreLoad → PromptAssembly → Provider → StateStoreSave → Response

For voice applications using text-based LLMs:

Audio → AudioTurn → STT → Provider → TTS → Audio

For native multimodal LLMs with real-time audio:

Audio/Text → DuplexProvider → Audio/Text

type StreamElement struct {
Text *string
Audio *AudioData
Message *types.Message
ToolCall *types.ToolCall
Metadata map[string]interface{}
Error error
Timestamp time.Time
}
type Message struct {
Role string
Content string
Parts []ContentPart
}
type Response struct {
Content string
ToolCalls []ToolCall
Usage *Usage
Metadata map[string]interface{}
}

Runtime is designed for streaming from the ground up:

  • Channel-based data flow
  • Concurrent stage execution
  • Backpressure support
  • True streaming (not simulated)

Runtime is designed to be extended without modifying core code:

  • Plugin-based provider system
  • Composable stages
  • Flexible validation
  • Open for extension, closed for modification

Optimized for production use:

  • Minimal allocations
  • Efficient streaming
  • Context-aware cancellation
  • Connection pooling

Leverage Go’s type system:

  • Strong typing throughout
  • Interface-based design
  • Compile-time checks
  • Clear contracts