Skip to content

feat: expose agent tool invocation metadata on run results#1040

Merged
seratch merged 3 commits intomainfrom
feat/agent-tool-run-context
Mar 2, 2026
Merged

feat: expose agent tool invocation metadata on run results#1040
seratch merged 3 commits intomainfrom
feat/agent-tool-run-context

Conversation

@seratch
Copy link
Copy Markdown
Member

@seratch seratch commented Mar 2, 2026

This pull request adds result. agentToolInvocation for nested Agent.asTool() runs and keeps result.runContext focused on plain execution context. The main runtime change lives under packages/agents-core/src/{agent,result,runContext,runState}.ts, with supporting tests in packages/agents-core/test/**, and it also exports CompletedAgentToolRunResult so customOutputExtractor can be annotated explicitly by SDK users.

The change is intentionally simpler than the earlier runContext-union approach: agent-tool invocation metadata now lives on the result object that consumes it, RunContext no longer carries agent-tool-specific shape, and serialized RunState writes top-level agentToolInvocation metadata.

Minimal usage example:

const billingTool = billingAgent.asTool({
  toolName: 'billing_agent',
  customOutputExtractor(result: CompletedAgentToolRunResult<any, typeof billingAgent>) {
    console.log(result.agentToolInvocation.toolName);
    console.log(result.agentToolInvocation.toolCallId);
    return String(result.finalOutput ?? '');
  },
});

Behaviorally, this gives users a stable public way to inspect nested agent-tool calls without reading result.state._context, and it keeps resumed nested runs consistent with non-resumed runs.

@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Mar 2, 2026

🦋 Changeset detected

Latest commit: 29c9036

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 5 packages
Name Type
@openai/agents-core Patch
@openai/agents Patch
@openai/agents-extensions Patch
@openai/agents-openai Patch
@openai/agents-realtime Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions github-actions bot added this to the 0.5.x milestone Mar 2, 2026
@seratch
Copy link
Copy Markdown
Member Author

seratch commented Mar 2, 2026

@codex review again

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 0b5b2c0750

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@seratch seratch merged commit e9f701e into main Mar 2, 2026
6 checks passed
@seratch seratch deleted the feat/agent-tool-run-context branch March 2, 2026 05:06
seratch added a commit that referenced this pull request Mar 2, 2026
@seratch seratch mentioned this pull request Mar 2, 2026
seratch added a commit that referenced this pull request Mar 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant