# Agent Delegation Depth／Recursion Guard

CURRENT_STATUS: CURRENT
OBSERVATION: SPEC_ONLY
FRESHNESS: CURRENT
PAGE_TYPE: reference
CANONICAL_URL: /tools/ea-507-agent-delegation-depth-recursion-guard
CLAIM_IDS: none
EVIDENCE_IDS: EVD-EA-507-URL-29F3AE8BBEDF, EVD-EA-507-URL-E22D8FCD6264, EVD-EA-507-URL-9F9EAB85F625, EVD-EA-507-URL-6984F18D1DFE, EVD-EA-507-URL-FD0584E42BD2, EA-507-CURRENT-APPROVAL, EA-507-CURRENT-BODY-READBACK
UNKNOWN_IDS: EA-507-UNKNOWN-01
OPS_IDS: none

## Summary
「max turnsを設定すれば再帰問題は解決する」「A2Aがdelegation cycleを防止する」とは断定しません。安全な表現は、「agent delegationにはdepth、fan-out、turn/tool/cost/deadline、cycle/no-progress、side-effectを別々のbudgetとして持たせ、root operationからchildへ残量を継承し、機械的terminationとcancellation/reconciliationを設ける。frameworkのmax-turn機能はその一部であり、remote agent内部やbusiness side effectまで自動保証するものではない」です。

## Current judgment
「max turnsを設定すれば再帰問題は解決する」「A2Aがdelegation cycleを防止する」とは断定しません。安全な表現は、「agent delegationにはdepth、fan-out、turn/tool/cost/deadline、cycle/no-progress、side-effectを別々のbudgetとして持たせ、root operationからchildへ残量を継承し、機械的terminationとcancellation/reconciliationを設ける。frameworkのmax-turn機能はその一部であり、remote agent内部やbusiness side effectまで自動保証するものではない」です。

## Scope
Agent Delegation Depth／Recursion Guard

## Confirmed

## UNKNOWN
- EA-507-UNKNOWN-01: - 対象業務で許容すべき最大delegation depth、fan-out、total turns、tool calls、wall-clockの値。
- subgoal fingerprintをどの粒度で同一と判定すべきか。
- remote A2A agentが内部delegation budgetを受け入れ、強制できる標準的な方法。
- parent cancellation後にremote childが継続した場合のreconciliation/compensation契約。
- token/cost budgetとside-effect risk budgetを同一root contextでどう整合させるか。
- human-in-the-loopの待機時間をdeadline budgetへ含めるか除外するか。

## Evidence
- EVD-EA-507-URL-29F3AE8BBEDF (RESEARCH): OpenAI Agents SDK Python Runner, accessed 2026-10-21: — https://openai.github.io/openai-agents-python/ja/ref/run/
- EVD-EA-507-URL-E22D8FCD6264 (RESEARCH): OpenAI Agents SDK JavaScript Running Agents, accessed 2026-10-21: — https://openai.github.io/openai-agents-js/guides/running-agents/
- EVD-EA-507-URL-9F9EAB85F625 (RESEARCH): Microsoft Agent Framework Handoff orchestration, accessed 2026-10-21: — https://learn.microsoft.com/en-us/agent-framework/user-guide/workflows/orchestrations/handoff
- EVD-EA-507-URL-6984F18D1DFE (RESEARCH): A2A Protocol v1.0.1 specification, accessed 2026-10-21: — https://a2a-protocol.org/v1.0.1/specification/
- EVD-EA-507-URL-FD0584E42BD2 (RESEARCH): A2A Protocol v1.0.1 specification, accessed 2026-10-21: — https://a2a-protocol.org/
- EA-507-CURRENT-APPROVAL (RESEARCH): 現行本文の監査・revision対応
- EA-507-CURRENT-BODY-READBACK (IMPL): 現行本文の収録照合

## Failure / limits
### Handoff cycle

handoff graphにA→BとB→Aが許可されていると、model判断だけで相互移譲を反復する可能性があります。各handoffがschema上validでも、goal progressが無ければloopです。agent名だけでなく、`(source_agent, target_agent, task_fingerprint)` の反復や、同一subgoalの再委譲を検出します。

### Depthだけでは止まらない

最大depth=3でも、各階層で多数のsiblingsを生成できればfan-outでwork量は増えます。逆に総turn数だけを制限すると、正当な深いworkflowを早期停止することがあります。depth、total delegations、concurrent children、model turns、tool calls、tokens/cost、wall-clockを別budgetとして扱います。

### Budget reset

親から子へ委譲するときに子が新しいrunとして初期budgetを得る設計では、再帰的委譲で上限を迂回できます。root operationのbudgetをauthoritativeに持ち、childへ「残量」を継承します。child local limitとroot global limitを分離し、より厳しい方で停止します。

### Cancellation propagation

親runがdeadlineやbudget超過で停止しても、既にremote agentやtoolへ送ったtaskが継続する場合があります。停止条件は新規delegation禁止だけでなく、outstanding childのcancel要求、結果無視、reconciliation、必要なcompensationまで含めます。cancel requestedをexternal effect canceledと同一視しません。

### Hidden recursion

A2Aのようなopaque remote agentでは、remote側が内部で何段sub-agentを使ったかclientから見えないことがあります。client側の「depth=1」はremote内部の計算量を意味しません。契約できるのは自分が発行するremote task数、deadline、quota、cost、response size等の観測可能な境界です。
## Failure / limits
厳しいdepth/turn上限はrunawayを止めますが、長い正当workflowも切断します。固定値を安全性の唯一基準にすると、複雑なincident response、調査、承認workflowでfalse terminationが増えます。budget exhaustionを単なるerrorではなく、partial-result返却やhuman escalationへ接続する必要があります。

cycleは常に異常ではありません。reviewer→author→reviewerの反復や、triage→specialist→triageのhandoffは正当な反復です。cycle detectionは「同じnodeを再訪した」だけでなく、progress、subgoal、iteration count、termination criteriaを考慮します。

remote agentがopaqueな場合、client側budgetはremote内部computeを直接制限できません。provider quota、deadline、billing cap、contract、remote側policyが必要です。
## 要点と前提
Agentが別Agentへ仕事を委譲できる構成では、個々のhandoffが正当でも、A→B→A、A→B→C→Aのようなcycleや、sub-agentがさらにsub-agentを生成する連鎖によって、turn数・token・tool call・外部副作用・待ち時間が上限なく増えることがあります。対策は単一の「再帰回数」だけではなく、run全体へ伝播するdelegation budget、visited-edge/cycle detection、per-agent turn limit、wall-clock/deadline、side-effect budget、明示的termination conditionを組み合わせることです。

## 主要claim
OpenAI Agents SDKのRunnerは、final outputが出るまでagent invocation、handoff、tool callをloopし、`max_turns` でrunの最大turn数を制限できます。現行Python SDK文書ではturnを1回のAI invocationとして定義し、上限超過時は `MaxTurnsExceeded` になります。JavaScript SDKも `maxTurns` を安全上の上限として持ちます。これは無限loopを止める実装上のguardですが、handoff depthそのもの、外部API call数、token/cost、business side effect数を個別に保証する契約ではありません。

Microsoft Agent Frameworkのhandoff orchestrationは、agent間のhandoff ruleを明示でき、autonomous modeではtermination conditionまたはper-agent turn limitまで継続します。現行文書ではautonomous modeにper-agent turn limitがあり、defaultは各agent 50 autonomous turnsです。したがってframeworkがloop guardを持つ例はありますが、複数agentを跨ぐ総delegation budgetやbusiness-side-effect budgetは別途設計する必要があります。

A2Aはagent間のinteroperabilityとtask lifecycleを定義し、agentが別agentへtaskを委譲・協調できる通信層です。一方、公式文書はA2Aをsub-agent/tool-call protocolではないと明記しています。したがってA2Aを使うだけで内部delegation depth、cycle、budget propagationが自動的に制御されるとは扱いません。

