feat(agentexec): record each agent run's transcript and show it per step (#1718)
The loop runner hooks every model call and tool call and reports ordered,
redacted, clipped entries. Each is persisted as an agent_transcript task
event through InsertEvent, left out of the timeline read, and served per
attempt at /api/tasks/{id}/transcript. The step run view shows it with Trace.
This commit is contained in:
35 files changed
+791
-68
No files matched your search
@@ -228,7 +228,7 @@ func (q *Queries) StageStats(ctx context.Context, scopeOrg pgtype.Text) ([]Stage
|
||||
const taskEventsByID = `-- name: TaskEventsByID :many
|
||||
SELECT id, at, kind, task_id, repo, issue, workflow, stage, attempt, actor_id, actor_kind, principal_id, detail, data, org_id, workspace_id
|
||||
FROM events
|
||||
WHERE task_id = $1 AND ($2::text IS NULL OR org_id = $2)
|
||||
WHERE task_id = $1 AND kind <> 'agent_transcript' AND ($2::text IS NULL OR org_id = $2)
|
||||
ORDER BY id
|
||||
`
|
||||
|
||||
@@ -274,6 +274,56 @@ func (q *Queries) TaskEventsByID(ctx context.Context, arg TaskEventsByIDParams)
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const taskTranscript = `-- name: TaskTranscript :many
|
||||
SELECT id, at, kind, task_id, repo, issue, workflow, stage, attempt, actor_id, actor_kind, principal_id, detail, data, org_id, workspace_id
|
||||
FROM events
|
||||
WHERE task_id = $1 AND attempt = $2 AND kind = 'agent_transcript' AND ($3::text IS NULL OR org_id = $3)
|
||||
ORDER BY id
|
||||
`
|
||||
|
||||
type TaskTranscriptParams struct {
|
||||
TaskID int64
|
||||
Attempt int64
|
||||
ScopeOrg pgtype.Text
|
||||
}
|
||||
|
||||
func (q *Queries) TaskTranscript(ctx context.Context, arg TaskTranscriptParams) ([]Event, error) {
|
||||
rows, err := q.db.Query(ctx, taskTranscript, arg.TaskID, arg.Attempt, arg.ScopeOrg)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []Event
|
||||
for rows.Next() {
|
||||
var i Event
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.At,
|
||||
&i.Kind,
|
||||
&i.TaskID,
|
||||
&i.Repo,
|
||||
&i.Issue,
|
||||
&i.Workflow,
|
||||
&i.Stage,
|
||||
&i.Attempt,
|
||||
&i.ActorID,
|
||||
&i.ActorKind,
|
||||
&i.PrincipalID,
|
||||
&i.Detail,
|
||||
&i.Data,
|
||||
&i.OrgID,
|
||||
&i.WorkspaceID,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const tokensByDay = `-- name: TokensByDay :many
|
||||
WITH event_totals AS (
|
||||
SELECT task_id, to_char(at AT TIME ZONE 'UTC', 'YYYY-MM-DD') AS day,
|
||||
|
||||
Reference in new issue
Block a user