package agentrun import "context" // Runner executes one autonomous stage against an already prepared workspace. type Runner interface { // report receives what the run does as it happens; its zero value // discards everything. Run(ctx context.Context, workspace string, req Request, report Reporter) (Result, error) } // ToolCallReport is one completed tool invocation, reported through a // Reporter. type ToolCallReport struct { Tool string // Detail is a clipped one-line summary: the tool's result, or // "error: " if it failed. Detail string Failed bool } // Reporter receives a run's activity. Either func may be nil. type Reporter struct { // ToolCall is notified once per completed tool call. ToolCall func(ToolCallReport) // Transcript is notified of each transcript entry, in order. Transcript func(TranscriptEntry) } // ReportTranscript forwards entry to r.Transcript, if set. func (r Reporter) ReportTranscript(entry TranscriptEntry) { if r.Transcript != nil { r.Transcript(entry) } } // Transcript entry kinds. const ( TranscriptSystem = "system" // Text: the system prompt TranscriptUser = "user" // Text: the mission, or input the loop added later TranscriptModel = "model" // Reasoning, Text and ToolCalls: one model response TranscriptTool = "tool" // one tool call's arguments and result TranscriptCompaction = "compaction" // Text: the summary that replaced the history ) // TranscriptEntry is one ordered item of an agent run's conversation. Text // fields are redacted and clipped; a *Bytes field holds the full size when its // field was clipped. type TranscriptEntry struct { Seq int `json:"seq"` Kind string `json:"kind"` Text string `json:"text,omitempty"` TextBytes int `json:"text_bytes,omitempty"` ToolCalls []TranscriptToolCall `json:"tool_calls,omitempty"` Reasoning string `json:"reasoning,omitempty"` ReasoningBytes int `json:"reasoning_bytes,omitempty"` CallID string `json:"call_id,omitempty"` Tool string `json:"tool,omitempty"` Args string `json:"args,omitempty"` ArgsBytes int `json:"args_bytes,omitempty"` Output string `json:"output,omitempty"` OutputBytes int `json:"output_bytes,omitempty"` Error string `json:"error,omitempty"` FinishReason string `json:"finish_reason,omitempty"` Usage *Usage `json:"usage,omitempty"` LatencyMS int64 `json:"latency_ms,omitempty"` } // TranscriptToolCall is one tool call a model response requested. type TranscriptToolCall struct { ID string `json:"id,omitempty"` Name string `json:"name"` Args string `json:"args,omitempty"` ArgsBytes int `json:"args_bytes,omitempty"` } // BlockedError is a run failure an operator fixes outside the run, such as a // model provider refusing its credential. Blocker is the taskstate blocker // that names the fix. type BlockedError struct { Blocker string Err error } func (e *BlockedError) Error() string { return e.Err.Error() } func (e *BlockedError) Unwrap() error { return e.Err }