derive

package
v0.3.29 Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TodoPending    = "pending"
	TodoInProgress = "in_progress"
	TodoDone       = "done"
)

Todo statuses. Anything other than TodoDone counts as outstanding work.

View Source
const (
	FinishCompleted = "completed"
	FinishBlocked   = "blocked"
)

Run finish statuses.

View Source
const AuditSpillPath = "spill_path"

AuditSpillPath records the workspace-relative spill file for a truncated tool result.

View Source
const DefaultMaxStoredTextBytes = 8192

DefaultMaxStoredTextBytes caps embedded tool-result text and spill preview views (pi-style truncation applies at tool execution / PrepareToolResultForStorage, not chat message bodies).

View Source
const InterruptedToolResultText = "tool execution was interrupted before it produced a result (process exited); re-run it if the result is still needed"

InterruptedToolResultText is the tool result synthesized for a call the process never got to answer. It is model-visible on purpose: the agent needs to know the call was cut off rather than silently succeeded.

View Source
const MetadataLogicalChars = "logical_chars"

MetadataLogicalChars stores pre-sanitize size when storage shrinks the message (e.g. stripped inline media).

Variables

This section is empty.

Functions

func AppendSkillLoad

func AppendSkillLoad(ctx context.Context, s agentkit.Session, agentID agentkit.AgentID, content skill.Content) error

func DeriveMessages

func DeriveMessages(ctx context.Context, events []agentkit.SessionEvent, maxToolBytes int) []agentkit.ModelMessage

func EstimateLogicalChars

func EstimateLogicalChars(msg agentkit.ModelMessage) int

EstimateLogicalChars approximates model-visible size before session storage.

func EstimateMessagesChars

func EstimateMessagesChars(messages []agentkit.ModelMessage) int

EstimateMessagesChars sums logical character counts for a message list (e.g. pre-step history including hydrated vision).

func FlattenTextParts

func FlattenTextParts(parts []agentkit.ContentPart, sep string) string

FlattenTextParts joins non-empty text parts with sep (empty type is treated as text).

func FormatSessionRecall

func FormatSessionRecall(hits []capsessionindex.Hit) string

FormatSessionRecall renders FTS hits for the review digest.

func HydrateLocalAttachments

func HydrateLocalAttachments(ctx context.Context, msgs []agentkit.ModelMessage, ws workspace.Service, maxImageBytes int) ([]agentkit.ModelMessage, error)

HydrateLocalAttachments reloads workspace images for LLM vision (text + image modalities).

func InterruptedToolResult

func InterruptedToolResult(call agentkit.ToolCall) agentkit.ToolResult

InterruptedToolResult is the stand-in result for a call that never ran to completion.

func LatestEventSeq

func LatestEventSeq(events []agentkit.SessionEvent) agentkit.EventSeq

func LatestSeq

func LatestSeq(ctx context.Context, s agentkit.Session) (agentkit.EventSeq, error)

LatestSeq returns the highest durable event sequence for the session.

func PrepareMessagesForLLM

func PrepareMessagesForLLM(ctx context.Context, msgs []agentkit.ModelMessage, ws workspace.Service, maxImageBytes int, modalities []string) ([]agentkit.ModelMessage, error)

PrepareMessagesForLLM applies modality policy and optional vision hydration before an LLM call.

func PrepareToolResultForStorage

func PrepareToolResultForStorage(ctx context.Context, sessionID agentkit.SessionID, result agentkit.ToolResult, maxViewBytes int) (agentkit.ToolResult, error)

PrepareToolResultForStorage keeps the model-visible body bounded while persisting the full output to workspace (pi-style spill). When workspace is unavailable, falls back to in-event truncation only.

func PruneToolResults

func PruneToolResults(messages []agentkit.ModelMessage, maxBytes int) []agentkit.ModelMessage

PruneToolResults truncates oversized tool result text deterministically.

func ReadAllEvents

func ReadAllEvents(ctx context.Context, s agentkit.Session) ([]agentkit.SessionEvent, error)

func SanitizeModelMessageForStorage

func SanitizeModelMessageForStorage(msg agentkit.ModelMessage, maxTextBytes int) agentkit.ModelMessage

SanitizeModelMessageForStorage strips bulky inline media before durable session history. User and assistant message text is persisted in full (aligned with pi session JSONL). When maxTextBytes > 0, only tests or explicit callers may cap message body text.

func SanitizeModelMessageForStorageWS

func SanitizeModelMessageForStorageWS(msg agentkit.ModelMessage, maxTextBytes int, ws workspace.Service) agentkit.ModelMessage

SanitizeModelMessageForStorageWS is like SanitizeModelMessageForStorage but normalizes attachment Source paths relative to work dir (no local:/global:/work/ prefixes) when ws implements layout.

func SanitizeToolCall

func SanitizeToolCall(call agentkit.ToolCall) agentkit.ToolCall

SanitizeToolCall prepares a tool call for durable session storage.

func SpillPathAbs

func SpillPathAbs(ctx context.Context, ws cw.Service, rel string) (string, error)

SpillPathAbs resolves a stored spill_path audit entry to an absolute path.

func SumLogicalCharsFromEvents

func SumLogicalCharsFromEvents(events []agentkit.SessionEvent, agentID agentkit.AgentID) int

SumLogicalCharsFromEvents totals logical message size for compaction estimates.

func ToolResultMessage

func ToolResultMessage(result agentkit.ToolResult) agentkit.ModelMessage

ToolResultMessage wraps a tool result as a tool-role model message.

func TruncateToolResult

func TruncateToolResult(result agentkit.ToolResult, maxBytes int) agentkit.ToolResult

TruncateToolResult truncates oversized tool result content after execution.

Types

type IndexedMessage

type IndexedMessage = compaction.IndexedMessage

IndexedMessage is a model-visible message with its primary source event seq.

func IndexMessagesForCompaction

func IndexMessagesForCompaction(ctx context.Context, events []agentkit.SessionEvent) []IndexedMessage

IndexMessagesForCompaction rebuilds the model-visible list used for compaction, including the latest compaction summary and retained tail when present.

type RunFinishData

type RunFinishData struct {
	Status  string `json:"status"`
	Summary string `json:"summary,omitempty"`
}

RunFinishData is the payload of an EventRunFinish event.

type RunState

type RunState struct {
	StartSeq agentkit.EventSeq
	Todos    []Todo
	Pending  []Todo
	Finish   *RunFinishData
	Repeats  int
	Usage    UsageData
	Context  int
}

RunState is a snapshot of autonomous-run signals from the session log.

type Todo

type Todo struct {
	ID     string `json:"id"`
	Title  string `json:"title"`
	Status string `json:"status"`
}

Todo is one entry of the durable task list written by tool/todo.

func (Todo) Done

func (t Todo) Done() bool

Done reports whether this entry no longer needs work.

type TodoUpdateData

type TodoUpdateData struct {
	Items []Todo `json:"items"`
}

TodoUpdateData is the payload of an EventTodoUpdate event.

type TurnContinueData

type TurnContinueData struct {
	Segment  int                     `json:"segment"`
	Reason   string                  `json:"reason"`
	Steps    int                     `json:"steps"`
	Messages []agentkit.ModelMessage `json:"messages,omitempty"`
}

TurnContinueData records one autonomous turn extension.

type UsageData

type UsageData struct {
	InputTokens  int `json:"inputTokens"`
	OutputTokens int `json:"outputTokens"`
	TotalTokens  int `json:"totalTokens"`
}

UsageData records token accounting for one model step.

Jump to

Keyboard shortcuts

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