## 運用上の意味・failure
### Handoff cycle

handoff graphにA→BとB→Aが許可されていると、model判断だけで相互移譲を反復する可能性があります。各handoffがschema上validでも、goal progressが無ければloopです。agent名だけでなく、`(source_agent, target_agent, task_fingerprint)` の反復や、同一subgoalの再委譲を検出します。

### Depthだけでは止まらない

最大depth=3でも、各階層で多数のsiblingsを生成できればfan-outでwork量は増えます。逆に総turn数だけを制限すると、正当な深いworkflowを早期停止することがあります。depth、total delegations、concurrent children、model turns、tool calls、tokens/cost、wall-clockを別budgetとして扱います。

### Budget reset

親から子へ委譲するときに子が新しいrunとして初期budgetを得る設計では、再帰的委譲で上限を迂回できます。root operationのbudgetをauthoritativeに持ち、childへ「残量」を継承します。child local limitとroot global limitを分離し、より厳しい方で停止します。

### Cancellation propagation

親runがdeadlineやbudget超過で停止しても、既にremote agentやtoolへ送ったtaskが継続する場合があります。停止条件は新規delegation禁止だけでなく、outstanding childのcancel要求、結果無視、reconciliation、必要なcompensationまで含めます。cancel requestedをexternal effect canceledと同一視しません。

### Hidden recursion

A2Aのようなopaque remote agentでは、remote側が内部で何段sub-agentを使ったかclientから見えないことがあります。client側の「depth=1」はremote内部の計算量を意味しません。契約できるのは自分が発行するremote task数、deadline、quota、cost、response size等の観測可能な境界です。

## 具体的control / implementation implication
### 1. Root delegation context

root operationに次を持たせ、handoff/subtask作成時に継承します。

- `root_operation_id`
- `parent_operation_id`
- `delegation_depth`
- `delegations_used / delegations_limit`
- `model_turns_used / model_turns_limit`
- `tool_calls_used / tool_calls_limit`
- `concurrent_children / child_limit`
- `deadline_at`
- `token_or_cost_budget`
- `side_effect_budget`
- `visited_delegation_edges` またはcycle-detection用fingerprint

framework固有のcontext object、workflow state、durable store等へ置けますが、childが勝手にbudgetを再初期化できないauthoritative sourceを持たせます。

### 2. Pre-delegation gate

新しいhandoff/subtaskを作る直前に、depth、残budget、deadline、同時child数、cycle、target allowlist、side-effect riskを判定します。上限超過時は「別agentへ投げ直す」のではなく、現在までの結果をまとめる、human escalationへ送る、bounded failureとして終了する、のいずれかへ遷移します。

### 3. Cycle detection

単純なagent-name visited setだけでは、A→B→Aでも別subgoalなら正当な場合があります。最低でもagent edgeとtask/subgoal fingerprintを組み合わせ、同一目的の反復を検出します。false positiveを避けるため、cycle検出時に即failureとせず、残budget、progress signal、成果差分を併用できます。

### 4. Termination condition

「モデルが終了を選ぶ」以外に機械的terminationを持たせます。例として、max turns、deadline、budget exhaustion、no-progress count、duplicate subgoal、required artifact completion、human approval待ち等があります。Microsoft Agent Frameworkのautonomous handoffがtermination conditionとper-agent turn limitを持つこと、OpenAI Agents SDKがmax turnsを持つことは、この種のguardをruntimeへ置く具体例です。

### 5. Side-effect separation

read-only調査Agentとwrite/action Agentでbudgetを分けます。多数のdelegationを許しても、payment/send/delete/deploy等の不可逆または高risk actionは別のapproval・idempotency・quotaを要求します。delegation budgetはside-effect safetyの代替ではありません。

### 6. Observability

