microsoft/autogen · error · ValueError
At least one of max_total_token, max_prompt_token, or max_co
Error message
At least one of max_total_token, max_prompt_token, or max_completion_token must be provided
What it means
TokenUsageTermination's constructor requires at least one token budget: max_total_token, max_prompt_token, or max_completion_token. Constructing it with no arguments (all None) raises ValueError immediately — it is a usage error, not a runtime state error.
Source
Thrown at python/packages/autogen-agentchat/src/autogen_agentchat/conditions/_terminations.py:257
max_total_token: The maximum total number of tokens allowed in the conversation.
max_prompt_token: The maximum number of prompt tokens allowed in the conversation.
max_completion_token: The maximum number of completion tokens allowed in the conversation.
Raises:
ValueError: If none of max_total_token, max_prompt_token, or max_completion_token is provided.
"""
component_config_schema = TokenUsageTerminationConfig
component_provider_override = "autogen_agentchat.conditions.TokenUsageTermination"
def __init__(
self,
max_total_token: int | None = None,
max_prompt_token: int | None = None,
max_completion_token: int | None = None,
) -> None:
if max_total_token is None and max_prompt_token is None and max_completion_token is None:
raise ValueError(
"At least one of max_total_token, max_prompt_token, or max_completion_token must be provided"
)
self._max_total_token = max_total_token
self._max_prompt_token = max_prompt_token
self._max_completion_token = max_completion_token
self._total_token_count = 0
self._prompt_token_count = 0
self._completion_token_count = 0
@property
def terminated(self) -> bool:
return (
(self._max_total_token is not None and self._total_token_count >= self._max_total_token)
or (self._max_prompt_token is not None and self._prompt_token_count >= self._max_prompt_token)
or (self._max_completion_token is not None and self._completion_token_count >= self._max_completion_token)
)
async def __call__(self, messages: Sequence[BaseAgentEvent | BaseChatMessage]) -> StopMessage | None:View on GitHub (pinned to 027ecf0a37)
Solutions
- Pass at least one limit, e.g. TokenUsageTermination(max_total_token=3000)
- Check parameter spelling: max_total_token / max_prompt_token / max_completion_token (singular 'token')
- Validate config payloads before constructing: require at least one non-None budget key
Example fix
# before cond = TokenUsageTermination() # ValueError # after cond = TokenUsageTermination(max_total_token=3000)
Defensive patterns
Strategy: validation
Validate before calling
budget = {"max_total_token": cfg.get("max_total_token"),
"max_prompt_token": cfg.get("max_prompt_token"),
"max_completion_token": cfg.get("max_completion_token")}
if all(v is None for v in budget.values()):
raise ValueError("config must set at least one token budget") Prevention
- Always pass at least one budget when constructing TokenUsageTermination
- Use exact parameter names (singular 'token')
- Validate config schemas before constructing conditions
When it happens
Trigger: TokenUsageTermination() with empty parentheses; passing budgets as keyword arguments with typos (max_total_tokens with trailing 's') so all real parameters stay None; building conditions from config where the budget fields are missing.
Common situations: Copy-pasting from examples that show a budget and then stripping it; config-driven condition construction where the limits key is absent or misnamed.
Related errors
- Unsupported config type {config.GetType()}
- Messages should not be provided in options
- The agent name must be a valid Python identifier.
- model_client.model_info must be provided when max_retries_on
- Specified model_client doesn't support structured output mod
AI-assisted analysis of microsoft/autogen@027ecf0a37 (2026-08-15).
Data as JSON: /api/errors/4d3bbaac01b808be.
Report an issue: GitHub.