Skip to content

Conversation

@OiPunk
Copy link
Contributor

@OiPunk OiPunk commented Feb 10, 2026

Summary

This fixes a bug where an agent used as a tool could ignore the parent run's RunConfig (notably custom model_provider) unless a separate run_config was explicitly passed to Agent.as_tool(...).

What changed

  • Added run_config to ToolContext so tool invocations can carry run-level configuration metadata.
  • In function tool execution, pass the active run config into ToolContext.from_agent_context(...).
  • In Agent.as_tool(...):
    • if run_config is explicitly provided, keep using it;
    • otherwise inherit run_config from the parent ToolContext when available.
  • Added regression tests for:
    • inheriting parent run_config when as_tool(run_config=None);
    • explicit run_config overriding parent context;
    • function tool contexts receiving the active RunConfig.

Why this is safe

  • Backward compatibility is preserved: explicit run_config behavior remains unchanged.
  • Existing code paths without nested agent tools are unaffected.
  • The change is additive (ToolContext.run_config defaults to None).

Validation

  • uv run --with ruff ruff check src/agents/agent.py src/agents/tool_context.py src/agents/run_internal/tool_execution.py tests/test_agent_as_tool.py tests/test_tool_context.py tests/test_run_step_execution.py
  • uv run --with pytest --with socksio pytest -q tests/test_tool_context.py tests/test_agent_as_tool.py tests/test_run_step_execution.py
  • uv run --with mypy --with socksio mypy src/agents/agent.py src/agents/tool_context.py src/agents/run_internal/tool_execution.py tests/test_tool_context.py tests/test_agent_as_tool.py tests/test_run_step_execution.py
  • Targeted trace coverage run to confirm modified paths were exercised.

@OiPunk
Copy link
Contributor Author

OiPunk commented Feb 10, 2026

Added a follow-up regression test in commit b8741b1 to explicitly cover inherited tracing privacy config on agent-as-tool runs:\n\n- \n\nThis verifies that on the parent RunConfig is preserved for the nested run when does not pass an explicit run_config.

@OiPunk
Copy link
Contributor Author

OiPunk commented Feb 10, 2026

Correction for formatting: added follow-up regression test in commit b8741b1 named test_agent_as_tool_inherits_trace_include_sensitive_data_setting. It verifies that trace_include_sensitive_data=False on the parent RunConfig is preserved for nested agent-as-tool runs when no explicit run_config is passed to as_tool.

Copy link
Member

@seratch seratch left a comment

Choose a reason for hiding this comment

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

one minor request

@seratch
Copy link
Member

seratch commented Feb 10, 2026

@codex review again

@seratch seratch added this to the 0.8.x milestone Feb 10, 2026
@chatgpt-codex-connector
Copy link

Codex Review: Didn't find any major issues. 🚀

ℹ️ 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".

@OiPunk
Copy link
Contributor Author

OiPunk commented Feb 11, 2026

Implemented this suggestion in commit 0d6f225.

Change made:

  • ToolContext.from_agent_context() now marks run_config as keyword-only (*) for clearer call-site intent and safer future parameter additions.

Local verification:

  • uv run ruff check src/agents/tool_context.py tests/test_tool_context.py tests/test_tool_metadata.py
  • uv run mypy src/agents/tool_context.py
  • env -u ALL_PROXY -u all_proxy -u HTTPS_PROXY -u https_proxy -u HTTP_PROXY -u http_proxy -u NO_PROXY -u no_proxy uv run pytest tests/test_tool_context.py tests/test_tool_metadata.py -q (11 passed)

@seratch seratch merged commit 1168ee1 into openai:main Feb 11, 2026
10 checks passed
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.

2 participants