Skip to content

Commit d678e46

Browse files
committed
docs; updates for #1040
1 parent 2c761dc commit d678e46

File tree

3 files changed

+39
-0
lines changed

3 files changed

+39
-0
lines changed

docs/src/content/docs/guides/results.mdx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ Most applications only need a few result properties:
2626
| `lastAgent` / `activeAgent` | The agent that should usually handle the next turn. |
2727
| `lastResponseId` | Continuation with `previousResponseId` on the next OpenAI Responses turn. |
2828
| `interruptions` | Pending tool approvals you must resolve before resuming. |
29+
| `runContext` | App context, approvals, usage, and nested `toolInput`. |
2930
| `state` | A serializable snapshot for resume/retry flows. |
3031

3132
## Final output
@@ -92,6 +93,10 @@ The `newItems` property contains the new items generated during the run. The ite
9293

9394
The `state` property contains the state of the run. Most of what is attached to the `result` is derived from the `state`, but `state` is also serializable/deserializable and can be used as input for a subsequent call to `run()` if you need to [recover from an error](/openai-agents-js/guides/running-agents#exceptions) or resume a paused [human-in-the-loop](/openai-agents-js/guides/human-in-the-loop) flow.
9495

96+
## Run context
97+
98+
The `runContext` property is the supported way to read the public run context for a result. `result.runContext.context` is the app context you passed into `run()`, and `result.runContext.toolInput` contains structured agent-tool input when that nested run was given one.
99+
95100
## Interruptions
96101

97102
If you are using `needsApproval` in your agent, your run might pause and expose `interruptions`. This array contains the `RunToolApprovalItem`s that require a decision before the run can continue. Resolve them through `result.state.approve(...)` / `result.state.reject(...)`, then call `run()` again with that same state. Check the [human-in-the-loop guide](/openai-agents-js/guides/human-in-the-loop) for end-to-end patterns.

docs/src/content/docs/guides/tools.mdx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import localBuiltInToolsExample from '../../../../../examples/docs/tools/localBu
1010
import nonStrictSchemaTools from '../../../../../examples/docs/tools/nonStrictSchemaTools.ts?raw';
1111
import agentsAsToolsExample from '../../../../../examples/docs/tools/agentsAsTools.ts?raw';
1212
import agentsAsToolsStreamingExample from '../../../../../examples/docs/tools/agentsAsToolsStreaming.ts?raw';
13+
import agentToolRunContextExample from '../../../../../examples/docs/tools/agentToolRunContext.ts?raw';
1314
import mcpLocalServer from '../../../../../examples/docs/tools/mcpLocalServer.ts?raw';
1415
import codexToolExample from '../../../../../examples/docs/tools/codexTool.ts?raw';
1516
import codexRunContextThreadExample from '../../../../../examples/docs/tools/codexRunContextThread.ts?raw';
@@ -189,6 +190,14 @@ When you run an agent as a tool, Agents SDK creates a runner with the default se
189190

190191
You can also set `needsApproval` and `isEnabled` on the agent tool via `asTool()` options to integrate with human‑in‑the‑loop flows and conditional tool availability.
191192

193+
Inside `customOutputExtractor`, use `result.agentToolInvocation` to inspect the current `Agent.asTool()` invocation. In that callback the result always comes from `Agent.asTool()`, so `agentToolInvocation` is always defined and exposes `toolName`, `toolCallId`, and `toolArguments`. Use `result.runContext` for the regular app context and `toolInput`. This metadata is scoped to the current nested invocation and is not serialized into `RunState`.
194+
195+
<Code
196+
lang="typescript"
197+
code={agentToolRunContextExample}
198+
title="Read agent tool invocation metadata"
199+
/>
200+
192201
Advanced structured-input options for `agent.asTool()`:
193202

194203
- `inputBuilder`: maps structured tool args to the nested agent input payload.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { Agent } from '@openai/agents';
2+
3+
const billingAgent = new Agent({
4+
name: 'Billing Agent',
5+
instructions: 'Handle billing questions and subscription changes.',
6+
});
7+
8+
const billingTool = billingAgent.asTool({
9+
toolName: 'billing_agent',
10+
toolDescription: 'Handles customer billing questions.',
11+
customOutputExtractor(result) {
12+
console.log('tool', result.agentToolInvocation.toolName);
13+
// Direct invoke() calls may not have a model-generated tool call id.
14+
console.log('call', result.agentToolInvocation.toolCallId);
15+
console.log('args', result.agentToolInvocation.toolArguments);
16+
17+
return String(result.finalOutput ?? '');
18+
},
19+
});
20+
21+
const orchestrator = new Agent({
22+
name: 'Support Orchestrator',
23+
instructions: 'Delegate billing questions to the billing agent tool.',
24+
tools: [billingTool],
25+
});

0 commit comments

Comments
 (0)