{"record":{"id":"8ebf795f76aa4389","repo":"huggingface/smolagents","slug":"error-while-generating-output-e","errorCode":null,"errorMessage":"Error while generating output:\n{e}","messagePattern":"Error while generating output:\n(.+?)","errorType":"exception","errorClass":"AgentGenerationError","httpStatus":null,"severity":"error","filePath":"src/smolagents/agents.py","lineNumber":1325,"sourceCode":"                chat_message = agglomerate_stream_deltas(chat_message_stream_deltas)\n            else:\n                chat_message: ChatMessage = self.model.generate(\n                    input_messages,\n                    stop_sequences=[\"Observation:\", \"Calling tools:\"],\n                    tools_to_call_from=self.tools_and_managed_agents,\n                )\n                self.logger.log_markdown(\n                    content=str(chat_message.content or chat_message.raw or \"\"),\n                    title=\"Output message of the LLM:\",\n                    level=LogLevel.DEBUG,\n                )\n\n            # Record model output\n            memory_step.model_output_message = chat_message\n            memory_step.model_output = chat_message.content\n            memory_step.token_usage = chat_message.token_usage\n        except Exception as e:\n            raise AgentGenerationError(f\"Error while generating output:\\n{e}\", self.logger) from e\n\n        if chat_message.tool_calls is None or len(chat_message.tool_calls) == 0:\n            try:\n                chat_message = self.model.parse_tool_calls(chat_message)\n            except Exception as e:\n                raise AgentParsingError(f\"Error while parsing tool call from model output: {e}\", self.logger)\n        else:\n            for tool_call in chat_message.tool_calls:\n                tool_call.function.arguments = parse_json_if_needed(tool_call.function.arguments)\n        final_answer, got_final_answer = None, False\n        for output in self.process_tool_calls(chat_message, memory_step):\n            yield output\n            if isinstance(output, ToolOutput):\n                if output.is_final_answer:\n                    if len(chat_message.tool_calls) > 1:\n                        raise AgentExecutionError(\n                            \"If you want to return an answer, please do not perform any other tool calls than the final answer tool call!\",\n                            self.logger,","sourceCodeStart":1307,"sourceCodeEnd":1343,"githubUrl":"https://github.com/huggingface/smolagents/blob/30bb1161095dbae2271e6bc3cc4c219cc3897a57/src/smolagents/agents.py#L1307-L1343","documentation":"Inside ToolCallingAgent._step_stream, any exception raised by model.generate() while producing the chat completion is wrapped in AgentGenerationError. The original exception is chained (raise ... from e), so the traceback retains the root cause — typically provider API errors, auth failures, rate limits, or malformed responses.","triggerScenarios":"Running agent.run(...) / agent.step(...) with stream_outputs where self.model.generate() raises: expired API key, network timeout, 429 rate limit, or a provider returning an unexpected payload.","commonSituations":"Long agent runs that exhaust token/rate limits; invalid or missing OPENAI_API_KEY-style env vars; transient network failures to the LLM provider; provider API schema changes between library versions.","solutions":["Inspect the chained cause (`raise ... from e` — read the full traceback) to identify the underlying provider error.","Fix the root cause: valid API key, correct base_url, sufficient quota/limits.","Wrap agent.run in retry logic (e.g. tenacity) for transient 429/5xx provider errors."],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"from smolagents.exceptions import AgentGenerationError\n\ntry:\n    result = agent.run(task)\nexcept AgentGenerationError as e:\n    cause = e.__cause__  # inspect underlying provider error\n    if 'rate limit' in str(cause).lower():\n        time.sleep(30)\n        result = agent.run(task)\n    else:\n        raise","preventionTips":["Validate provider credentials and quota before starting long agent runs.","Wrap runs in retry with exponential backoff for transient provider errors.","Log e.__cause__ to distinguish provider failures from agent logic errors."],"tags":["smolagents","llm-provider","generation-failure","wrapper-exception"],"backgroundTag":"llm-api-request-failed","analyzedSha":"30bb1161095dbae2271e6bc3cc4c219cc3897a57","analyzedAt":"2026-08-28T18:52:54.169Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}