Documentation
¶
Overview ¶
Package sidequestion captures immutable main-agent checkpoints. It never owns an agent session or a tool executor.
Index ¶
- Constants
- Variables
- func Attach(ctx context.Context, parent Parent, deps harness.QueryDeps, ...) (context.Context, harness.QueryDeps)
- func Bind(inner llm.Provider, model Model) llm.Provider
- func BuildRequest(s Snapshot, history []Exchange, question string) (llm.CompletionRequest, error)
- func CloneRequest(req llm.CompletionRequest) (llm.CompletionRequest, error)
- func EstimateInputTokens(req llm.CompletionRequest) int
- func Finish(ctx context.Context, messages []llm.Message)
- func WithHistory(ctx context.Context, revision int64, runID string) context.Context
- func WithPublisher(ctx context.Context, publish Publisher) context.Context
- func WithRequestObserver(ctx context.Context, observer RequestObserver) context.Context
- func WithWorkingSetProjector(ctx context.Context, ...) context.Context
- type Answer
- type Capture
- type ContextInfo
- type ContextOptions
- type Exchange
- type Memory
- type Model
- type Parent
- type Publisher
- type Replay
- type RequestEvent
- type RequestObserver
- type SideQuestionService
- type Snapshot
Constants ¶
const DefaultOutputTokens = 8192
const MaxRecentExchanges = 20
Variables ¶
var ErrContextBudget = locale.NewError("Side-question context still exceeds the model budget after compaction; narrow the question or adjust the model context configuration")
Functions ¶
func Attach ¶
func Attach(ctx context.Context, parent Parent, deps harness.QueryDeps, provider llm.Provider) (context.Context, harness.QueryDeps)
Attach uses QueryDeps rather than a global provider hook so compaction and other auxiliary completions cannot replace the main conversation checkpoint.
func BuildRequest ¶
func CloneRequest ¶
func CloneRequest(req llm.CompletionRequest) (llm.CompletionRequest, error)
func EstimateInputTokens ¶
func EstimateInputTokens(req llm.CompletionRequest) int
EstimateInputTokens follows norma's byte-based block estimate with its 4/3 safety factor. Include system/schema and framing costs too; JSON characters are not tokens (and marshaling HTML can add many non-semantic escapes).
func Finish ¶
Finish adds tool results that landed after the final model request. Norma's first API message is its host reminder, absent from Terminal.Messages.
func WithHistory ¶
func WithRequestObserver ¶
func WithRequestObserver(ctx context.Context, observer RequestObserver) context.Context
Types ¶
type ContextInfo ¶
type ContextInfo struct {
Phase string `json:"phase,omitempty"`
RecentExchanges int `json:"recent_exchanges"`
HistorySummarized bool `json:"history_summarized"`
SnapshotSummarized bool `json:"snapshot_summarized"`
EstimatedInputTokens int `json:"estimated_input_tokens,omitempty"`
InputBudget int `json:"input_budget,omitempty"`
OutputTokens int `json:"output_tokens,omitempty"`
OverflowRetried bool `json:"overflow_retried,omitempty"`
}
type ContextOptions ¶
type ContextOptions struct{ OutputTokens int }
type Exchange ¶
type Exchange struct {
HistoryRevision int64 `json:"history_revision"`
SourceRunID string `json:"source_run_id,omitempty"`
ID string `json:"id"`
SessionKey string `json:"-"`
ClientID string `json:"client_request_id"`
Generation int64 `json:"-"`
Question string `json:"question"`
Answer string `json:"answer"`
Status string `json:"status"`
Error string `json:"error,omitempty"`
Model Model `json:"model"`
SnapshotAt time.Time `json:"snapshot_at"`
CreatedAt time.Time `json:"created_at"`
Sequence int64 `json:"sequence"`
Usage llm.Usage `json:"usage"`
Ordinal int64 `json:"ordinal"`
Context ContextInfo `json:"context"`
}
type Memory ¶
type Memory struct {
History string `json:"history,omitempty"`
Through int64 `json:"through,omitempty"`
SnapshotKey string `json:"snapshot_key,omitempty"`
SnapshotSummary string `json:"snapshot_summary,omitempty"`
TailStart int `json:"tail_start,omitempty"`
}
Memory is independent of the main snapshot. Through is a persisted ordinal, not an array offset; restart, pagination and failed requests cannot shift it.
type Model ¶
type Model struct {
ProfileID int64 `json:"profile_id"`
Name string `json:"name"`
Format string `json:"format"`
Model string `json:"model"`
Identity string `json:"identity"`
Streaming bool `json:"streaming"`
WindowTokens int `json:"window_tokens"`
}
Model contains only configuration identity, never credentials or proxy URLs.
type Parent ¶
type Replay ¶
type Replay struct {
Memory Memory
Load func(context.Context, int64) ([]Exchange, error)
Save func(context.Context, Memory) error
}
Load returns ascending completed exchanges after the cursor, in bounded pages, restricted to ordinals before this request. Save must reject writes after a clear/delete/cancel using the admitted request's generation.
type RequestEvent ¶
type RequestEvent struct {
Request llm.CompletionRequest
AnchorRequest llm.CompletionRequest
Model Model
Usage llm.Usage
Source string
}
RequestEvent observes only main requests selected by QueryDeps. Usage belongs to AnchorRequest; Request may additionally include newly generated messages.
type RequestObserver ¶
type RequestObserver func(context.Context, RequestEvent)
type SideQuestionService ¶
SideQuestionService has no harness, tool executor, transcript writer or model failover chain. Answer is one completion; Respond adds bounded preparation and at most one context-overflow recovery around that completion.
func (SideQuestionService) Answer ¶
func (s SideQuestionService) Answer(ctx context.Context, req llm.CompletionRequest, streaming bool, update func(Answer)) (out Answer, err error)
func (SideQuestionService) Respond ¶
func (s SideQuestionService) Respond(ctx context.Context, snapshot Snapshot, question string, replay Replay, options ContextOptions, update func(Answer, ContextInfo)) (out Answer, info ContextInfo, err error)
Respond owns preparation and at most one overflow recovery. No tools, main transcript or model-failover chain are introduced by the summary calls.
type Snapshot ¶
type Snapshot struct {
HistoryRevision int64 `json:"history_revision,string"`
SourceRunID string `json:"source_run_id,omitempty"`
Parent Parent `json:"parent"`
RunID int64 `json:"run_id"`
Version int64 `json:"version"`
CapturedAt time.Time `json:"captured_at"`
Model Model `json:"model"`
Request llm.CompletionRequest `json:"request"`
}