{"record":{"id":"fe78e4815d13f63d","repo":"huggingface/smolagents","slug":"stream-outputs-is-set-to-true-but-the-model-cla","errorCode":null,"errorMessage":"`stream_outputs` is set to True, but the model class implements no `generate_stream` method.","messagePattern":"`stream_outputs` is set to True, but the model class implements no `generate_stream` method\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/smolagents/agents.py","lineNumber":1254,"sourceCode":"        planning_interval: int | None = None,\n        stream_outputs: bool = False,\n        max_tool_threads: int | None = None,\n        **kwargs,\n    ):\n        prompt_templates = prompt_templates or yaml.safe_load(\n            importlib.resources.files(\"smolagents.prompts\").joinpath(\"toolcalling_agent.yaml\").read_text()\n        )\n        super().__init__(\n            tools=tools,\n            model=model,\n            prompt_templates=prompt_templates,\n            planning_interval=planning_interval,\n            **kwargs,\n        )\n        # Streaming setup\n        self.stream_outputs = stream_outputs\n        if self.stream_outputs and not hasattr(self.model, \"generate_stream\"):\n            raise ValueError(\n                \"`stream_outputs` is set to True, but the model class implements no `generate_stream` method.\"\n            )\n        # Tool calling setup\n        self.max_tool_threads = max_tool_threads\n\n    @property\n    def tools_and_managed_agents(self):\n        \"\"\"Returns a combined list of tools and managed agents.\"\"\"\n        return list(self.tools.values()) + list(self.managed_agents.values())\n\n    def initialize_system_prompt(self) -> str:\n        system_prompt = populate_template(\n            self.prompt_templates[\"system_prompt\"],\n            variables={\n                \"tools\": self.tools,\n                \"managed_agents\": self.managed_agents,\n                \"custom_instructions\": self.instructions,\n            },","sourceCodeStart":1236,"sourceCodeEnd":1272,"githubUrl":"https://github.com/huggingface/smolagents/blob/30bb1161095dbae2271e6bc3cc4c219cc3897a57/src/smolagents/agents.py#L1236-L1272","documentation":"ToolCallingAgent.__init__ validates that streaming is actually available: when stream_outputs=True, the underlying model instance must expose a generate_stream method. Base model classes (e.g. OpenAIServerModel in some versions, or custom Model subclasses) that only implement generate() cannot stream, so the constructor fails fast rather than crashing later during a run.","triggerScenarios":"Constructing ToolCallingAgent(model=..., stream_outputs=True) where the model object has no generate_stream attribute — typically a custom Model subclass or a provider implementation without streaming support.","commonSituations":"Reusing a custom model written against an older smolagents API; combining stream_outputs=True with a local/open-source model wrapper that never implemented generate_stream.","solutions":["Drop stream_outputs=True (or set it to False) if you don't strictly need token streaming.","Implement generate_stream on your custom model class, yielding ModelStreamEvent objects as in smolagents' built-in streaming models.","Switch to a model class that supports streaming (check hasattr(model, 'generate_stream') before constructing the agent)."],"exampleFix":"# before\nagent = ToolCallingAgent(model=my_custom_model, tools=[], stream_outputs=True)\n\n# after\nagent = ToolCallingAgent(model=my_custom_model, tools=[], stream_outputs=False)\n# or implement streaming:\nclass MyModel(Model):\n    def generate_stream(self, messages, stop_sequences=None, **kwargs):\n        ...  # yield content chunks","handlingStrategy":"validation","validationCode":"assert not stream_outputs or hasattr(model, 'generate_stream'), 'model cannot stream'\nagent = ToolCallingAgent(model=model, tools=tools, stream_outputs=stream_outputs)","typeGuard":"def model_supports_streaming(model) -> bool:\n    return hasattr(model, 'generate_stream') and callable(model.generate_stream)","tryCatchPattern":null,"preventionTips":["Check hasattr(model, 'generate_stream') before enabling stream_outputs.","Default stream_outputs to the model's capability, not to True unconditionally.","When writing custom models, implement generate_stream if you intend to stream."],"tags":["smolagents","streaming","model-capability","constructor-validation"],"backgroundTag":"unsupported-capability-flag","analyzedSha":"30bb1161095dbae2271e6bc3cc4c219cc3897a57","analyzedAt":"2026-08-28T18:52:54.169Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}