Skip to content

Commit d8caec4

Browse files
authored
test(qa): cover composed tool result consumption (#118991)
1 parent abf9e26 commit d8caec4

1 file changed

Lines changed: 141 additions & 0 deletions

File tree

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
title: Agent tool result consumption
2+
3+
scenario:
4+
id: agent-tool-consumption
5+
surface: agent-runtime
6+
coverage:
7+
primary:
8+
- agent-runtime.tool-switching
9+
- agent-runtime.tool-no-fake-progress
10+
- agent-runtime.tool-evidence
11+
objective: Verify one agent turn consumes two distinct real tool results in order before producing one evidence-backed terminal response.
12+
successCriteria:
13+
- The agent calls memory_search and memory_get in strict sequence with distinct call identities.
14+
- Each tool result reaches the next provider request with the matching call identity.
15+
- No terminal response is emitted until both tool results have been consumed.
16+
- The single terminal response quotes a nonce available only from the memory_get result.
17+
docsRefs:
18+
- docs/help/testing.md
19+
codeRefs:
20+
- src/agents/embedded-agent-runner/run/attempt.ts
21+
- extensions/memory-core/src/tools.ts
22+
- extensions/qa-lab/src/providers/mock-openai/server.ts
23+
execution:
24+
kind: flow
25+
summary: Consume an ordered memory_search and memory_get chain before one evidence-backed terminal response.
26+
providerMode: mock-openai
27+
retryCount: 0
28+
config:
29+
requiredProviderMode: mock-openai
30+
memoryQuery: hidden project codename
31+
expectedMemoryPath: memory/qa-agent-tool-consumption.md
32+
promptSnippet: "Memory tools check"
33+
prompt: "Memory tools check: what is the hidden project codename stored only in memory? Use memory tools first. Do not guess, narrate progress, or claim completion before both tool results are available."
34+
35+
flow:
36+
steps:
37+
- name: consumes both matched tool results before replying
38+
actions:
39+
- assert:
40+
expr: "env.providerMode === config.requiredProviderMode"
41+
message:
42+
expr: "`expected provider mode ${config.requiredProviderMode}, got ${env.providerMode}`"
43+
- call: reset
44+
- set: nonce
45+
value:
46+
expr: "`ORBIT-${parseInt(randomUUID().replaceAll('-', '').slice(0, 8), 16)}`"
47+
- set: memoryFact
48+
value:
49+
expr: "`Hidden QA fact: the project codename is ${nonce}.`"
50+
- assert:
51+
expr: "!config.prompt.includes(nonce)"
52+
message: tool-only nonce leaked into the user prompt
53+
- call: fs.mkdir
54+
args:
55+
- expr: "path.dirname(path.join(env.gateway.workspaceDir, config.expectedMemoryPath))"
56+
- recursive: true
57+
- call: fs.writeFile
58+
args:
59+
- expr: "path.join(env.gateway.workspaceDir, config.expectedMemoryPath)"
60+
- expr: "`${memoryFact}\\n`"
61+
- utf8
62+
- call: forceMemoryIndex
63+
args:
64+
- env:
65+
ref: env
66+
query:
67+
expr: config.memoryQuery
68+
expectedNeedle:
69+
ref: nonce
70+
- call: waitForGatewayHealthy
71+
args:
72+
- ref: env
73+
- 60000
74+
- set: requestCursorBefore
75+
value:
76+
expr: "(await fetchJson(`${env.mock.baseUrl}/debug/request-cursor`)).cursor"
77+
- set: outboundStartIndex
78+
value:
79+
expr: "state.getSnapshot().messages.filter((message) => message.direction === 'outbound').length"
80+
- set: sessionKey
81+
value:
82+
expr: "`agent:qa:tool-consumption:${randomUUID().slice(0, 8)}`"
83+
- call: runAgentPrompt
84+
args:
85+
- ref: env
86+
- sessionKey:
87+
ref: sessionKey
88+
message:
89+
expr: config.prompt
90+
timeoutMs:
91+
expr: liveTurnTimeoutMs(env, 30000)
92+
- call: waitForOutboundMessage
93+
saveAs: outbound
94+
args:
95+
- ref: state
96+
- lambda:
97+
params: [candidate]
98+
expr: "candidate.conversation.id === 'qa-operator' && candidate.text.includes(nonce)"
99+
- expr: liveTurnTimeoutMs(env, 30000)
100+
- sinceIndex:
101+
ref: outboundStartIndex
102+
- set: scenarioRequests
103+
value:
104+
expr: "(await fetchJson(`${env.mock.baseUrl}/debug/requests?after=${requestCursorBefore}`)).filter((request) => String(request.allInputText ?? '').includes(config.promptSnippet))"
105+
- assert:
106+
expr: scenarioRequests.length === 3
107+
message:
108+
expr: "`expected exactly three provider requests, got ${JSON.stringify(scenarioRequests)}`"
109+
- set: searchPlanRequest
110+
value:
111+
expr: scenarioRequests[0]
112+
- set: searchResultRequest
113+
value:
114+
expr: scenarioRequests[1]
115+
- set: getResultRequest
116+
value:
117+
expr: scenarioRequests[2]
118+
- assert:
119+
expr: "searchPlanRequest.plannedToolName === 'memory_search' && typeof searchPlanRequest.plannedToolCallId === 'string' && searchPlanRequest.plannedToolCallId.length > 0 && !searchPlanRequest.toolOutputCallId && !String(searchPlanRequest.allInputText ?? '').includes(nonce)"
120+
message:
121+
expr: "`first request did not exclusively plan memory_search without the nonce: ${JSON.stringify(searchPlanRequest)}`"
122+
- assert:
123+
expr: "searchResultRequest.toolOutputCallId === searchPlanRequest.plannedToolCallId && searchResultRequest.toolOutputStructuredError !== true && String(searchResultRequest.toolOutput ?? '').includes(config.expectedMemoryPath) && String(searchResultRequest.toolOutput ?? '').includes(nonce) && String(searchResultRequest.allInputText ?? '').includes(nonce) && searchResultRequest.plannedToolName === 'memory_get' && searchResultRequest.plannedToolArgs?.path === config.expectedMemoryPath && typeof searchResultRequest.plannedToolCallId === 'string' && searchResultRequest.plannedToolCallId.length > 0 && searchResultRequest.plannedToolCallId !== searchPlanRequest.plannedToolCallId"
124+
message:
125+
expr: "`memory_search result did not causally plan a distinct memory_get call: ${JSON.stringify(searchResultRequest)}`"
126+
- assert:
127+
expr: "getResultRequest.toolOutputCallId === searchResultRequest.plannedToolCallId && getResultRequest.toolOutputStructuredError !== true && String(getResultRequest.toolOutput ?? '').includes(nonce) && String(getResultRequest.allInputText ?? '').includes(nonce) && !getResultRequest.plannedToolName"
128+
message:
129+
expr: "`memory_get result was not consumed before terminal generation: ${JSON.stringify(getResultRequest)}`"
130+
- set: terminalOutbounds
131+
value:
132+
expr: "state.getSnapshot().messages.filter((message) => message.direction === 'outbound').slice(outboundStartIndex)"
133+
- assert:
134+
expr: "terminalOutbounds.length === 1 && terminalOutbounds[0].id === outbound.id"
135+
message:
136+
expr: "`expected exactly one visible terminal outcome after both results: ${JSON.stringify(terminalOutbounds)}`"
137+
- assert:
138+
expr: "outbound.text.includes(nonce) && (outbound.text.match(new RegExp(nonce, 'g')) ?? []).length === 1"
139+
message:
140+
expr: "`terminal response did not quote the tool-only nonce exactly once: ${outbound.text}`"
141+
detailsExpr: "`${outbound.text}; tools=${searchPlanRequest.plannedToolName}->${searchResultRequest.plannedToolName}; matched=${searchResultRequest.toolOutputCallId === searchPlanRequest.plannedToolCallId && getResultRequest.toolOutputCallId === searchResultRequest.plannedToolCallId}; terminalOutcomes=${terminalOutbounds.length}`"

0 commit comments

Comments
 (0)