Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

Feature proposal: inherited recursion-depth budget for Agent.as_tool delegation

未关闭
#5,453 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
5/5
预计耗时
一周以上
新手友好度
35/100
Issue 类型
功能
描述清晰度
描述清楚
活跃度
活跃
技术栈
python
领域
ai, backend

调研方向

Start with Agent.as_tool() in src/agents/agent.py, then trace how nested calls create Runner.run() and Runner.run_streamed() executions and how their turn limits are resolved. Review the existing runtime governance discussion #2775 and per-agent max_turns request #551 before deciding whether the proposed inherited depth limit fits the SDK. Done means maintainers settle the scope and semantics, including concurrent task inheritance and resumed workflows.

由索引模型根据 Issue 内容生成。

描述

Summary

I would like to propose an opt-in, inherited delegation-depth limit for Agent.as_tool() to help applications bound recursive or multi-agent delegation trees.

This is not a claim of a security vulnerability or a defect in max_turns. I understand that max_turns limits an individual Runner.run(), and a nested agent tool starts another run. The motivation is to offer an explicit SDK-side safety primitive when applications require a depth limit over a delegation chain, rather than just each run.

Reproduced behavior (no API access)

I ran a fully offline agents.testing.ScriptedModel test against public main commit cd26bbbc52847845fde73b9952b51e62e2bcbdc0 (v0.24.0 source) using distinct call IDs and a deliberately finite, four-delegation script.

  • Outer Runner.run(..., max_turns=1)
  • Recursive Agent.as_tool(..., max_turns=1)
  • Unmodified SDK: 5 model calls occur before the outer run raises MaxTurnsExceeded. This is consistent with per-run limits.
  • Candidate guard with max_agent_tool_depth=1: 2 model calls occur; the next nested agent tool fails before starting another child run, including through streaming.

The source boundary is Agent.as_tool() in src/agents/agent.py, where each nested invocation creates its own Runner.run() / Runner.run_streamed() with a separately resolved turn limit.

Proposed narrow, compatible implementation
  • Append optional max_agent_tool_depth: int | None = None to Agent.as_tool(). None preserves current behavior.
  • Track active agent-tool depth in an async context using ContextVar, with finally reset.
  • Propagate a configured limit through other agents' as_tool() wrappers, even if those descendants do not configure a limit. Children may tighten but cannot relax an inherited bound.
  • Reject excessive delegation before another child run is started.
  • No dependencies, persisted-state changes or wire-protocol changes.

Reproducible public research repository: https://github.com/BlackRonin-coder/openai-agents-recursive-budget-research

It contains the unmodified SDK reproducer, opt-in two-file patch, synthetic tests, and local verification log. The published candidate passed 1,188 relevant tests, 63 skipped, on macOS with Python 3.12.15; Ruff checks and a pristine-source patch-application check passed. I am not claiming comprehensive CI, independent validation or OpenAI endorsement.

Limitations and maintainer questions

This is a nesting-depth limit, not a root-owned cumulative model-turn, token, cost, wall-clock or cross-process execution budget. Application-initiated independent Runner.run() calls are outside this implementation. Further review is needed around concurrent task inheritance and resumed/persisted workflows.

  1. Would an opt-in inherited agent-tool depth limit be useful as a first-class SDK control?
  2. Or would you prefer a root-owned, cumulative execution budget with explicit checkpoint/cancellation semantics?
  3. If there is an existing supported mechanism addressing this exact delegation-depth use case, I would welcome a pointer and will revise or close the proposal.

Related but broader prior art: runtime governance discussions (e.g. #2775), and the existing per-agent max_turns feature request (#551). I did not find a directly equivalent recursive delegation-depth control in the currently indexed issues/PRs. This is offered as independently reproducible engineering research, not a claim of being the first person to explore recursive agent budgets.

Thank you for considering it.

主要语言
Python
星标
30.4k
派生
4.9k
平均合并
15 小时 42 分钟
30 天内合并 PR
124

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

openai/openai-agents-python 的其他 Issue

查看 openai/openai-agents-python 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。