Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func TruncateResponses ¶
TruncateResponses returns a copy of responses where, if the total character count exceeds maxTotalChars, the longest responses are proportionally truncated so the combined length fits within the budget. Truncated entries have "[truncated]" appended.
Types ¶
type ConsensusAnalysis ¶ added in v0.2.0
type ConsensusAnalysis struct {
Recommendation string
Confidence string // "high", "medium", "low", or ""
Agreements []string
MinorityReports []MinorityReport
Evidence []string
Raw string // the full original synthesis text
}
ConsensusAnalysis holds the structured breakdown of a consensus synthesis.
func ParseConsensusAnalysis ¶ added in v0.2.0
func ParseConsensusAnalysis(rawOutput string) *ConsensusAnalysis
ParseConsensusAnalysis extracts structured sections from the primary model's synthesis output. If the output does not contain structured headers (## ), the full text is returned as both Recommendation and Raw (graceful degradation).
type Engine ¶
type Engine struct {
// contains filtered or unexported fields
}
Engine drives the consensus synthesis step. It takes the collected responses from a fan-out query and asks a primary provider to synthesize them into a single authoritative answer.
func NewEngine ¶
NewEngine creates a consensus Engine.
- primary is the provider used to synthesize the final answer.
- timeout is the maximum time allowed for the synthesis query.
- minResponses is the minimum number of successful responses required before synthesis can proceed.
func (*Engine) BuildConsensusPrompt ¶
func (e *Engine) BuildConsensusPrompt(originalPrompt string, responses map[string]string, mode SynthesisMode) []provider.Message
BuildConsensusPrompt constructs the message slice sent to the primary provider for synthesis. The mode controls the depth of analysis requested.
func (*Engine) Synthesize ¶
func (e *Engine) Synthesize( ctx context.Context, originalPrompt string, responses map[string]string, opts provider.QueryOpts, ) (<-chan provider.StreamChunk, error)
Synthesize sends the consensus prompt to the primary provider and returns the streaming response channel. The caller is responsible for consuming the channel.
type FanOutResult ¶
type FanOutResult struct {
// Responses maps provider ID to the full assembled response text.
Responses map[string]string
// Errors maps provider ID to any error encountered during the query.
Errors map[string]error
// Usage maps provider ID to the token usage reported by that provider.
Usage map[string]tokens.Usage
// Latencies maps provider ID to the response wall-clock duration.
Latencies map[string]time.Duration
// Skipped lists provider IDs that were skipped due to context limits.
Skipped []string
}
FanOutResult holds the collected responses and errors from a fan-out query to multiple providers.
func FanOut ¶
func FanOut( ctx context.Context, providers []provider.Provider, messages []provider.Message, opts provider.QueryOpts, timeout time.Duration, tracker *tokens.TokenTracker, ) *FanOutResult
FanOut dispatches a query to all providers concurrently, collects their streaming responses into complete strings, and returns once every provider has finished or the timeout is reached.
If a tracker is provided, providers that would exceed their context limit are skipped (recorded in result.Skipped).
type MinorityReport ¶ added in v0.2.0
MinorityReport captures a dissenting view from the consensus.
type Pipeline ¶
type Pipeline struct {
// contains filtered or unexported fields
}
Pipeline orchestrates the full consensus workflow: fan-out query to all providers, threshold check, and synthesis via the primary provider.
func NewPipeline ¶
func NewPipeline( providers []provider.Provider, primary provider.Provider, timeout time.Duration, minResponses int, tracker *tokens.TokenTracker, mode SynthesisMode, ) *Pipeline
NewPipeline creates a Pipeline.
- providers is the full set of providers to fan-out to.
- primary is the provider used for the synthesis step.
- timeout is the per-phase timeout (fan-out and synthesis each get this).
- minResponses is the minimum number of successful fan-out responses required before synthesis proceeds.
- tracker is optional (may be nil) for token usage tracking and limit enforcement.
- mode controls synthesis depth (quick/balanced/thorough).
func (*Pipeline) Run ¶
func (p *Pipeline) Run( ctx context.Context, messages []provider.Message, opts provider.QueryOpts, ) (<-chan provider.StreamChunk, *FanOutResult, error)
Run executes the full consensus pipeline:
- Fan-out the query to every provider.
- Check the minimum-response threshold.
- If only the primary provider responded, return its response directly without synthesis.
- Otherwise, synthesize the collected responses through the primary.
It returns the streaming consensus channel, the raw fan-out results (so the TUI can display individual responses), and any error.
type SynthesisMode ¶ added in v1.11.0
type SynthesisMode string
SynthesisMode controls the depth of the consensus synthesis prompt.
const ( // SynthesisQuick produces a concise, direct answer without structured sections. SynthesisQuick SynthesisMode = "quick" // SynthesisBalanced produces a structured synthesis with confidence, agreements, // minority reports, and evidence sections. SynthesisBalanced SynthesisMode = "balanced" // SynthesisThorough produces deep analysis with extended reasoning, trade-off // analysis, step-by-step verification, and alternative approaches. SynthesisThorough SynthesisMode = "thorough" )