Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Add run configuration inheritance for agent-as-tool workflows#1006

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
DanielHashmi wants to merge20 commits intoopenai:main
base:main
Choose a base branch
Loading
fromDanielHashmi:config-with-agent-as-tool

Conversation

DanielHashmi
Copy link
Contributor

Problem:
When using the "agents as tools" pattern, tool-agents create their own execution context but don't inherit the parent's run_config.

This creates two problems:
Tool-agents can't access the parent's global model configuration
If tool-agents don't have their own model field set and the parent's run_config.model is unavailable, model resolution fails entirely, causing the orchestrator to fail when calling the tool

Solution:
Modified the agent-as-tool execution to properly handle run_config inheritance while ensuring robust model resolution. This prevents execution failures when tool-agents lack explicit model configuration.

Changes

1. traces.py

  • Added_run_config attribute to bothNoOpTrace andTraceImpl classes
  • AddedTYPE_CHECKING import forRunConfig type annotation
  • Enables storing run configuration in trace context for cross-agent access

2. run.py

  • Enhanced trace context management to store run configuration
  • Implements two-tier storage: metadata dictionary (preferred) or_run_config attribute (fallback)
  • Ensures sub-agents can access original run configuration during execution

3. agent.py

  • Addedget_current_trace import from tracing module
  • Enhancedas_tool() method to retrieve and inherit run configuration from trace context
  • Passes inherited configuration toRunner.run() for consistent behavior

@seratchseratch added enhancementNew feature or request feature:core labelsJul 8, 2025
@seratch
Copy link
Member

I am not sure what@rh-openai thinks but here are my initial thoughts on this:

  • I see the need for some use cases but in general, setting the most suitable model for each agent would be recommended rather than sharing the parent's one (again, I hear the need though)
  • I don' think passing via current trace is the best approach for this; enhancing in a more straight-forward way without breaking changes would be ideal
DanielHashmi reacted with thumbs up emoji

Copy link
Collaborator

@rm-openairm-openai left a comment

Choose a reason for hiding this comment

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

Yeah using the trace to store this data isn't right. What you could do instead, is use a ContextVar. So:

  1. Add apass_run_config_to_sub_agents: bool param to the RunConfig, just in case people want to enable/disable this behavior
  2. Set the run_config context var from run.py
  3. Read the run_config in the agent as tool
  4. Also ensure that you add tests to make sure the contextvar is unset in all cases (errors, success, cancel etc)

I'm also not entirely sure if it makes sense to have this as part of the SDK, or just something you do. The approach I've taken to as_tool is that if you want customization, you can just create your own tool via:

@function_tooldef run_my_agent(input):  my_agent = Agent(...)  result = Runner.run(my_agent)  return result.foo

DanielHashmi reacted with thumbs up emoji
@DanielHashmi
Copy link
ContributorAuthor

Why This Feature is Needed

TheRunConfig is designed to serve as a global configuration for the entire agent workflow. However, the current implementation breaks this contract when agents are used as tools, creating an inconsistent experience where:

  1. Configuration Fragmentation: Global settings like model configuration, tracing preferences, and guardrails don't apply to sub-agents
  2. Debugging Difficulties: Tracing and observability settings don't propagate, making it hard to debug complex agent hierarchies
  3. Inconsistent Behavior: The same agent behaves differently when run directly vs. when used as a tool

This implementation addresses the OpenAI Agents SDK team's feedback to use ContextVar instead of storing configuration in traces, providing a clean, opt-in solution that maintains backward compatibility while enabling consistent global configuration across agent hierarchies.

Testing

Comprehensive test coverage includes:

  • RunConfig inheritance when enabled/disabled
  • Proper cleanup on errors and exceptions
  • Direct API testing of Scope methods
  • Integration testing with agent-as-tool workflows

This feature addresses a fundamental consistency issue in the SDK whereRunConfig wasn't truly "global" due to the gap in agent-as-tool scenarios. The ContextVar approach recommended by you guys is actually great, But previously i didn't know how to do this,

I have tried my best and changes the code according to the recommended way.

If it still needs modification, tell me! I will try my best :)

@DanielHashmi
Copy link
ContributorAuthor

I have updated this PR can your guys review it?@seratch@rm-openai

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@rm-openairm-openaiAwaiting requested review from rm-openai

@seratchseratchAwaiting requested review from seratch

Requested changes must be addressed to merge this pull request.

Assignees
No one assigned
Labels
enhancementNew feature or requestfeature:core
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

3 participants
@DanielHashmi@seratch@rm-openai

[8]ページ先頭

©2009-2025 Movatter.jp