Documentation
¶
Index ¶
- Constants
- func AppendAutoRetryEnd(ctx context.Context, s agentkit.Session, agentID agentkit.AgentID, ...) error
- func AppendAutoRetryStart(ctx context.Context, s agentkit.Session, agentID agentkit.AgentID, ...) error
- func AppendCompaction(ctx context.Context, s agentkit.Session, agentID agentkit.AgentID, ...) error
- func AppendMessage(ctx context.Context, s agentkit.Session, agentID agentkit.AgentID, ...) error
- func AppendOverflowRecovery(ctx context.Context, s agentkit.Session, agentID agentkit.AgentID, ...) error
- func AppendRunFinish(ctx context.Context, s agentkit.Session, agentID agentkit.AgentID, ...) error
- func AppendSessionRecovery(ctx context.Context, s agentkit.Session, agentID agentkit.AgentID, ...) error
- func AppendSkillLoad(ctx context.Context, s agentkit.Session, agentID agentkit.AgentID, ...) error
- func AppendStepEnd(ctx context.Context, s agentkit.Session, agentID agentkit.AgentID, step int) error
- func AppendStepStart(ctx context.Context, s agentkit.Session, agentID agentkit.AgentID, step int) error
- func AppendSubagentEnd(ctx context.Context, s agentkit.Session, agentID agentkit.AgentID, ...) error
- func AppendSubagentStart(ctx context.Context, s agentkit.Session, agentID agentkit.AgentID, ...) error
- func AppendSummarizationRetryEnd(ctx context.Context, s agentkit.Session, agentID agentkit.AgentID, ...) error
- func AppendSummarizationRetryStart(ctx context.Context, s agentkit.Session, agentID agentkit.AgentID, ...) error
- func AppendTodoUpdate(ctx context.Context, s agentkit.Session, agentID agentkit.AgentID, ...) error
- func AppendToolCall(ctx context.Context, s agentkit.Session, agentID agentkit.AgentID, ...) error
- func AppendToolResult(ctx context.Context, s agentkit.Session, agentID agentkit.AgentID, ...) error
- func AppendTurnContinue(ctx context.Context, s agentkit.Session, agentID agentkit.AgentID, ...) error
- func AppendTurnEnd(ctx context.Context, s agentkit.Session, agentID agentkit.AgentID, steps int) error
- func AppendTurnStart(ctx context.Context, s agentkit.Session, agentID agentkit.AgentID) error
- func AppendUsage(ctx context.Context, s agentkit.Session, agentID agentkit.AgentID, ...) error
- func InterruptedToolResult(call agentkit.ToolCall) agentkit.ToolResult
- func LastAssistantText(events []agentkit.SessionEvent, seq agentkit.EventSeq) string
- func LatestEventSeq(events []agentkit.SessionEvent) agentkit.EventSeq
- func NewCLISessionID() agentkit.SessionID
- func NewJSONL(cfg JSONLConfig) (agentkit.Session, error)
- func NewMemory(cfg MemoryConfig) (agentkit.Session, error)
- func NewStatic(_ StaticConfig, deps StaticDeps) (agentkit.SessionStore, error)
- func NewStore(cfg StoreConfig, deps StoreDeps) (agentkit.SessionStore, error)
- func ReadAllEvents(ctx context.Context, s agentkit.Session) ([]agentkit.SessionEvent, error)
- func RepeatedToolCalls(events []agentkit.SessionEvent, seq agentkit.EventSeq) int
- func RunStartSeq(events []agentkit.SessionEvent) agentkit.EventSeq
- func SlackSessionID(channelID, threadTS string) agentkit.SessionID
- func SlackSessionIDForScope(scope SessionScope, channelID, threadTS, userID string) agentkit.SessionID
- func StepCount(events []agentkit.SessionEvent, seq agentkit.EventSeq) int
- type AutoRetryEndData
- type AutoRetryStartData
- type CLICurrentStore
- type FileBacked
- type IncompleteTurn
- type JSONL
- func (s *JSONL) Append(ctx context.Context, event agentkit.SessionEvent) (agentkit.EventSeq, error)
- func (s *JSONL) DeriveMessages(ctx context.Context) ([]agentkit.ModelMessage, error)
- func (s *JSONL) FilePath() string
- func (s *JSONL) ID() agentkit.SessionID
- func (s *JSONL) Read(ctx context.Context, from agentkit.EventSeq) ([]agentkit.SessionEvent, error)
- type JSONLConfig
- type Memory
- func (s *Memory) Append(_ context.Context, event agentkit.SessionEvent) (agentkit.EventSeq, error)
- func (s *Memory) DeriveMessages(_ context.Context) ([]agentkit.ModelMessage, error)
- func (s *Memory) ID() agentkit.SessionID
- func (s *Memory) Read(_ context.Context, from agentkit.EventSeq) ([]agentkit.SessionEvent, error)
- type MemoryConfig
- type OverflowRecoveryData
- type RecoveryData
- type RunFinishData
- type SessionScope
- type StaticConfig
- type StaticDeps
- type StaticStore
- type StepEndData
- type StepStartData
- type Store
- type StoreConfig
- type StoreDeps
- type SubagentEndData
- type SubagentStartData
- type SummarizationRetryEndData
- type SummarizationRetryStartData
- type Todo
- type TodoUpdateData
- type TurnContinueData
- type TurnEndData
- type TurnStartData
- type UsageData
Constants ¶
const ( TodoPending = "pending" TodoInProgress = "in_progress" TodoDone = "done" )
Todo statuses. Anything other than TodoDone counts as outstanding work.
const ( FinishCompleted = "completed" FinishBlocked = "blocked" )
Run finish statuses.
const CLICurrentLinkName = "cli_current.jsonl"
CLICurrentLinkName is a symlink in the session store dir pointing at the JSONL file CLI should attach to on the next start.
const DefaultCLISessionID = agentkit.SessionID("cli:default")
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.
Variables ¶
This section is empty.
Functions ¶
func AppendAutoRetryEnd ¶
func AppendAutoRetryStart ¶
func AppendCompaction ¶
func AppendMessage ¶
func AppendOverflowRecovery ¶
func AppendRunFinish ¶
func AppendSessionRecovery ¶
func AppendSkillLoad ¶
func AppendStepEnd ¶
func AppendStepStart ¶
func AppendSubagentEnd ¶
func AppendSubagentStart ¶
func AppendTodoUpdate ¶
func AppendToolCall ¶
func AppendToolResult ¶
func AppendTurnContinue ¶
func AppendTurnEnd ¶
func AppendTurnStart ¶
func AppendUsage ¶
func InterruptedToolResult ¶
func InterruptedToolResult(call agentkit.ToolCall) agentkit.ToolResult
InterruptedToolResult is the stand-in result for a call that never ran to completion.
func LastAssistantText ¶
func LastAssistantText(events []agentkit.SessionEvent, seq agentkit.EventSeq) string
LastAssistantText returns the text of the most recent assistant message after seq. It is the fallback answer for a run that stopped without calling tool/finish, which is the common case for a child agent that was only asked a question.
func LatestEventSeq ¶
func LatestEventSeq(events []agentkit.SessionEvent) agentkit.EventSeq
func NewCLISessionID ¶
NewCLISessionID returns a fresh opaque CLI session id.
func NewJSONL ¶
func NewJSONL(cfg JSONLConfig) (agentkit.Session, error)
NewJSONL registers session/jsonl: Append-only JSONL event log for one session.
Best practices:
- Reopening a file resumes event sequence numbering, so seq stays unique across restarts.
func NewMemory ¶
func NewMemory(cfg MemoryConfig) (agentkit.Session, error)
NewMemory registers session/memory: Ephemeral in-memory session. Nothing survives the process.
func NewStatic ¶
func NewStatic(_ StaticConfig, deps StaticDeps) (agentkit.SessionStore, error)
NewStatic registers session/static: Wrap one pre-built Session as a store that returns it for every id.
Best practices:
- For tests and single-session hosts; every session id maps to the same log.
func NewStore ¶
func NewStore(cfg StoreConfig, deps StoreDeps) (agentkit.SessionStore, error)
NewStore registers session/store: Resolve durable JSONL sessions by id; contributes /new and /session.
func ReadAllEvents ¶
func RepeatedToolCalls ¶
func RepeatedToolCalls(events []agentkit.SessionEvent, seq agentkit.EventSeq) int
RepeatedToolCalls returns how many times the most recent tool call signature repeats consecutively at the tail of the log, counting only calls after seq. A stuck agent calling the same tool with the same input is the cheapest stall signal available.
func RunStartSeq ¶
func RunStartSeq(events []agentkit.SessionEvent) agentkit.EventSeq
RunStartSeq returns the seq of the most recent inbound user message, which marks where the current run began. Continuations are recorded as turn/continue events rather than user/message events, so they never shift it.
func SlackSessionID ¶
SlackSessionID builds a stable session key from Slack channel and optional thread timestamp. Use threadTS from event.ThreadTimeStamp; for top-level channel messages pass "".
func SlackSessionIDForScope ¶
func SlackSessionIDForScope(scope SessionScope, channelID, threadTS, userID string) agentkit.SessionID
SlackSessionIDForScope builds the session key for a given scope. Arguments not used by the scope are ignored, so a platform can pass everything it has and let the configured scope decide.
An unknown scope falls back to ScopeThread rather than erroring: over-sharing a session is a privacy problem, and thread scope is the narrower default of the two candidates a typo could land between.
Types ¶
type AutoRetryEndData ¶
type AutoRetryStartData ¶
type CLICurrentStore ¶
type CLICurrentStore interface {
ResolveCLICurrent(ctx context.Context) (agentkit.SessionID, error)
SetCLICurrent(ctx context.Context, id agentkit.SessionID) error
}
CLICurrentStore tracks which CLI session is active across process restarts.
type FileBacked ¶
type FileBacked interface {
FilePath() string
}
FileBacked is implemented by sessions that persist to a file path.
type IncompleteTurn ¶
type IncompleteTurn struct {
TurnStartSeq agentkit.EventSeq
AgentID agentkit.AgentID
StepsStarted int
StepsEnded int
// OpenStep is the index of a step/start with no step/end, or -1 when the
// last step closed cleanly.
OpenStep int
// OrphanCalls are tool calls in the derived history that no tool result
// answers. Left alone they make the history unusable: providers reject an
// assistant message whose tool calls have no replies.
OrphanCalls []agentkit.ToolCall
}
IncompleteTurn describes a turn that never reached turn/end, which is what a crash, SIGKILL, or power loss leaves behind.
func ScanIncomplete ¶
func ScanIncomplete(events []agentkit.SessionEvent) *IncompleteTurn
ScanIncomplete reports the trailing unterminated turn, or nil when the log ends cleanly. Only the last turn can be incomplete: every earlier turn either wrote turn/end or was repaired on a previous startup.
type JSONL ¶
type JSONL struct {
// contains filtered or unexported fields
}
JSONL persists session events as append-only JSON lines.
func (*JSONL) DeriveMessages ¶
type JSONLConfig ¶
type Memory ¶
type Memory struct {
// contains filtered or unexported fields
}
Memory is an in-memory session backend for tests and ephemeral runs.
func (*Memory) DeriveMessages ¶
type MemoryConfig ¶
type OverflowRecoveryData ¶
type RecoveryData ¶
type RecoveryData struct {
TurnStartSeq agentkit.EventSeq `json:"turnStartSeq"`
Steps int `json:"steps"`
OrphanResults int `json:"orphanResults"`
ClosedStep int `json:"closedStep"`
Reason string `json:"reason"`
}
RecoveryData is the audit payload of a session/recovery event.
func RepairIncomplete ¶
func RepairIncomplete(ctx context.Context, s agentkit.Session, turn *IncompleteTurn) (RecoveryData, error)
RepairIncomplete makes an interrupted turn replayable and closes it: it answers every orphan tool call, ends the open step, writes turn/end, then records a session/recovery event for audit.
type RunFinishData ¶
type RunFinishData struct {
Status string `json:"status"`
Summary string `json:"summary,omitempty"`
}
RunFinishData is the payload of an EventRunFinish event: the agent's explicit statement that it is done, which is what stops an autonomous run.
func FinishAfter ¶
func FinishAfter(events []agentkit.SessionEvent, seq agentkit.EventSeq) *RunFinishData
FinishAfter returns the run/finish event recorded after seq, or nil when the agent has not declared completion since then. Callers pass the seq of the message that started the current run so a stale finish cannot end a new run.
type SessionScope ¶
type SessionScope string
SessionScope selects how one group's messages map to sessions. It is the platform's decision and is deliberately independent of the working directory: every scope below derives the same cap/tenant key, so a channel keeps one workdir no matter how finely its history is split.
const ( // ScopeChannel gives the whole channel a single session. Everyone in the // group shares one history and is told apart by per-message user // attribution, which is what makes "两个人在同一个群里接着聊" work. ScopeChannel SessionScope = "channel" // ScopeThread gives each thread its own session, with the channel's // top-level messages sharing one. This is the usual choice for a busy // channel where unrelated tasks run side by side. ScopeThread SessionScope = "thread" // ScopeUser gives each person their own session inside the channel: shared // working directory, private history. ScopeUser SessionScope = "user" )
type StaticConfig ¶
type StaticConfig struct{}
type StaticDeps ¶
type StaticStore ¶
type StaticStore struct {
// contains filtered or unexported fields
}
StaticStore returns one Session for matching IDs. Useful for CLI presets and tests where a single session instance is wired through pluginkit.
func NewStaticStore ¶
func NewStaticStore(sess agentkit.Session) *StaticStore
type StepEndData ¶
type StepEndData struct {
Step int `json:"step"`
}
type StepStartData ¶
type StepStartData struct {
Step int `json:"step"`
}
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store opens one JSONL session file per SessionID under Dir. Suitable for IM platforms where each channel/thread maps to a distinct session.
func (*Store) ResolveCLICurrent ¶
ResolveCLICurrent returns the session id behind cli_current.jsonl, or DefaultCLISessionID when the link is missing. A missing link is also written so the default session file is discoverable without knowing the id format.
type StoreConfig ¶
type StoreConfig struct {
// Dir is root directory holding one file per session, resolved through the workspace.
Dir string `json:"dir"`
}
type SubagentEndData ¶
type SubagentEndData struct {
Agent string `json:"agent"`
Session string `json:"session"`
Status string `json:"status"`
Summary string `json:"summary,omitempty"`
Steps int `json:"steps"`
Error string `json:"error,omitempty"`
}
SubagentEndData records the outcome of a delegation. Summary duplicates what the model sees in the tool result, on purpose: reading the parent log alone should be enough to reconstruct what came back.
type SubagentStartData ¶
type SubagentStartData struct {
Agent string `json:"agent"`
Session string `json:"session"`
Task string `json:"task"`
}
SubagentStartData records a delegation on the *parent* session. The child's own work lives in its own session; these two events are the audit trail linking the two logs together.
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 LatestTodos ¶
func LatestTodos(events []agentkit.SessionEvent) []Todo
LatestTodos returns the task list from the most recent todo/update event.
func PendingTodos ¶
PendingTodos filters LatestTodos down to entries that still need work.
type TodoUpdateData ¶
type TodoUpdateData struct {
Items []Todo `json:"items"`
}
TodoUpdateData is the payload of an EventTodoUpdate event. It carries the full list after the update so the latest event alone reconstructs the state.
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. Messages holds the text injected to keep the agent going; derive replays it as a user message, so this single event is both the audit record and the model-visible source.
type TurnEndData ¶
type TurnEndData struct {
Steps int `json:"steps"`
}
type TurnStartData ¶
type TurnStartData struct{}
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.
func LatestUsage ¶
func LatestUsage(events []agentkit.SessionEvent) UsageData
LatestUsage returns the most recent usage event. Its InputTokens is the measured prompt size at that step — the best available reading of how large the context currently is, already net of any earlier compaction.
func TotalUsage ¶
func TotalUsage(events []agentkit.SessionEvent, seq agentkit.EventSeq) UsageData
TotalUsage sums usage events recorded after seq.