hitlservice

package
v1.0.0-rc.2 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2026 License: Apache-2.0 Imports: 18 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	AttentionToolsName = "mission"
	AttentionToolName  = "mission_ask_attention"
)
View Source
const (
	ReasonMatchedRule   = "matched_rule"
	ReasonDefaultAction = "default_action"
)
View Source
const DefaultApprovalCeiling = time.Hour
View Source
const DefaultMaxAgentAnswers = 3
View Source
const DefaultMaxAgentApprovals = 10

Variables

View Source
var (
	ErrApprovalNotFound        = errors.New("hitlservice: approval not found")
	ErrApprovalAlreadyResolved = errors.New("hitlservice: approval already answered")
	ErrApprovalExpired         = errors.New("hitlservice: approval expired before it was answered")
)
View Source
var ErrAgentAnswerBoundSpent = errors.New("hitlservice: mission agent-answer bound spent")
View Source
var ErrAgentApprovalBoundSpent = errors.New("hitlservice: mission agent-approval bound spent")
View Source
var ErrAttentionUnanswered = errors.New("hitlservice: attention ask went unanswered")

Functions

func AnswerOf

func AnswerOf(row *runtimetypes.HITLApproval) string

func IsAttentionAsk

func IsAttentionAsk(row *runtimetypes.HITLApproval) bool

func PolicyNameFromContext

func PolicyNameFromContext(ctx context.Context) string

func SetAdjudicator

func SetAdjudicator(svc Service, adjudicator Adjudicator)

func SetApprovalCeiling

func SetApprovalCeiling(svc Service, ceiling time.Duration)

func WithPolicyName added in v0.36.0

func WithPolicyName(ctx context.Context, policyName string) context.Context

Types

type Action

type Action string
const (
	ActionAllow   Action = "allow"
	ActionApprove Action = "approve"
	ActionDeny    Action = "deny"
)

type Adjudication

type Adjudication struct {
	AskID       string
	Kind        AskKind
	MissionID   string
	SessionID   string
	InstanceID  string
	AgentName   string
	Summary     string
	Detail      string
	ToolsName   string
	ToolName    string
	ArgsSummary string
	Diff        string
	PolicyName  string
	MatchedRule string
	OnTimeout   string
}

type Adjudicator

type Adjudicator interface {
	Adjudicate(ctx context.Context, ask Adjudication)
}

type ApprovalRequest

type ApprovalRequest struct {
	ToolCallID string
	ToolsName  string
	ToolName   string
	Args       map[string]any
	Diff       string
	DiffOld    string
	DiffNew    string

	PolicyName  string
	MatchedRule *int
	TimeoutS    int
	OnTimeout   Action

	InstanceID string
	SessionID  string
	AgentName  string
	MissionID  string
}

type AskKind

type AskKind string
const (
	AskKindPermission AskKind = "permission"
	AskKindAttention  AskKind = "attention"
)

type AttentionBounds

type AttentionBounds struct {
	AllowAgentAnswers   bool `json:"allowAgentAnswers,omitempty"`
	MaxAgentAnswers     int  `json:"maxAgentAnswers,omitempty"`
	AllowAgentApprovals bool `json:"allowAgentApprovals,omitempty"`
	MaxAgentApprovals   int  `json:"maxAgentApprovals,omitempty"`
}

func (AttentionBounds) EffectiveMaxAgentAnswers

func (b AttentionBounds) EffectiveMaxAgentAnswers() int

func (AttentionBounds) EffectiveMaxAgentApprovals

func (b AttentionBounds) EffectiveMaxAgentApprovals() int

type AttentionRequest

type AttentionRequest struct {
	Summary    string
	Detail     string
	MissionID  string
	InstanceID string
	SessionID  string
	AgentName  string

	OnRaised func(askID string)
}

type ComputeBounds

