Documentation
¶
Overview ¶
Package pipeline provides internal pipeline construction for the SDK.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Build ¶
func Build(cfg *Config) (*stage.StreamPipeline, error)
Build creates a stage-based streaming pipeline.
Stage order:
- StateStoreLoadStage - Load conversation history (if configured)
- VariableProviderStage - Dynamic variable resolution (if configured)
- PromptAssemblyStage - Load and assemble prompt from registry
- TemplateStage - Prepare system prompt for provider
- ProviderStage/DuplexProviderStage - LLM call with streaming support
- StateStoreSaveStage - Save conversation state (if configured)
This matches the runtime pipeline used by Arena.
func BuildAudioTrackStages ¶ added in v1.5.6
func BuildAudioTrackStages( namePrefix string, includeResample bool, vad stage.AudioTurnConfig, stt stage.STTStageConfig, sttSvc base.STTProvider, ) ([]stage.Stage, error)
BuildAudioTrackStages returns the ordered stages for one named audio track: [Resample→]AudioTurn(VAD)→STT. namePrefix uniquifies stage names (e.g. "caller") so multiple tracks can be wired into the same pipeline graph without name collisions; pass "" to keep the constructors' natural names (single-track case). Reused by both the VAD front (buildVADPipelineStages, includeResample=false to keep that topology byte-for-byte unchanged) and custom ingestion sub-graphs that need to feed one or more raw audio tracks — possibly at an arbitrary sample rate — into the standard agent chain (includeResample=true).
When includeResample is true, the AudioResampleStage normalizes the track to vad.SampleRate (falling back to the package default when unset) before VAD/turn-detection runs, and is a no-op passthrough when the source is already at that rate — see runtime/pipeline/stage/stages_resample.go.
func BuildStreamPipeline ¶ added in v1.1.6
func BuildStreamPipeline(cfg *Config) (*stage.StreamPipeline, error)
BuildStreamPipeline is deprecated, use Build instead. Kept for backward compatibility.
Types ¶
type Config ¶
type Config struct {
// Provider for LLM calls
Provider providers.Provider
// ToolRegistry for tool execution (optional)
ToolRegistry *tools.Registry
// PromptRegistry for loading prompts (required for PromptAssemblyStage)
PromptRegistry *prompt.Registry
// TaskType is the prompt ID/task type to load from the registry
TaskType string
// Variables for template substitution
Variables map[string]string
// VariableProviders for dynamic variable resolution (optional)
VariableProviders []variables.Provider
// ToolPolicy for tool usage constraints (optional)
ToolPolicy *rtpipeline.ToolPolicy
// WorkflowStateResolver applies workflow state changes between tool-loop
// rounds, so a transition's destination state generates the next round
// rather than the turn ending with the origin state in control. Optional;
// nil for non-workflow conversations.
WorkflowStateResolver stage.WorkflowStateResolver
// TokenBudget for context management (0 = no limit)
TokenBudget int
// TruncationStrategy for context management ("sliding", "summarize", or "relevance")
TruncationStrategy string
// RelevanceConfig for embedding-based truncation (optional, used with "relevance" strategy)
RelevanceConfig *stage.RelevanceConfig
// MaxTokens for LLM response
MaxTokens int
// Temperature for LLM response
Temperature float32
// ResponseFormat for JSON mode output (optional)
ResponseFormat *providers.ResponseFormat
// StateStore for conversation history persistence (optional)
// When provided, StateStoreLoad/Save stages will be added to the pipeline
StateStore statestore.Store
// ConversationID for state store operations
ConversationID string
// MessageLog for per-round write-through during tool loops (optional).
// When set, the provider stage persists messages per-round and the
// save stage skips message append.
MessageLog statestore.MessageLog
// CompactionEnabled controls context compaction in tool loops.
// nil = default (enabled), false = disabled.
CompactionEnabled *bool
// ToolSelector narrows the pack-declared allowedTools per turn
// before they're sent to the provider. Optional; when nil the
// provider sees the full allowedTools list (existing behavior).
ToolSelector selection.Selector
// ApprovalChecker, when set, gates tool execution for human-in-the-loop
// approval on the standard ProviderStage: a tool the checker holds is
// surfaced as pending instead of executing. Optional; nil executes normally.
ApprovalChecker tools.ApprovalChecker
// CompactionStrategy replaces the default compactor entirely.
// Mutually exclusive with CompactionRules.
CompactionStrategy stage.CompactionStrategy
// CompactionRules configures custom rules on the default ContextCompactor.
// Mutually exclusive with CompactionStrategy.
CompactionRules []stage.CompactionRule
// ContextWindow is the hot window size for RAG context assembly.
// When > 0, ContextAssemblyStage + IncrementalSaveStage replace the
// standard StateStoreLoad/Save stages.
ContextWindow int
// MessageIndex for semantic retrieval of relevant older messages (optional).
MessageIndex statestore.MessageIndex
// RetrievalTopK is the number of results to retrieve from the message index.
RetrievalTopK int
// Summarizer for auto-summarization (optional).
Summarizer statestore.Summarizer
// SummarizeThreshold is the message count above which summarization triggers.
SummarizeThreshold int
// SummarizeBatchSize is how many messages to summarize at once.
SummarizeBatchSize int
// StreamInputProvider for duplex streaming (ASM mode) (optional)
// When provided with StreamInputConfig, DuplexProviderStage will be used.
// The stage creates the session lazily using TurnState.SystemPrompt
// (published by PromptAssemblyStage / TemplateStage).
StreamInputProvider providers.StreamInputSupport
// StreamInputConfig for duplex streaming session creation (ASM mode) (optional).
// The system prompt is sourced from TurnState by the duplex stage.
StreamInputConfig *providers.StreamingInputConfig
// ReorderInputTranscript inserts a TranscriptReorderStage after the provider
// stage so each turn's user transcript is emitted before that turn's assistant
// text — needed for providers that deliver the transcript late (OpenAI
// Realtime). Resolved by the SDK from the provider's LateInputTranscriber
// capability + the streaming config's additional properties.
ReorderInputTranscript bool
// InputTranscriptPlaceholder is the user-turn text synthesized by the reorder
// stage when a turn ends with no transcription (empty omits the user turn).
InputTranscriptPlaceholder string
// PaceOutputAudio inserts an output-direction AudioPacingStage after the
// provider/TTS stage so response audio is forwarded at real-time cadence.
// Set when the pipeline drives a realtime speaker (OpenVoice / a bound
// audio.Session): a streaming provider delivers a whole reply faster than
// realtime, and an unpaced burst overruns the sink's ~200ms jitter buffer,
// dropping the oldest audio (audible stutter/corruption). Leave false for
// headless/manual consumers (OpenDuplex reading Response() directly) — pacing
// would only slow them down with no realtime sink to protect.
PaceOutputAudio bool
// UseStages is deprecated and ignored - stages are always used.
// This field is kept for backward compatibility but has no effect.
UseStages bool
// VADConfig configures the AudioTurnStage for VAD mode
VADConfig *stage.AudioTurnConfig
// Ingestion, when non-nil, authors a custom upstream stage sub-graph whose
// output node feeds the standard agent chain. Mutually exclusive with the
// VAD/ASM front. The callback adds stages/edges to the shared builder and
// returns the name of the node whose output feeds the agent chain.
Ingestion func(b *stage.PipelineBuilder) (outputNode string, err error)
// STTService for speech-to-text in VAD mode
STTService base.STTProvider
// STTConfig configures the STTStage
STTConfig *stage.STTStageConfig
// TTSService for text-to-speech in VAD mode
TTSService tts.Service
// TTSConfig configures the TTSStageWithInterruption
TTSConfig *stage.TTSStageWithInterruptionConfig
// InterruptionHandler shared between AudioTurnStage and TTSStage for barge-in support
InterruptionHandler *audio.InterruptionHandler
// ImagePreprocessConfig configures image preprocessing (resizing, optimization)
// When non-nil, ImagePreprocessStage is added before the provider stage
ImagePreprocessConfig *stage.ImagePreprocessConfig
// VideoStreamConfig configures frame rate limiting for realtime video streaming.
// When non-nil and TargetFPS > 0, a FrameRateLimitStage is added before the provider stage.
VideoStreamConfig *stage.FrameRateLimitConfig
// EventEmitter for emitting provider call events (optional)
// When provided, ProviderStage will emit ProviderCallStarted/Completed/Failed events
EventEmitter *events.Emitter
// HookRegistry for policy enforcement hooks (optional)
// When provided, ProviderStage will use hooks for provider call, chunk, and tool interception
HookRegistry *hooks.Registry
// MemoryRetriever for automatic memory RAG injection (optional).
// When set, a MemoryRetrievalStage is added before the provider stage.
MemoryRetriever memory.Retriever
// MemoryExtractor for automatic memory extraction (optional).
// When set, a MemoryExtractionStage is added after the provider stage.
MemoryExtractor memory.Extractor
// MemoryStore for memory persistence (required if Retriever or Extractor set).
MemoryStore memory.Store
// MemoryScope for memory isolation.
MemoryScope map[string]string
// MemoryContextFormatter overrides the rendering of retrieved memories
// into the "memory_context" template variable. Defaults to
// [memory.DefaultContextFormatter] when nil.
MemoryContextFormatter memory.ContextFormatter
// ExecutionTimeout overrides the default pipeline execution timeout.
// When non-nil, the pointed-to duration is used instead of the default 30s.
// A zero value disables timeout entirely.
ExecutionTimeout *time.Duration
// RecordingConfig enables recording stages in the pipeline.
// When set, input and output RecordingStages are inserted to capture
// full binary content for session replay.
RecordingConfig *stage.RecordingStageConfig
// RecordingStore is the destination for recording stage writes.
// Required when RecordingConfig is set; without it, recording stages
// will not be added to the pipeline.
RecordingStore events.EventStore
// ClassifyRegistry is attached to the pipeline execution context.
// When non-nil, stages and downstream consumers can resolve inference
// backends via classify.FromContext.
ClassifyRegistry *classify.Registry
// ActiveComposition, when non-nil, makes the work stage a CompositionStage
// that runs this composition instead of an LLM ProviderStage (RFC 0010).
ActiveComposition *composition.Composition
// CompositionName labels the CompositionStage (typically the state's composition name).
// Falls back to "composition" when empty.
CompositionName string
// SchemaResolver resolves a step's output_schema path to JSON-schema bytes.
// nil means no structured output is used.
SchemaResolver func(path string) (json.RawMessage, error)
}
Config holds configuration for building a pipeline.