Skip to content

feat(tools): edit selected tool results before tracing and publication - #6141

Open
markstuart-oai wants to merge 3 commits into
feat/simple-codexfrom
feat/runner-tool-text-transforms
Open

markstuart-oai wants to merge 3 commits into
feat/simple-codexfrom
feat/runner-tool-text-transforms

Conversation

@markstuart-oai

@markstuart-oai markstuart-oai commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

Summary

This pull request adds experimental tool_text_transforms for SDK function tools and SDK-discovered MCP tools. With prepare_tool_output, an MCP result can already be visible in a trace when the editor runs. A selected text editor runs before the Runner publishes the result to traces, history or the next model request.

Register the same function tool on the agent and in the run configuration. For MCP, use the connected server object and the original tool name.

from agents import Agent, RunConfig, Runner, ToolExecutionConfig, function_tool

@function_tool
def report() -> str:
    return "internal draft"

async def hide_drafts(call, texts):
    return tuple(text.replace("internal draft", "[hidden]") for text in texts)

async def run(server):
    agent = Agent(name="reports", tools=[report], mcp_servers=[server])
    config = RunConfig(
        tool_execution=ToolExecutionConfig(
            tool_text_transforms=[(report, hide_drafts), ((server, "read.report"), hide_drafts)]
        )
    )
    return await Runner.run(agent, "Check the reports", run_config=config)

Creating a second wrapper or reconnecting a server can leave a selector pointing to an unused object. The Runner raises UserError before invoking another object with the same key unless it has its own exact editor. For local functions, the key includes the tool name and namespace. For MCP, it is the server name and original tool name. This rule applies across agents. Use distinct keys or register an editor for each object. For a namespace, register the tool returned by tool_namespace.

A pending selected call saves an editor requirement in the invocation record. Register the current tool or server again on resume. A missing match stops the call before execution. A paused ResumableSession checks those pending calls, including calls in an interrupted agent tool, before claiming the session, so the caller can correct the configuration and retry. Older snapshots remain readable and have no saved requirement.

The editor returns one string per text slot. For typed function results, return a one-element tuple containing JSON. The SDK validates the edited JSON, checks that serialization preserves the values and returns a dictionary. A selected call bypasses prepare_tool_output and error formatters. A failed tool or invalid edit stops the run without publishing the rejected result. Any completed side effects remain.

The application must trust the editor and retained media. Hosted and native tools are outside this option.

Test plan

  • Both Runner modes, repeated wrappers, exact selectors across agents and namespaces, and live and restored MCP approvals. Paused sessions cover refusals and corrected retries, including child runs.
  • SDK and OpenTelemetry traces, streamed events, saved history and the next model request on success, failure and cancellation.
  • Focused checks on MCP 1 and 2, full SDK verification (13,400 passed, 50 skipped) and the documentation build.

Checks

  • Added regression tests.
  • Ran .agents/skills/code-change-verification/scripts/run.sh.
  • Confirmed all verification steps pass.
  • Completed two independent reviews of the full diff.

@markstuart-oai
markstuart-oai requested review from a team, rm-openai and seratch as code owners November 21, 2026 14:48
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 21, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-22T22:20:08.928024Z b2ed3f7 New commits
🔒 Security Review ✅ Completed 2026-11-22T22:20:25.764213Z b2ed3f7 New commits
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@jbeckwith-oai jbeckwith-oai left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Approved at e05a2ee67a5447052d48e1e58d95764fd1e31391. Reviewed the full nine-file change and surrounding invocation, MCP conversion, tracing, and publication paths, with two independent reviews. No actionable findings. Exact function/server identity selection, edited text and retained-media ordering, typed JSON validation and conversion preservation, approval/resume and stream argument isolation, failure/timeout/cancellation handling, and process-control diagnostic redaction are consistent with the documented scope. Regression tests cover SDK/OpenTelemetry traces, streamed output, saved history, and the next model request.

The editor and retained media remain trusted; completed tool side effects cannot be undone, and hosted/native tools are outside this feature. Hosted CI is complete: 33 checks passed and 2 skipped; no failures. Static review only; no candidate code or local tests executed.

Update feat/runner-tool-text-transforms against feat/simple-codex.

@jbeckwith-oai jbeckwith-oai left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Re-reviewed current commit b2ed3f71cb8f2777bf77ebc8756afbee680304b7 and the selector/admission/restore changes since the prior approval. Checked exact function and MCP server identity, namespaced dispatch collisions, weak-reference preservation through tool copying, requirement binding before admission and rechecking before side effects, and persistence of incomplete selected calls in schema 1.23. Missing or stale editors are rejected before a paused session becomes active; nested agent-tool policies follow the same live override/inheritance rules as execution, and rejected calls do not require an editor. Reviewed the new restore and retryability cases alongside the existing output transformation and redaction paths; no actionable regression found.

Hosted CI: {'SUCCESS': 17, 'IN_PROGRESS': 7}. Unfinished checks remain pending follow-up. Static review only; no candidate code or local tests executed.

Hosted CI follow-up (2026-11-22 22:40 UTC): all 33 executed checks passed; 2 checks skipped. No checks remain pending for this commit. Static review only; no local tests executed.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants