--exec: a sub-agent that reaches max_iterations ends the whole run instead of handing back to its parent

Aperta
#4,947 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
55/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
go
Ambito
ai, cli

Direzione di ricerca

Start with pkg/runtime/agent_delegation.go to trace how child sessions inherit iteration and non-interactive settings, then read enforceMaxIterations in pkg/runtime/loop_steps.go and the --exec handling in pkg/cli/runner.go. Reproduce with the supplied team configuration and non-terminal stdin; confirm that a helper capped at one iteration returns control to the root, which then completes its run.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

area/agent area/cli area/runtime
Description

In docker agent run --exec, a sub-agent that reaches its max_iterations ends the whole run. Its lead never gets control back, so the lead cannot finish, summarise or report what the sub-agent did. The run exits 0.

Versions: v1.152.0 and v1.161.0, Linux, stdin not a terminal (CI or an unattended job).

Steps to reproduce

The provider is an OpenAI-compatible stub that answers with tool calls.

agents:
  root:
    model: m
    instruction: lead
    max_iterations: 20
    sub_agents: [helper]
  helper:
    model: m
    instruction: helper
    max_iterations: 1
    toolsets:
      - type: todo
  1. The root's first answer is transfer_task to helper.
  2. The helper answers with several create_todos calls, then text.
  3. Run docker agent run team.yaml --exec go </dev/null.

Result: one helper call, then

⚠️  Maximum iterations (1) reached. The agent may be stuck in a loop.
Do you want to continue for 10 more iterations? (y/n):
Failed to read input, exiting...

and exit 0. The root's next model call never happens.

With the helper at max_iterations: 0 (no cap), the helper finishes and the root gets transfer_task response → "…" as expected.

Why (from the source, v1.161.0)
  • Each transfer_task starts a child session with the sub-agent's own cap (pkg/runtime/agent_delegation.go, session.WithMaxIterations(childAgent.MaxIterations())).
  • In enforceMaxIterations (pkg/runtime/loop_steps.go), a NonInteractive session stops itself and appends "Execution stopped after reaching the configured max_iterations limit". For a sub-agent, that would return its turn to the lead.
  • The --exec CLI path never marks the session NonInteractive, and transfer_task copies the parent's value. So the MaxIterationsReachedEvent reaches the CLI runner (pkg/cli/runner.go). The runner prompts, the read fails without a terminal, and it calls rt.Resume(ResumeReject("")) and return nil, which ends the whole run.
Expected

In --exec with no terminal, a capped sub-agent stops and hands its turn back to its parent, as a NonInteractive session already does, instead of the CLI ending the run. Possible approaches:

  • mark --exec sessions NonInteractive when stdin is not a terminal;
  • or have the CLI, on a failed read, reject only the session that reached its cap.

--yolo avoids the prompt, but it also auto-approves every tool call, which an unattended run with a restricted permission set cannot accept.

Related: #4560 (the continuation increment).

Lingua principale
Go
Stelle
4.7k
Fork
565
Merge medio
18h 52m
PR unite (30g)
221

Preparare l'ambiente

Apri in Codespaces

Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.

  • Include un Dockerfile o un file Docker Compose
  • Nessun modello di pull request
  • Nessuna guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di docker/docker-agent

Tutte le issue di docker/docker-agent

Issue simili

Altre issue su Go

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.