deliberation

package
v1.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 25, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrDecisionRejected = errors.New("decision rejected by human reviewer")

ErrDecisionRejected is returned when a human reviewer rejects a low-confidence decision.

Functions

This section is empty.

Types

type ApprovalOption added in v1.0.0

type ApprovalOption struct {
	ID    string
	Label string
}

ApprovalOption is a single choice presented to the reviewer.

type ApprovalRequest added in v1.0.0

type ApprovalRequest struct {
	Title       string
	Description string
	Data        any
	Options     []ApprovalOption
	Timeout     time.Duration
}

ApprovalRequest describes what the human needs to review.

type ApprovalResponse added in v1.0.0

type ApprovalResponse struct {
	Action   string // "approve", "reject", "modify"
	Feedback string
	Data     any
}

ApprovalResponse carries the human reviewer's decision.

type Decision

type Decision struct {
	Action     string         `json:"action"`
	Tool       string         `json:"tool,omitempty"`
	Parameters map[string]any `json:"parameters,omitempty"`
	Reasoning  string         `json:"reasoning"`
	Confidence float64        `json:"confidence"`
}

决定是审议后的最后决定。

type DeliberationConfig

type DeliberationConfig struct {
	Mode               DeliberationMode `json:"mode"`
	MaxThinkingTime    time.Duration    `json:"max_thinking_time"`
	MinConfidence      float64          `json:"min_confidence"`
	EnableSelfCritique bool             `json:"enable_self_critique"`
	MaxIterations      int              `json:"max_iterations"`
}

Deconfig 配置审议引擎 。

func DefaultDeliberationConfig

func DefaultDeliberationConfig() DeliberationConfig

默认De ReleaseConfig 返回默认配置 。

type DeliberationMode

type DeliberationMode string

审议 模式控制代理在行动前的理性.

const (
	ModeImmediate  DeliberationMode = "immediate"  // Direct tool execution
	ModeDeliberate DeliberationMode = "deliberate" // Full reasoning cycle
	ModeAdaptive   DeliberationMode = "adaptive"   // Context-dependent
)

type DeliberationResult

type DeliberationResult struct {
	TaskID          string           `json:"task_id"`
	Thoughts        []ThoughtProcess `json:"thoughts"`
	Decision        *Decision        `json:"decision"`
	TotalTime       time.Duration    `json:"total_time"`
	Iterations      int              `json:"iterations"`
	FinalConfidence float64          `json:"final_confidence"`
}

审议结果载有审议结果。

type Engine

type Engine struct {
	OnThought  func(ThoughtProcess)
	OnDecision func(Decision)
	// contains filtered or unexported fields
}

Engine provides deliberation capabilities.

func NewEngine

func NewEngine(config DeliberationConfig, reasoner Reasoner, logger *zap.Logger) *Engine

NewEngine创造了一个新的审议引擎.

func (*Engine) Deliberate

func (e *Engine) Deliberate(ctx context.Context, task Task) (*DeliberationResult, error)

Deliberate performs reasoning before action.

func (*Engine) GetMode

func (e *Engine) GetMode() DeliberationMode

GetMode returns the current deliberation mode.

func (*Engine) SetMode

func (e *Engine) SetMode(mode DeliberationMode)

设置模式在运行时更改审议模式 。

type HITLBridge added in v1.0.0

type HITLBridge struct {
	// contains filtered or unexported fields
}

HITLBridge connects deliberation to human approval.

func NewHITLBridge added in v1.0.0

func NewHITLBridge(engine *Engine, requester InterruptRequester, config HITLConfig, logger *zap.Logger) *HITLBridge

NewHITLBridge creates a bridge between the deliberation engine and human review.

func (*HITLBridge) DeliberateWithApproval added in v1.0.0

func (b *HITLBridge) DeliberateWithApproval(ctx context.Context, task Task) (*DeliberationResult, error)

DeliberateWithApproval runs deliberation and escalates to a human reviewer when the final confidence falls below the configured threshold.

type HITLConfig added in v1.0.0

type HITLConfig struct {
	Enabled             bool
	ConfidenceThreshold float64       // below this, escalate to human
	InterruptTimeout    time.Duration // how long to wait for human response
}

HITLConfig configures human-in-the-loop escalation.

func DefaultHITLConfig added in v1.0.0

func DefaultHITLConfig() HITLConfig

DefaultHITLConfig returns sensible defaults for HITL escalation.

type HITLInterruptAdapter added in v1.0.0

type HITLInterruptAdapter struct {
	// contains filtered or unexported fields
}

HITLInterruptAdapter adapts hitl.InterruptManager to the InterruptRequester interface. This is the only file in the deliberation package that imports agent/hitl, keeping the rest of the package loosely coupled.

func NewHITLInterruptAdapter added in v1.0.0

func NewHITLInterruptAdapter(manager *hitl.InterruptManager) *HITLInterruptAdapter

NewHITLInterruptAdapter wraps an InterruptManager for use with HITLBridge.

func (*HITLInterruptAdapter) RequestApproval added in v1.0.0

func (a *HITLInterruptAdapter) RequestApproval(ctx context.Context, opts ApprovalRequest) (*ApprovalResponse, error)

RequestApproval translates an ApprovalRequest into a hitl.InterruptOptions call and maps the hitl.Response back to an ApprovalResponse.

type InterruptRequester added in v1.0.0

type InterruptRequester interface {
	RequestApproval(ctx context.Context, opts ApprovalRequest) (*ApprovalResponse, error)
}

InterruptRequester is a local interface for HITL integration. Matches the subset of hitl.InterruptManager needed here. Using a local interface (§15) to keep deliberation loosely coupled.

type LLMReasoner added in v1.0.0

type LLMReasoner struct {
	// contains filtered or unexported fields
}

LLMReasoner implements Reasoner using an llm.Provider.

func NewLLMReasoner added in v1.0.0

func NewLLMReasoner(provider llm.Provider, model string, logger *zap.Logger) *LLMReasoner

NewLLMReasoner creates a new LLM-backed Reasoner.

func (*LLMReasoner) Think added in v1.0.0

func (r *LLMReasoner) Think(ctx context.Context, prompt string) (string, float64, error)

Think sends a reasoning prompt to the LLM and returns the response content along with a confidence score extracted from the response.

type Reasoner

type Reasoner interface {
	Think(ctx context.Context, prompt string) (string, float64, error)
}

基于LLM的推理的理性界面.

type Task

type Task struct {
	ID             string         `json:"id"`
	Description    string         `json:"description"`
	Goal           string         `json:"goal"`
	Context        map[string]any `json:"context,omitempty"`
	AvailableTools []string       `json:"available_tools,omitempty"`
	SuggestedTool  string         `json:"suggested_tool,omitempty"`
	Parameters     map[string]any `json:"parameters,omitempty"`
}

任务是一项需要审议的任务。

type ThoughtProcess

type ThoughtProcess struct {
	ID         string    `json:"id"`
	Step       int       `json:"step"`
	Type       string    `json:"type"` // understand, evaluate, plan, critique
	Content    string    `json:"content"`
	Confidence float64   `json:"confidence"`
	Timestamp  time.Time `json:"timestamp"`
}

ThoughtProcess代表了单一的推理步骤.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL