{"record":{"id":"4d3bbaac01b808be","repo":"microsoft/autogen","slug":"at-least-one-of-max-total-token-max-prompt-token","errorCode":null,"errorMessage":"At least one of max_total_token, max_prompt_token, or max_completion_token must be provided","messagePattern":"At least one of max_total_token, max_prompt_token, or max_completion_token must be provided","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/packages/autogen-agentchat/src/autogen_agentchat/conditions/_terminations.py","lineNumber":257,"sourceCode":"        max_total_token: The maximum total number of tokens allowed in the conversation.\n        max_prompt_token: The maximum number of prompt tokens allowed in the conversation.\n        max_completion_token: The maximum number of completion tokens allowed in the conversation.\n\n    Raises:\n        ValueError: If none of max_total_token, max_prompt_token, or max_completion_token is provided.\n    \"\"\"\n\n    component_config_schema = TokenUsageTerminationConfig\n    component_provider_override = \"autogen_agentchat.conditions.TokenUsageTermination\"\n\n    def __init__(\n        self,\n        max_total_token: int | None = None,\n        max_prompt_token: int | None = None,\n        max_completion_token: int | None = None,\n    ) -> None:\n        if max_total_token is None and max_prompt_token is None and max_completion_token is None:\n            raise ValueError(\n                \"At least one of max_total_token, max_prompt_token, or max_completion_token must be provided\"\n            )\n        self._max_total_token = max_total_token\n        self._max_prompt_token = max_prompt_token\n        self._max_completion_token = max_completion_token\n        self._total_token_count = 0\n        self._prompt_token_count = 0\n        self._completion_token_count = 0\n\n    @property\n    def terminated(self) -> bool:\n        return (\n            (self._max_total_token is not None and self._total_token_count >= self._max_total_token)\n            or (self._max_prompt_token is not None and self._prompt_token_count >= self._max_prompt_token)\n            or (self._max_completion_token is not None and self._completion_token_count >= self._max_completion_token)\n        )\n\n    async def __call__(self, messages: Sequence[BaseAgentEvent | BaseChatMessage]) -> StopMessage | None:","sourceCodeStart":239,"sourceCodeEnd":275,"githubUrl":"https://github.com/microsoft/autogen/blob/027ecf0a379bcc1d09956d46d12d44a3ad9cee14/python/packages/autogen-agentchat/src/autogen_agentchat/conditions/_terminations.py#L239-L275","documentation":"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.","triggerScenarios":"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.","commonSituations":"Copy-pasting from examples that show a budget and then stripping it; config-driven condition construction where the limits key is absent or misnamed.","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"],"exampleFix":"# before\ncond = TokenUsageTermination()  # ValueError\n\n# after\ncond = TokenUsageTermination(max_total_token=3000)","handlingStrategy":"validation","validationCode":"budget = {\"max_total_token\": cfg.get(\"max_total_token\"),\n         \"max_prompt_token\": cfg.get(\"max_prompt_token\"),\n         \"max_completion_token\": cfg.get(\"max_completion_token\")}\nif all(v is None for v in budget.values()):\n    raise ValueError(\"config must set at least one token budget\")","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always pass at least one budget when constructing TokenUsageTermination","Use exact parameter names (singular 'token')","Validate config schemas before constructing conditions"],"tags":["termination","token-usage","constructor","validation","agentchat"],"backgroundTag":null,"analyzedSha":"027ecf0a379bcc1d09956d46d12d44a3ad9cee14","analyzedAt":"2026-08-15T03:38:00.719Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}