feat(runs): filter runs by workflow and name each tool call in a trail entry (#2061)
This commit is contained in:
3 files changed
+31
-14
No files matched your search
@@ -2906,6 +2906,8 @@ components:
|
||||
RunsToolCallView:
|
||||
additionalProperties: false
|
||||
properties:
|
||||
id:
|
||||
type: string
|
||||
input:
|
||||
type: string
|
||||
name:
|
||||
@@ -2953,6 +2955,8 @@ components:
|
||||
at:
|
||||
format: date-time
|
||||
type: string
|
||||
call_id:
|
||||
type: string
|
||||
error:
|
||||
type: string
|
||||
finish_reason:
|
||||
@@ -6145,6 +6149,13 @@ paths:
|
||||
maximum: 200
|
||||
minimum: 1
|
||||
type: integer
|
||||
- description: Only this workflow's runs
|
||||
explode: false
|
||||
in: query
|
||||
name: workflow
|
||||
schema:
|
||||
description: Only this workflow's runs
|
||||
type: string
|
||||
responses:
|
||||
"200":
|
||||
content:
|
||||
|
||||
@@ -521,12 +521,13 @@ type Recorded struct {
|
||||
RecordedAt time.Time `db:"recorded_at"`
|
||||
}
|
||||
|
||||
// Recent returns an organisation's latest runs, newest first.
|
||||
func (s *Store) Recent(ctx context.Context, orgID string, limit int) ([]Summary, error) {
|
||||
// Recent returns an organisation's latest runs, newest first, of one workflow when
|
||||
// one is named.
|
||||
func (s *Store) Recent(ctx context.Context, orgID, workflow string, limit int) ([]Summary, error) {
|
||||
var out []Summary
|
||||
if err := s.db.SelectContext(ctx, &out, `
|
||||
SELECT id, workflow, workflow_version, state, attempts, error, detail, created_at, finished_at, dry FROM runs.runs
|
||||
WHERE org_id = $1 AND NOT dry ORDER BY created_at DESC LIMIT $2`, orgID, limit); err != nil {
|
||||
WHERE org_id = $1 AND NOT dry AND ($3 = '' OR workflow = $3) ORDER BY created_at DESC LIMIT $2`, orgID, limit, workflow); err != nil {
|
||||
return nil, fmt.Errorf("list runs: %w", err)
|
||||
}
|
||||
return out, nil
|
||||
|
||||
+16
-11
@@ -121,16 +121,20 @@ type TrailEntry struct {
|
||||
// tools offered and the sampling settings.
|
||||
Request jsontext.Value `json:"request,omitzero"`
|
||||
// FinishReason is the wire finish reason of a model call.
|
||||
FinishReason string `json:"finish_reason,omitzero"`
|
||||
Input string `json:"input,omitzero"`
|
||||
Output string `json:"output,omitzero"`
|
||||
Value jsontext.Value `json:"value,omitzero"`
|
||||
Error string `json:"error,omitzero"`
|
||||
Unknown bool `json:"unknown,omitzero"`
|
||||
FinishReason string `json:"finish_reason,omitzero"`
|
||||
// CallID is the model's id for the tool call a tool entry answers.
|
||||
CallID string `json:"call_id,omitzero"`
|
||||
Input string `json:"input,omitzero"`
|
||||
Output string `json:"output,omitzero"`
|
||||
Value jsontext.Value `json:"value,omitzero"`
|
||||
Error string `json:"error,omitzero"`
|
||||
Unknown bool `json:"unknown,omitzero"`
|
||||
}
|
||||
|
||||
// ToolCallView is a tool call a model asked for.
|
||||
type ToolCallView struct {
|
||||
// ID pairs the call with the tool entry that answers it.
|
||||
ID string `json:"id,omitzero"`
|
||||
Name string `json:"name"`
|
||||
Input string `json:"input"`
|
||||
}
|
||||
@@ -221,7 +225,8 @@ func (a *runAPI) cancel(ctx context.Context, in *cancelRunInput) (*httpapi.Reply
|
||||
}
|
||||
|
||||
type recentRunsInput struct {
|
||||
Limit int `query:"limit" minimum:"1" maximum:"200" default:"50"`
|
||||
Limit int `query:"limit" minimum:"1" maximum:"200" default:"50"`
|
||||
Workflow string `query:"workflow" doc:"Only this workflow's runs"`
|
||||
}
|
||||
|
||||
type runInput struct {
|
||||
@@ -238,7 +243,7 @@ type runAPI struct {
|
||||
}
|
||||
|
||||
func (a *runAPI) recent(ctx context.Context, in *recentRunsInput) (*httpapi.Reply[[]RunView], error) {
|
||||
runs, err := a.db.Recent(ctx, a.orgID, in.Limit)
|
||||
runs, err := a.db.Recent(ctx, a.orgID, in.Workflow, in.Limit)
|
||||
if err != nil {
|
||||
return nil, huma.NewError(http.StatusInternalServerError, "couldn't list runs")
|
||||
}
|
||||
@@ -432,7 +437,7 @@ func entry(s store.Recorded) TrailEntry {
|
||||
}
|
||||
switch je.Kind {
|
||||
case agentloop.EntryTool:
|
||||
e.Kind, e.Name = "tool", je.ToolName
|
||||
e.Kind, e.Name, e.CallID = "tool", je.ToolName, je.ToolCallID
|
||||
e.Input, e.Output, e.Error, e.Unknown = je.Input, je.Output, je.Error, je.Unknown
|
||||
case agentloop.EntryModel, agentloop.EntryCompact:
|
||||
e.Kind, e.Name = "model", ""
|
||||
@@ -450,7 +455,7 @@ func entry(s store.Recorded) TrailEntry {
|
||||
}
|
||||
}
|
||||
for _, c := range je.Message.ToolCalls {
|
||||
e.ToolCalls = append(e.ToolCalls, ToolCallView{Name: c.Name, Input: c.Arguments})
|
||||
e.ToolCalls = append(e.ToolCalls, ToolCallView{ID: c.ID, Name: c.Name, Input: c.Arguments})
|
||||
}
|
||||
}
|
||||
e.Error = je.Error
|
||||
@@ -460,7 +465,7 @@ func entry(s store.Recorded) TrailEntry {
|
||||
|
||||
// Recent returns orgID's latest runs, newest first.
|
||||
func (e *Engine) Recent(ctx context.Context, orgID string, limit int) ([]RunView, error) {
|
||||
runs, err := e.db.Recent(ctx, orgID, limit)
|
||||
runs, err := e.db.Recent(ctx, orgID, "", limit)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user