type ComputeBounds struct {
	MaxTurns         int         `json:"maxTurns,omitempty"`
	MaxToolCalls     int         `json:"maxToolCalls,omitempty"`
	MaxTokens        int         `json:"maxTokens,omitempty"`
	ModelAllowlist   []string    `json:"modelAllowlist,omitempty"`
	BackendAllowlist []string    `json:"backendAllowlist,omitempty"`
	OnExhausted      OnExhausted `json:"onExhausted,omitempty"`
}

type ComputeBoundsReader

type ComputeBoundsReader interface {
	ComputeBoundsFor(ctx context.Context, policyName string) (ComputeBounds, error)
}

type Condition

type Condition struct {
	Key   string      `json:"key"`
	Op    ConditionOp `json:"op"`
	Value string      `json:"value"`
}

type ConditionOp

type ConditionOp string
const (
	OpEq                    ConditionOp = "eq"
	OpGlob                  ConditionOp = "glob"
	OpHost                  ConditionOp = "host"
	OpCommandBlacklist      ConditionOp = "command_blacklist"
	OpCommandAskAlways      ConditionOp = "command_ask_always"
	OpNoCommandSubstitution ConditionOp = "no_command_substitution"
)

type EvaluationResult

type EvaluationResult struct {
	Action      Action
	MatchedRule *int
	Reason      string
	TimeoutS    int
	OnTimeout   Action
	PolicyName  string
}

type KVReader

type KVReader interface {
	GetKV(ctx context.Context, key string, out interface{}) error
}

type OnExhausted

type OnExhausted string
const (
	OnExhaustedFinishStuck OnExhausted = "finish_stuck"
	OnExhaustedPauseAsk    OnExhausted = "pause_ask"
)

type Policy

type Policy struct {
	DefaultAction Action           `json:"default_action,omitempty"`
	Rules         []Rule           `json:"rules"`
	Compute       *ComputeBounds   `json:"compute,omitempty"`
	Attention     *AttentionBounds `json:"attention,omitempty"`
}

type PolicyEvaluator

type PolicyEvaluator interface {
	Evaluate(ctx context.Context, toolsName, toolName string, args map[string]any) (EvaluationResult, error)
}

type PolicySource

type PolicySource interface {
	ReadPolicy(ctx context.Context, tenantID, name string) ([]byte, error)
}

func NewFSPolicySource

func NewFSPolicySource(dirs ...string) PolicySource

type PolicyValidator

type PolicyValidator interface {
	ValidatePolicy(ctx context.Context, policyName string) error
}

func NewPolicyValidator

func NewPolicyValidator(src PolicySource, tenantID, fallbackPolicy string) PolicyValidator

type Rule

type Rule struct {
	Tools     string      `json:"tools"`
	Tool      string      `json:"tool"`
	When      []Condition `json:"when,omitempty"`
	Action    Action      `json:"action"`
	TimeoutS  int         `json:"timeout_s,omitempty"`
	OnTimeout Action      `json:"on_timeout,omitempty"`
}

type Service

type Service interface {
	PolicyEvaluator

	RequestApproval(ctx context.Context, req ApprovalRequest, sink taskengine.TaskEventSink) (bool, error)

	Respond(ctx context.Context, approvalID string, approved bool) error

	RequestAttention(ctx context.Context, req AttentionRequest, sink taskengine.TaskEventSink) (string, error)

	Answer(ctx context.Context, askID, text string) error

	AnswerAsAgent(ctx context.Context, askID, text string) error

	PendingAttentionAsks(ctx context.Context, missionID string) ([]*runtimetypes.HITLApproval, error)

	AttentionBoundsFor(ctx context.Context, policyName string) (AttentionBounds, error)

	AgentAnswerCount(ctx context.Context, missionID string) (int, error)

	SweepExpired(ctx context.Context) (int, error)

	ListPending(ctx context.Context, limit int) ([]*runtimetypes.HITLApproval, error)
}

func New

func New(src PolicySource, tenantID string, store KVReader, tracker libtracker.ActivityTracker) Service

func NewWithDefaultPolicy

func NewWithDefaultPolicy(src PolicySource, tenantID string, store KVReader, tracker libtracker.ActivityTracker, fallbackPolicy string) Service

Jump to

Keyboard shortcuts

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