少なくともroot operationごとに、handoff graph、depth、fan-out、turns、tool calls、elapsed time、cost/token、termination reason、cycle-detection hit、outstanding childを記録します。p95/p99のdepth・delegation countと、budget exhaustion率、同一edge反復、cancel後残存childを監視します。

### 7. Evaluation

正常系だけでなく、A↔B ping-pong、三角cycle、fan-out爆発、child budget reset、remote timeout、parent cancel後のchild継続、同一subgoal表現ゆれを含むfailure testを作ります。上限到達時に新しい副作用が発生しないこと、partial resultまたは明示的failureへ収束することを確認します。

## 適用境界
OpenAI Agents SDKの `max_turns` / `maxTurns` はSDK run loopの上限です。これを「delegation depth上限」「tool call総数上限」「cost上限」と読み替えません。SDK versionやlanguage implementationでdefaultやerror handlingは変わり得るため、利用versionの文書を固定します。

Microsoft Agent Frameworkのper-agent turn limitはhandoff autonomous modeの具体的runtime behaviorであり、他frameworkへ一般化しません。またper-agent limitはroot全体のglobal budgetと同義ではありません。

A2Aはremote agent間のtask/message protocolです。remote agent内部のsub-agent recursionをclientが完全観測できるとは限りません。protocol task ID、state、cancel等で見える範囲と、remote implementation内部を分離します。

## Counterevidence / limitations
厳しいdepth/turn上限はrunawayを止めますが、長い正当workflowも切断します。固定値を安全性の唯一基準にすると、複雑なincident response、調査、承認workflowでfalse terminationが増えます。budget exhaustionを単なるerrorではなく、partial-result返却やhuman escalationへ接続する必要があります。

cycleは常に異常ではありません。reviewer→author→reviewerの反復や、triage→specialist→triageのhandoffは正当な反復です。cycle detectionは「同じnodeを再訪した」だけでなく、progress、subgoal、iteration count、termination criteriaを考慮します。

remote agentがopaqueな場合、client側budgetはremote内部computeを直接制限できません。provider quota、deadline、billing cap、contract、remote側policyが必要です。

## OPEN_UNKNOWN
- 対象業務で許容すべき最大delegation depth、fan-out、total turns、tool calls、wall-clockの値。
- subgoal fingerprintをどの粒度で同一と判定すべきか。
- remote A2A agentが内部delegation budgetを受け入れ、強制できる標準的な方法。
- parent cancellation後にremote childが継続した場合のreconciliation/compensation契約。
- token/cost budgetとside-effect risk budgetを同一root contextでどう整合させるか。
- human-in-the-loopの待機時間をdeadline budgetへ含めるか除外するか。

## SAFE_WORDING
「max turnsを設定すれば再帰問題は解決する」「A2Aがdelegation cycleを防止する」とは断定しません。安全な表現は、「agent delegationにはdepth、fan-out、turn/tool/cost/deadline、cycle/no-progress、side-effectを別々のbudgetとして持たせ、root operationからchildへ残量を継承し、機械的terminationとcancellation/reconciliationを設ける。frameworkのmax-turn機能はその一部であり、remote agent内部やbusiness side effectまで自動保証するものではない」です。

## Source / provenance locators
- OpenAI Agents SDK Python Runner, accessed 2026-10-21: https://openai.github.io/openai-agents-python/ja/ref/run/
- OpenAI Agents SDK JavaScript Running Agents, accessed 2026-10-21: https://openai.github.io/openai-agents-js/guides/running-agents/
- Microsoft Agent Framework Handoff orchestration, accessed 2026-10-21: https://learn.microsoft.com/en-us/agent-framework/user-guide/workflows/orchestrations/handoff
- A2A Protocol v1.0.1 specification, accessed 2026-10-21: https://a2a-protocol.org/v1.0.1/specification/
- A2A Protocol overview / framework boundary, accessed 2026-10-21: https://a2a-protocol.org/

NEXT: /agent/start.json
STOP: This is a knowledge projection, not an execution order.