본문으로 건너뛰기

서브 시약 위임

anchor alias

서브 시약 위임

delegate_task 도구는 격리된 컨텍스트, 제한 도구 및 자체 터미널 세션을 가진 아이 AIAgent 인스턴스를 낳습니다. 각 아이는 신선한 대화를 얻고 독립적으로 작동합니다. - 최종 요약 만 부모의 맥락을 입력합니다.

단일 작업

delegate_task(
goal="Debug why tests fail",
context="Error: assertion in test_foo.py line 42",
toolsets=["terminal", "file"]
)

평행한 배치

기본적으로 3개의 동시 subagents까지 (configurable, 단단한 천장 없음):

delegate_task(tasks=[
{"goal": "Research topic A", "toolsets": ["web"]},
{"goal": "Research topic B", "toolsets": ["web"]},
{"goal": "Fix the build", "toolsets": ["terminal", "file"]}
])

Subagent 컨텍스트 작동 방법

Critical: Subagents Know Nothing {#how-subagent-context-works}

Subagents는 완전 신선한 대화로 시작합니다. 그들은 부모의 대화 역사, 사전 도구 통화, 또는 위임 전에 논의 된 것들의 0 지식이 있습니다. 하위 시약의 유일한 컨텍스트는 goal컨텍스트 필드에서 모회사가 delegate_task를 호출할 때 나타납니다.

이것은 부모 에이전트가 everything 호출의 하위 시약 요구 사항을 통과해야합니다.

# BAD - subagent has no idea what "the error" is
delegate_task(goal="Fix the error")

# GOOD - subagent has all context it needs
delegate_task(
goal="Fix the TypeError in api/handlers.py",
context="""The file api/handlers.py has a TypeError on line 47:
'NoneType' object has no attribute 'get'.
The function process_request() receives a dict from parse_body(),
but parse_body() returns None when Content-Type is missing.
The project is at /home/user/myproject and uses Python 3.11."""
)

하위 시약은 목표와 컨텍스트에서 구축 된 집중된 시스템 프롬프트를 수신하고 작업을 완료하고 그것이 무엇인지의 구조화 된 요약을 제공, 그것이 발견 된 어떤 파일, 수정 된 모든 문제.

Practical 예제

병렬 연구

동시에 여러 주제를 연구하고 요약을 수집:

delegate_task(tasks=[
{
"goal": "Research the current state of WebAssembly in 2025",
"context": "Focus on: browser support, non-browser runtimes, language support",
"toolsets": ["web"]
},
{
"goal": "Research the current state of RISC-V adoption in 2025",
"context": "Focus on: server chips, embedded systems, software ecosystem",
"toolsets": ["web"]
},
{
"goal": "Research quantum computing progress in 2025",
"context": "Focus on: error correction breakthroughs, practical applications, key players",
"toolsets": ["web"]
}
])

코드 검토 + 수정

검토 및 수정 워크플로를 신선한 컨텍스트로 불러옵니다:

delegate_task(
goal="Review the authentication module for security issues and fix any found",
context="""Project at /home/user/webapp.
Auth module files: src/auth/login.py, src/auth/jwt.py, src/auth/middleware.py.
The project uses Flask, PyJWT, and bcrypt.
Focus on: SQL injection, JWT validation, password handling, session management.
Fix any issues found and run the test suite (pytest tests/auth/).""",
toolsets=["terminal", "file"]
)

다중 파일 Refactoring

부모의 컨텍스트를 홍수시키는 큰 재발견 작업:

delegate_task(
goal="Refactor all Python files in src/ to replace print() with proper logging",
context="""Project at /home/user/myproject.
Use the 'logging' module with logger = logging.getLogger(__name__).
Replace print() calls with appropriate log levels:
- print(f"Error:...") -> logger.error(...)
- print(f"Warning:...") -> logger.warning(...)
- print(f"Debug:...") -> logger.debug(...)
- Other prints -> logger.info(...)
Don't change print() in test files or CLI output.
Run pytest after to verify nothing broke.""",
toolsets=["terminal", "file"]
)

일괄 모드 세부 사항

tasks 배열을 제공 할 때 스레드 풀을 사용하여 parallel에서 하위 시약 실행:

  • 최대 통화: 기본적으로 3개의 작업 (delegation.max_concurrent_children 또는 DELEGATION_MAX_CONCURRENT_CHILDREN env var를 통해 구성 가능; 1 층, 단단한 천장 없음). 제한보다 큰 배치는 침묵적으로 truncated보다 도구 오류를 반환합니다.
  • 스레드 풀: ThreadPoolExecutor를 사용하여 구성된 통화 제한을 최대 노동자로 사용합니다
  • ** 표시:** CLI 모드에서, 트리뷰는 per-task 완료 라인과 실시간 각 하위 시약에서 도구 통화를 보여줍니다. 게이트웨이 모드에서 진행은 부모의 진행 콜백에 배치되고 릴레이됩니다
  • 결과 주문: 결과는 완료 순서에 관계없이 입력 순서를 일치하기 위하여 작업 색인에 의해 분류됩니다
  • 분쟁: 부모(예를 들어, 새 메시지를 보내)를 방해하는 모든 활성 어린이

Single-task delegation는 실 수영장 오버 헤드 없이 직접 실행됩니다.

모델 Override

config.yaml를 통해 하위 시약에 대한 다른 모델을 구성할 수 있습니다. 간단한 작업을 더 저렴하고 빠르게 모델에 위임하는 데 유용합니다

# In ~/.hermes/config.yaml
delegation:
model: "google/gemini-flash-2.0" # Cheaper model for subagents
provider: "openrouter" # Optional: route subagents to a different provider

omitted 경우, subagents는 부모와 동일한 모델을 사용합니다.

Toolset 선택 팁

toolsets 매개 변수는 하위 시약이 접근하는 것을 제어합니다. 작업을 기반으로 선택하세요

Toolset 패턴사용 사례
["terminal", "file"]Code work, debugging, 파일 편집, 빌드
["web"]연구, 사실 검사, 문서 보기
["terminal", "file", "web"]Full-stack 작업 (과태)
["file"]읽기 전용 분석, 실행하지 않고 코드 검토
["terminal"]시스템 관리, 공정 관리

특정 도구는 지정한 내용에 관계없이 하위 시약에 대해 차단됩니다

  • delegation - 잎 시약에 대한 차단 (기본값). role="orchestrator" 아이들은 max_spawn_depth에 의해 묶여 Depth Limit and Nested Orchestration를 아래에서 볼 수 있습니다.
  • clarify - 시약은 사용자와 상호 작용할 수 없습니다
  • memory - 영구 기억을 공유하는 쓰기
  • code_execution - 아이들은 단계별
  • send_message - 크로스 플랫폼 부작용 없음 (예: Telegram 메시지 보내기)

최대 Iterations

각 시약에는 이탈 한계가 있습니다 (과태: 50) 많은 공구 외침이 그것을 가지고 가는 방법을 통제하는:

delegate_task(
goal="Quick file check",
context="Check if /etc/nginx/nginx.conf exists and print its first 10 lines",
max_iterations=10 # Simple task, don't need many turns
)

아이 타임아웃

시약은 delegation.child_timeout_seconds 벽시 초 이상에 조용히 갈 경우 갇혀있다. 기본값은 600 (10 분) - 비 트리 바이알 연구 작업에 고밀도 모델 때문에 이전 릴리스에서 300 s에서 범퍼. Tune 그것 per-install:

delegation:
child_timeout_seconds: 600 # default

빠른 국부적으로 모델을 위해 그것을 낮추십시오; 단단한 문제에 느린 reasoning 모델을 위해 그것을 올리십시오. 타이머는 아이가 API 호출 또는 도구 호출을 만들 때마다 재설정합니다. 정품 idle 노동자는 죽을 것입니다.

Diagnostic dump on zero-call timeout

** zero** API 호출 (보통: 제공자의 부정적, auth 실패, 또는 도구 - schema 거부)를 한 후 delegate_task~/.hermes/logs/subagent-timeout-<session>-<timestamp>.log에 구조화된 진단을 씁니다. 이전의 침묵 운동 행동보다 훨씬 쉽게.

모니터링 실행 시약 (/agents)

TUI는 /agents 오버레이 (alias /tasks)를 재발견하는 delegate_task 팬 아웃을 일류 감사 표면으로 발송합니다

  • 런닝의 라이브 트리보기 및 최근 완성 된 시약, 부모 그룹
  • Per-branch 비용, 토큰 및 파일 터치 롤업
  • Kill and pause controls — siblings를 중단하지 않고 특정 시약 중간 기쁨을 취소
  • Post-hoc 검토: 각 하위 시약의 회전에 의한 역사를 통해 단계는 부모에 반환 한 후

고전적인 CLI는 텍스트 요약으로 /agents를 인쇄합니다. TUI는 오버레이 빛이 어디에 있습니다. TUI - 슬래시 명령를 참조하세요.

깊이 한계와 둥지가 되는 Orchestration

기본적으로, 위임은 flat: 부모 (깊은 0) 스파드 어린이 (깊은 1), 그리고 그 아이들은 더 delegate 할 수 없습니다. 이 런웨이 recursive 위임을 방지합니다.

다단계 워크플로우(research → 종합, 또는 하위 프로블럼에 평행한 오케스트라션)의 경우, 부모는 spawnorchestrator 아이들이 자신의 노동자를 delegate 할 수 있습니다

delegate_task(
goal="Survey three code review approaches and recommend one",
role="orchestrator", # Allows this child to spawn its own workers
context="...",
)
  • role="leaf" (과태): 아이는 평평한 위임 행동과 동일하지 않습니다.
  • role="orchestrator": 아이는 delegation 툴릿을 유지합니다. delegation.max_spawn_depth (기본 1 = 평평한, 그래서 role="orchestrator"는 기본값에서 노점입니다). max_spawn_depth 를 2로 올리며 관현관 아이들이 종족 잎을 웅장하게 할 수 있도록 합니다. 3단계(캡).
  • delegation.orchestrator_enabled: false: leaf에 대한 모든 아이를 강제하는 글로벌 킬 스위치.

** 경고:** max_spawn_depth: 3max_concurrent_children: 3로 나무는 3×3×3 = 27 동시 잎 에이전트에 도달 할 수 있습니다. 각 추가 레벨 다변화 지출 — 상승 max_spawn_depth 의도적으로.

일생과 내구성

delegate_task is synchronous — not durable {#lifetime-and-durability}

delegate_task부모의 현재 턴 옆에 있습니다. 모든 아이가 끝날 때까지 부모를 차단합니다 (또는 취소됩니다). 그것은 아니다 배경 작업 큐:

  • 부모가 중단되면 (사용자는 새로운 메시지를 보내, /stop, /new), 모든 활성 어린이가 취소하고 반환 status="interrupted". 그들의 in-progress 일은 discarded.
  • 아이들은 ** 부모가 종료 후 계속 실행되지 않습니다.
  • 취소 된 아이들은 구조화 된 결과를 반환 (status="interrupted", exit_reason="interrupted"), 그러나 부모가 너무 중단했기 때문에, 그 결과 종종 사용자 접근 가능한 대답으로 만들 수 없습니다.

durable long-running work는 중단하거나 현재 턴을 능숙해야 합니다

  • cronjob (action=create) - 별도의 에이전트 실행을 계획합니다. 면역은 부모의 회전 중단을 방해합니다.
  • terminal(background=True, notify_on_complete=True) - 에이전트가 다른 일을 수행하는 동안 실행되는 긴 실행 쉘 명령.

키 속성

  • 각 시약은 단말 세션 (모자에서 계산)
  • Nested delegation is opt-in — only role="orchestrator" children can delegate more, and only when __HMES_TOKEN_00001__는 1 (flat)의 기본으로 제기됩니다. orchestrator_enabled: false로 전 세계적으로 사용 가능.
  • 잎 시약 ** 전화: delegate_task, clarify, memory, send_message, execute_code. Orchestrator subagents 유지 delegate_task 하지만 여전히 다른 4를 사용할 수 없습니다.
  • Interrupt propagation - 부모는 모든 활성 어린이를 중단 (오케스트라의 할머니 포함)
  • 최종 요약은 부모의 컨텍스트를 입력하고, 토큰 사용량을 효율적으로 유지
  • Subagents는 부모의 **API 키, 제공자 구성 및 자격 풀 ** (요금 제한에 열쇠 교체를 활성화)

위임 vs run_code

기준delegate_taskexecute_code
추론전체 LLM reasoning loopPython 코드 실행만
컨텍스트새롭고 격리된 대화대화 없음, 스크립트만
도구 접근차단되지 않은 모든 도구 + reasoningRPC를 통한 제한된 도구, reasoning 없음
병렬성기본 3개 동시 subagent(설정 가능)단일 스크립트
적합한 작업판단이 필요한 복잡한 작업기계적인 다단계 파이프라인
토큰 비용높은 (풀 LLM 루프)낮은 (만 stdout 반환)
사용자 상호작용없음(subagent는 clarification을 요청할 수 없음)없음

엄지: delegate_task를 사용하여 하위 작업이 이유, 판단, 또는 다중 단계 문제 해결이 필요합니다. 사용 execute_code 당신은 기계 데이터 처리 또는 스크립트 작업 흐름을 필요로 할 때.

제품 설명

# In ~/.hermes/config.yaml
delegation:
max_iterations: 50 # Max turns per child (default: 50)
# max_concurrent_children: 3 # Parallel children per batch (default: 3)
# max_spawn_depth: 1 # Tree depth (1-3, default 1 = flat). Raise to 2 to allow orchestrator children to spawn leaves; 3 for three levels.
# orchestrator_enabled: true # Disable to force all children to leaf role.
model: "google/gemini-3-flash-preview" # Optional provider/model override
provider: "openrouter" # Optional built-in provider

# Or use a direct custom endpoint instead of provider:
delegation:
model: "qwen2.5-coder"
base_url: "http://localhost:1234/v1"
api_key: "local-key"

에이전트는 작업 복잡성을 기반으로 위임을 자동으로 처리합니다. 명시적으로 delegate에 요청할 필요가 없습니다. 그렇게 할 것입니다.