microsoft/autogen · error · TerminatedException
Termination condition has already been reached.
Error message
Termination condition has already been reached.
What it means
StopMessageTermination terminates when it sees a StopMessage in the batch. Once _terminated is set, any further call raises TerminatedException. Reset clears the flag.
Source
Thrown at python/packages/autogen-agentchat/src/autogen_agentchat/conditions/_terminations.py:39
pass
class StopMessageTermination(TerminationCondition, Component[StopMessageTerminationConfig]):
"""Terminate the conversation if a StopMessage is received."""
component_config_schema = StopMessageTerminationConfig
component_provider_override = "autogen_agentchat.conditions.StopMessageTermination"
def __init__(self) -> None:
self._terminated = False
@property
def terminated(self) -> bool:
return self._terminated
async def __call__(self, messages: Sequence[BaseAgentEvent | BaseChatMessage]) -> StopMessage | None:
if self._terminated:
raise TerminatedException("Termination condition has already been reached")
for message in messages:
if isinstance(message, StopMessage):
self._terminated = True
return StopMessage(content="Stop message received", source="StopMessageTermination")
return None
async def reset(self) -> None:
self._terminated = False
def _to_config(self) -> StopMessageTerminationConfig:
return StopMessageTerminationConfig()
@classmethod
def _from_config(cls, config: StopMessageTerminationConfig) -> Self:
return cls()
class MaxMessageTerminationConfig(BaseModel):View on GitHub (pinned to 027ecf0a37)
Solutions
- Check condition.terminated before calling
- await condition.reset() / await team.reset() between runs
- In custom loops, break out of iteration immediately once a StopMessage is returned
Example fix
# before result = await team.run(task=t1) result = await team.run(task=t2) # StopMessageTermination still terminated # after await team.reset() result = await team.run(task=t2)
Defensive patterns
Strategy: validation
Validate before calling
if not cond.terminated:
stop = await cond(messages) Try / catch
from autogen_agentchat.conditions import TerminatedException
try:
stop = await cond(messages)
except TerminatedException:
await cond.reset()
stop = await cond(messages) Prevention
- Reset teams/conditions between runs
- Break your orchestration loop as soon as a StopMessage is produced
- Check .terminated before calling
When it happens
Trigger: A StopMessage appeared in a previous batch (e.g. emitted by a handoff-aware agent or another termination source inside a team), then the condition is evaluated again — typically a second team.run() without reset, or the StopMessage-producing agent and this condition wired into an And composite that is re-invoked.
Common situations: Teams where agents emit StopMessage for early exit; reusing a one-shot condition across runs; inspecting conditions by calling them in custom orchestration code.
Related errors
- Termination condition has already been reached.
- Termination condition has already been reached
- At least one of max_total_token, max_prompt_token, or max_co
- Handoff name must be a string: {values['name']}
- Handoff name must be a valid identifier: {values['name']}
AI-assisted analysis of microsoft/autogen@027ecf0a37 (2026-08-15).
Data as JSON: /api/errors/eb90972fdc5a2b07.
Report an issue: GitHub.