huggingface/smolagents · error · ValueError

`stream_outputs` is set to True, but the model class impleme

Error message

`stream_outputs` is set to True, but the model class implements no `generate_stream` method.

What it means

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.

Source

Thrown at src/smolagents/agents.py:1254

        planning_interval: int | None = None,
        stream_outputs: bool = False,
        max_tool_threads: int | None = None,
        **kwargs,
    ):
        prompt_templates = prompt_templates or yaml.safe_load(
            importlib.resources.files("smolagents.prompts").joinpath("toolcalling_agent.yaml").read_text()
        )
        super().__init__(
            tools=tools,
            model=model,
            prompt_templates=prompt_templates,
            planning_interval=planning_interval,
            **kwargs,
        )
        # Streaming setup
        self.stream_outputs = stream_outputs
        if self.stream_outputs and not hasattr(self.model, "generate_stream"):
            raise ValueError(
                "`stream_outputs` is set to True, but the model class implements no `generate_stream` method."
            )
        # Tool calling setup
        self.max_tool_threads = max_tool_threads

    @property
    def tools_and_managed_agents(self):
        """Returns a combined list of tools and managed agents."""
        return list(self.tools.values()) + list(self.managed_agents.values())

    def initialize_system_prompt(self) -> str:
        system_prompt = populate_template(
            self.prompt_templates["system_prompt"],
            variables={
                "tools": self.tools,
                "managed_agents": self.managed_agents,
                "custom_instructions": self.instructions,
            },

View on GitHub (pinned to 30bb116109)

Solutions

  1. Drop stream_outputs=True (or set it to False) if you don't strictly need token streaming.
  2. Implement generate_stream on your custom model class, yielding ModelStreamEvent objects as in smolagents' built-in streaming models.
  3. Switch to a model class that supports streaming (check hasattr(model, 'generate_stream') before constructing the agent).

Example fix

# before
agent = ToolCallingAgent(model=my_custom_model, tools=[], stream_outputs=True)

# after
agent = ToolCallingAgent(model=my_custom_model, tools=[], stream_outputs=False)
# or implement streaming:
class MyModel(Model):
    def generate_stream(self, messages, stop_sequences=None, **kwargs):
        ...  # yield content chunks
Defensive patterns

Strategy: validation

Validate before calling

assert not stream_outputs or hasattr(model, 'generate_stream'), 'model cannot stream'
agent = ToolCallingAgent(model=model, tools=tools, stream_outputs=stream_outputs)

Type guard

def model_supports_streaming(model) -> bool:
    return hasattr(model, 'generate_stream') and callable(model.generate_stream)

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of huggingface/smolagents@30bb116109 (2026-08-28). Data as JSON: /api/errors/fe78e4815d13f63d. Report an issue: GitHub.