google / google/adk-python

feat: Add Explicit Termination Mechanism for Multi-Agent Workflows (Similar to AutoGen "TERMINATE")

Abierto
#5,211 1 comentario 1 reacción 2 asignados Reclamado por @wyf7107 Ver en GitHub
core needs review
Lenguaje dominante
Python
Estrellas
21.5k
Forks
4k
Merge medio
1 d 14 h
PR fusionados (30 d)
37

Descripción

## Is your feature request related to a problem? Please describe.

In multi-agent workflows using ADK, agents can sometimes fall into infinite or
long-running loops during collaborative tasks. This happens especially when
orchestration depends only on message passing, with no built-in signal to
indicate that the task is completed.

Other multi-agent frameworks — for example, Microsoft's AutoGen — include
explicit termination mechanisms (e.g., `TextMentionTermination`,
`StopMessageTermination`, or custom termination callbacks) that help teams of
agents know when to gracefully stop.

In ADK today, there is no simple built-in mechanism for agents to signal "task
completed," which can lead to runaway conversations, wasted tokens, and stalled
agent workflows.

## Describe the solution you'd like

ADK should support a standardized termination mechanism that allows:

- **Agents to explicitly signal termination**, for example by producing a
special message type (like `StopMessage` in AutoGen) that ends the
conversation.
- **Teams to define termination conditions**, such as detecting a specific
keyword (`"TERMINATE"`), max message counts, function call results, token
usage, or any other customizable logic.
- **External termination control**, so applications integrating ADK can stop a
run programmatically (e.g., a UI "Stop" button).
- **Composable termination conditions**, allowing multiple rules combined with
`AND`/`OR` logic (similar to AutoGen's
`MaxMessageTermination | TextMentionTermination`).

This would give ADK parity with AutoGen's termination system and prevent
infinite loops in multi-agent workflows.

## Describe alternatives you've considered

- **Custom stop messages in agent prompts** — unreliable; agents may not follow
instructions consistently.
- **Max iterations as a safeguard** — prevents infinite loops but doesn't allow
agents to end a task early when done.
- **External timeout logic** — helps with long runs but doesn't let agents
indicate intentional completion.

None of these provide the simple, robust, and explicit termination controls that
AutoGen offers.

## Additional context

AutoGen's termination system includes the following primitives, all of which
this proposal aims to replicate in ADK:

| Condition | Description |
|---|---|
| `TextMentionTermination` | Stop when a keyword appears in content |
| `MaxMessageTermination` | Stop after N events |
| `TokenUsageTermination` | Stop when token budget is exceeded |
| `TimeoutTermination` | Stop after a wall-clock duration |
| `FunctionCallTermination` | Stop when a specific function is called |
| `ExternalTermination` | Stop on external async signal |
| `StopMessageTermination` | Stop on a special stop message type |

## Cross-repository alignment

This feature is being implemented in parallel across both ADK implementations to
keep them aligned:

- **adk-js** — Feature request: google/adk-js#29
- **adk-js** — Implementation PR (under review): google/adk-js#193
- **adk-python** — Implementation PR: https://github.com/google/adk-python/pull/5213

The goal is for both `adk-python` and `adk-js` to ship the same termination
primitives with a consistent API surface, so developers can reason about
termination the same way regardless of which SDK they use.

Guía de contribución

Abrir la guía de contribución

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.