Documentation
¶
Overview ¶
Package agent implements the transport-neutral, read-only conversational RAG domain.
Index ¶
- Constants
- Variables
- func WithRequestTimeout(parent context.Context, limits Limits, transport Transport) (context.Context, context.CancelFunc)
- type Answer
- type AuditEvent
- type AuditFailure
- type AuditPhase
- type AuditSink
- type AuditTelemetry
- type Auditor
- type CompletionClaim
- type CompletionProvider
- type CompletionRequest
- type CompletionResult
- type CompletionUsage
- type Confidence
- type Error
- type ErrorCode
- type Evidence
- type EvidenceKind
- type LimitPolicy
- type LimitTier
- type Limits
- type Message
- type QuotaError
- type Request
- type RetrievalResult
- type RetrievalStage
- type RetrievalStageStatus
- type RetrievalStatus
- type RetrievalTier
- type RetrievalTrace
- type Retriever
- type Scope
- type ScopedRetriever
- type Service
- type Source
- type StreamCallbacks
- type StreamingCompletionProvider
- type Transport
Constants ¶
const ( AuditErrorInvalidMetadata = "audit_invalid_metadata" AuditErrorSinkDelivery = "audit_sink_delivery" )
const ( MaxQuestionBytes = 8 * 1024 MaxHistoryMessages = 12 MaxHistoryMessageBytes = 4 * 1024 MaxHistoryBytes = 24 * 1024 MaxEvidencePerCorpus = 8 MaxContextBytes = 32 * 1024 )
const ( RoleUser = "user" RoleAssistant = "assistant" )
const ( ConfidenceLow = "low" ConfidenceMedium = "medium" ConfidenceHigh = "high" DegradedNoEvidence = "no_authorized_evidence" )
const HardMaxOutputTokens = 4096
Variables ¶
var ErrUnknownLimitTier = errors.New("unknown agent limit tier")
Functions ¶
func WithRequestTimeout ¶
func WithRequestTimeout(parent context.Context, limits Limits, transport Transport) (context.Context, context.CancelFunc)
WithRequestTimeout derives the server-owned transport deadline while preserving an earlier upstream deadline and cancellation.
Types ¶
type Answer ¶
type Answer struct {
Answer string `json:"answer"`
Sources []Source `json:"sources"`
Confidence Confidence `json:"confidence"`
Retrieval RetrievalStatus `json:"retrieval"`
Usage CompletionUsage `json:"-"`
}
type AuditEvent ¶
type AuditEvent struct {
Phase AuditPhase `json:"phase"`
CorrelationID string `json:"correlation_id"`
ActorID string `json:"actor_id"`
TenantID string `json:"tenant_id"`
WorkspaceID string `json:"workspace_id"`
Project string `json:"project"`
Transport Transport `json:"transport"`
ResultClass string `json:"result_class"`
Duration time.Duration `json:"duration_ns"`
InputTokens int `json:"input_tokens"`
OutputTokens int `json:"output_tokens"`
SourceCount int `json:"source_count"`
Confidence string `json:"confidence,omitempty"`
Degraded []string `json:"degraded,omitempty"`
}
AuditEvent is deliberately a closed, metadata-only schema. Conversational content, evidence, credentials, embeddings and provider destinations have no representable field here.
type AuditFailure ¶
type AuditFailure struct {
CorrelationID string `json:"correlation_id"`
Project string `json:"project"`
ResultClass string `json:"result_class"`
SourceCount int `json:"source_count"`
Duration time.Duration `json:"duration_ns"`
ErrorClass string `json:"error_class"`
}
AuditFailure is the only outcome-delivery failure exposed to telemetry. It intentionally excludes the sink error and all request content.
type AuditPhase ¶
type AuditPhase string
const ( AuditPhaseAuthorization AuditPhase = "authorization" AuditPhaseOutcome AuditPhase = "outcome" )
type AuditTelemetry ¶
type AuditTelemetry interface {
AuditDeliveryFailed(AuditFailure)
}
type Auditor ¶
type Auditor struct {
Sink AuditSink
Telemetry AuditTelemetry
}
func (Auditor) RecordAuthorization ¶
func (a Auditor) RecordAuthorization(ctx context.Context, event AuditEvent) error
RecordAuthorization is the mandatory pre-provider audit. It fails closed.
func (Auditor) RecordOutcome ¶
func (a Auditor) RecordOutcome(ctx context.Context, event AuditEvent)
RecordOutcome is best effort because a completed answer cannot be recalled. Delivery failure is reported using content-free telemetry only.
type CompletionClaim ¶
type CompletionClaim struct {
Text string `json:"text"`
CitationHandles []string `json:"citation_handles"`
}
CompletionClaim is the provider's smallest factual output unit. A claim is eligible for the public answer only when at least one handle was issued for this request and resolves to authorized evidence.
type CompletionProvider ¶
type CompletionProvider interface {
Complete(context.Context, CompletionRequest) (CompletionResult, error)
}
CompletionProvider intentionally exposes no tools, URL, model or credentials.
type CompletionRequest ¶
type CompletionResult ¶
type CompletionResult struct {
Claims []CompletionClaim
InputTokens int
OutputTokens int
}
func (CompletionResult) Usage ¶
func (r CompletionResult) Usage() CompletionUsage
type CompletionUsage ¶
type Confidence ¶
type Evidence ¶
type Evidence struct {
Kind EvidenceKind `json:"type"`
Title string `json:"title"`
Path string `json:"path,omitempty"`
LineStart int `json:"line_start,omitempty"`
LineEnd int `json:"line_end,omitempty"`
Content string `json:"-"`
Score float64 `json:"-"`
}
Evidence is trusted scope-wise by its adapter. Content is prompt-only and never returned.
type EvidenceKind ¶
type EvidenceKind string
const ( EvidenceMemory EvidenceKind = "memory" EvidenceCode EvidenceKind = "code" )
type LimitPolicy ¶
func DefaultLimitPolicy ¶
func DefaultLimitPolicy() LimitPolicy
type Limits ¶
type Limits struct {
RequestsPerMinute int
TokensPerMinute int
MaxTenantConcurrent int
DefaultOutputTokens int
MaxOutputTokens int
JSONTimeout time.Duration
StreamTimeout time.Duration
}
Limits are trusted server-side budgets. None of these values may be supplied by an agent request.
type QuotaError ¶
QuotaError carries bounded retry metadata without exposing limiter keys or internal capacity state.
func (*QuotaError) Error ¶
func (e *QuotaError) Error() string
type RetrievalResult ¶
type RetrievalResult struct {
Evidence []Evidence
Trace RetrievalTrace
}
RetrievalResult keeps evidence and its safe execution trace together.
type RetrievalStage ¶
RetrievalStage reports only safe pipeline state; it never carries query, content, internal identifiers, or authorization details.
type RetrievalStageStatus ¶
type RetrievalStageStatus struct {
Name string `json:"name"`
Status string `json:"status"`
Count int `json:"count"`
}
RetrievalStageStatus is the public, content-free projection of one retrieval stage. Generation remains empty until a trusted corpus generation is carried by the retrieval port; transports must never synthesize one from request data or expose internal checksums.
type RetrievalStatus ¶
type RetrievalStatus struct {
Tier string `json:"tier,omitempty"`
Stages []RetrievalStageStatus `json:"stages,omitempty"`
RefinementCount int `json:"refinement_count,omitempty"`
Generation string `json:"generation,omitempty"`
Degraded []string `json:"degraded"`
InvalidCitations int `json:"invalid_citations,omitempty"`
}
type RetrievalTier ¶
type RetrievalTier string
RetrievalTier is the bounded route selected for one scoped read.
const ( RetrievalTierDirectFactual RetrievalTier = "direct_factual" RetrievalTierSemanticHybrid RetrievalTier = "semantic_hybrid" RetrievalTierMultiHopGraph RetrievalTier = "multi_hop_graph" RetrievalTierArchitecturalGlobal RetrievalTier = "architectural_global" )
type RetrievalTrace ¶
type RetrievalTrace struct {
Tier RetrievalTier
Stages []RetrievalStage
Degraded []string
}
RetrievalTrace is transport-neutral metadata from the scoped retriever.
type ScopedRetriever ¶
type ScopedRetriever interface {
RetrieveScoped(context.Context, Scope, string, int) (RetrievalResult, error)
}
ScopedRetriever is the single read-only retrieval port used by the agent. Server composition resolves tenant, workspace, and project authority before the implementation touches lexical, dense, or graph dependencies.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
func NewScopedService ¶
func NewScopedService(retriever ScopedRetriever, completion CompletionProvider) *Service
NewScopedService composes the agent with one deep, scope-preserving retrieval module. NewService remains for local compatibility while server mode uses this constructor exclusively.
func NewService ¶
func NewService(memory, code Retriever, completion CompletionProvider) *Service
func (*Service) Stream ¶
func (s *Service) Stream(ctx context.Context, req Request, callbacks StreamCallbacks) (Answer, error)
Stream shares retrieval, prompt construction, claim validation, citation resolution and final answer semantics with Answer while allowing validated claims to reach the caller progressively.
type StreamCallbacks ¶
type StreamCallbacks struct {
Meta func(RetrievalStatus) error
Delta func(string) error
Sources func([]Source) error
}
StreamCallbacks is transport-neutral. Meta precedes every delta, Sources is emitted once after all claims have been validated, and the returned Answer is the canonical terminal representation shared with the JSON transport.
type StreamingCompletionProvider ¶
type StreamingCompletionProvider interface {
Stream(context.Context, CompletionRequest, func(CompletionClaim) error) (CompletionUsage, error)
}
StreamingCompletionProvider emits complete, provider-produced claims as soon as they can be parsed. Claims are still untrusted until Service resolves their handles against the evidence issued for the current request.