{"record":{"id":"6194cb85329e28c8","repo":"microsoft/autogen","slug":"buffer-size-must-be-greater-than-0","errorCode":null,"errorMessage":"buffer_size must be greater than 0.","messagePattern":"buffer_size must be greater than 0\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/packages/autogen-core/src/autogen_core/model_context/_buffered_chat_completion_context.py","lineNumber":31,"sourceCode":"    initial_messages: List[LLMMessage] | None = None\n\n\nclass BufferedChatCompletionContext(ChatCompletionContext, Component[BufferedChatCompletionContextConfig]):\n    \"\"\"A buffered chat completion context that keeps a view of the last n messages,\n    where n is the buffer size. The buffer size is set at initialization.\n\n    Args:\n        buffer_size (int): The size of the buffer.\n        initial_messages (List[LLMMessage] | None): The initial messages.\n    \"\"\"\n\n    component_config_schema = BufferedChatCompletionContextConfig\n    component_provider_override = \"autogen_core.model_context.BufferedChatCompletionContext\"\n\n    def __init__(self, buffer_size: int, initial_messages: List[LLMMessage] | None = None) -> None:\n        super().__init__(initial_messages)\n        if buffer_size <= 0:\n            raise ValueError(\"buffer_size must be greater than 0.\")\n        self._buffer_size = buffer_size\n\n    async def get_messages(self) -> List[LLMMessage]:\n        \"\"\"Get at most `buffer_size` recent messages.\"\"\"\n        messages = self._messages[-self._buffer_size :]\n        # Handle the first message is a function call result message.\n        if messages and isinstance(messages[0], FunctionExecutionResultMessage):\n            # Remove the first message from the list.\n            messages = messages[1:]\n        return messages\n\n    def _to_config(self) -> BufferedChatCompletionContextConfig:\n        return BufferedChatCompletionContextConfig(\n            buffer_size=self._buffer_size, initial_messages=self._initial_messages\n        )\n\n    @classmethod\n    def _from_config(cls, config: BufferedChatCompletionContextConfig) -> Self:","sourceCodeStart":13,"sourceCodeEnd":49,"githubUrl":"https://github.com/microsoft/autogen/blob/027ecf0a379bcc1d09956d46d12d44a3ad9cee14/python/packages/autogen-core/src/autogen_core/model_context/_buffered_chat_completion_context.py#L13-L49","documentation":"BufferedChatCompletionContext keeps only the most recent buffer_size messages and rejects non-positive sizes at construction with ValueError, since a buffer of 0 (or negative) would make get_messages always return an empty list and silently starve the model of all context. This is a fail-fast configuration check on the constructor argument.","triggerScenarios":"`BufferedChatCompletionContext(buffer_size=0)`, negative values, or a computed size that evaluates to 0 (e.g. `len(something)` on an empty collection, or a config default of 0 meaning 'unlimited'). Note: there is no unlimited option — omit the context or use UnboundedChatCompletionContext for that.","commonSituations":"Config files where 0 conventionally means 'default/unlimited'; deriving buffer_size from message counts or model limits that can be 0 in edge cases; disabling buffering by passing 0.","solutions":["Pass a positive integer: `BufferedChatCompletionContext(buffer_size=10)`.","If 0 in your config means unlimited, use UnboundedChatCompletionContext instead of mapping it to buffer_size.","Clamp computed values: `buffer_size=max(1, computed)` when the source can legitimately be 0."],"exampleFix":"# before\ncontext = BufferedChatCompletionContext(buffer_size=0)  # ValueError\n\n# after\nfrom autogen_core.model_context import UnboundedChatCompletionContext\ncontext = UnboundedChatCompletionContext()  # if '0' meant unlimited\n# or: BufferedChatCompletionContext(buffer_size=10)","handlingStrategy":"validation","validationCode":"buffer_size = int(cfg.get(\"buffer_size\", 10))\nif buffer_size <= 0:\n    raise ValueError(\"buffer_size must be > 0; use UnboundedChatCompletionContext for unlimited\")","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Treat 0 in config as 'unbounded' and map it to UnboundedChatCompletionContext explicitly.","Clamp computed sizes with max(1, value)."],"tags":["python","autogen-core","model-context","configuration","validation"],"backgroundTag":null,"analyzedSha":"027ecf0a379bcc1d09956d46d12d44a3ad9cee14","analyzedAt":"2026-08-15T03:38:00.719Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}