Quality / check (pull_request) Successful in 3m38s
Record the model's reasoning parts. The step run view shows reasoning as a Thought row, shell calls as a terminal, the gate as a test run, web_fetch as a source, finish as the verdict, and each fan-out branch as a subagent.
86 lines
2.9 KiB
Go
86 lines
2.9 KiB
Go
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: <message>" 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)
|
|
}
|
|
|
|
// ReportToolCall forwards report to r.ToolCall, if set.
|
|
func (r Reporter) ReportToolCall(report ToolCallReport) {
|
|
if r.ToolCall != nil {
|
|
r.ToolCall(report)
|
|
}
|
|
}
|
|
|
|
// 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"`
|
|
}
|