Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion core/session/toolpair/toolpair.go
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,11 @@ func Calls(events []model.SessionEvent, opts Options) Result {
}
}
prev[c.agent] = msgs
if lastAsk[c.agent].Before(c.req.At) {
// Only a call that offers tools can carry a tool's result. Bob's security classifier and
// router calls offer none, and they follow every tool call. An imported call has no
// manifest, but a transcript holds only real turns.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: "Only a call that offers tools can carry a tool's result" is not quite what this gate does. The ToolResults loop above still records a result from any request, tool-less ones included, and that is right. What this decides is whether the request counts as the agent asking again, which is the input to ReasonAbandoned. Something like "Only a call that offers tools counts as the agent moving on…" would say that. Two other comments still describe the old rule and could be updated in the same pass: the lastAsk declaration ("agent → its latest request's At", line 319) and the ReasonAbandoned doc ("asked again without ever carrying its result").

canAnswer := len(inf.Tools) > 0 || inf.ToolCount > 0 || c.req.Imported()
if canAnswer && lastAsk[c.agent].Before(c.req.At) {
lastAsk[c.agent] = c.req.At
}

Expand Down
25 changes: 25 additions & 0 deletions core/session/toolpair/toolpair_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,31 @@ func TestAbandonedCallIsNamedAsSuch(t *testing.T) {
}
}

// TestToolLessCallDoesNotAbandon: Bob asks its security classifier, with no tool manifest, while
// its command runs. That call cannot carry the result, so the command stays open until the
// request that does.
func TestToolLessCallDoesNotAbandon(t *testing.T) {
var r rec
bob := &model.EventClient{Name: "bob"}
ask := func(start float64, tools []model.InferenceTool, results []model.InferenceToolResult, calls ...model.InferenceToolCall) {
id := r.id()
r.add(model.SessionEvent{At: at(start), Phase: model.SessionRequest, RequestID: id, Client: bob,
Inference: &model.InferenceExtension{Tools: tools, Messages: []model.InferenceMessage{user("go")}, ToolResults: results}})
r.add(model.SessionEvent{At: at(start + 1), Phase: model.SessionResponse, RequestID: id, Client: bob, StatusCode: 200,
Inference: &model.InferenceExtension{FinishReason: "tool_calls", ToolCalls: calls}})
}
ask(0, manifest, nil, model.InferenceToolCall{ID: "t1", Name: "execute_command"})
ask(2, nil, nil) // the security classifier

if c := callOf(t, Calls(r.events, Options{}).Calls, "t1"); c.EndReason != "" {
t.Fatalf("after the classifier: EndReason = %q, want empty (still open)", c.EndReason)
}
ask(10, manifest, []model.InferenceToolResult{result("t1", "done")})
if c := callOf(t, Calls(r.events, Options{}).Calls, "t1"); c.EndReason != ReasonResult {
t.Errorf("after the result: EndReason = %q, want %q", c.EndReason, ReasonResult)
}
}

// TestOpenCallHasNoReason is the distinction the zero value exists for: a call still being
// waited on is not a lost one, and must not read as a 0 ms call.
func TestOpenCallHasNoReason(t *testing.T) {
Expand Down
Loading