{"record":{"id":"b41277f731b35301","repo":"jd-opensource/joyagent-jdgenie","slug":"error-in-generating-model-output-e","errorCode":null,"errorMessage":"Error in generating model output:\n{e}","messagePattern":"Error in generating model output:\n(.+?)","errorType":"exception","errorClass":"AgentGenerationError","httpStatus":null,"severity":"error","filePath":"genie-tool/genie_tool/tool/ci_agent.py","lineNumber":126,"sourceCode":"            self.logger.log_markdown(\n                content=output_text,\n                title=\"Output message of the LLM:\",\n                level=LogLevel.DEBUG,\n            )\n            memory_step.model_output_message = chat_message\n            output_text = chat_message.content\n\n            # This adds <end_code> sequence to the history.\n            # This will nudge ulterior LLM calls to finish with <end_code>, thus efficiently stopping generation.\n            if output_text and output_text.strip().endswith(\"```\"):\n                output_text += \"<end_code>\"\n                memory_step.model_output_message.content = output_text\n\n            memory_step.model_output = output_text\n            # This put call was missing await\n\n        except Exception as e:\n            raise AgentGenerationError(\n                f\"Error in generating model output:\\n{e}\", self.logger\n            ) from e\n\n        self.logger.log_markdown(\n            content=output_text,\n            title=\"Output message of the LLM:\",\n            level=LogLevel.DEBUG,\n        )\n\n        # Parse\n        try:\n            code_action = fix_final_answer_code(parse_code_blobs(output_text))\n        except Exception as e:\n            error_msg = (\n                f\"Error in code parsing:\\n{e}\\nMake sure to provide correct code blobs.\"\n            )\n            raise AgentParsingError(error_msg, self.logger)\n","sourceCodeStart":108,"sourceCodeEnd":144,"githubUrl":"https://github.com/jd-opensource/joyagent-jdgenie/blob/2417e0b8b636d941ad5fb14c59b20dddfef5375d/genie-tool/genie_tool/tool/ci_agent.py#L108-L144","documentation":"`_step_stream` in the CI agent raises `AgentGenerationError` when the LLM generation step fails for any reason (API error, malformed streaming response, serialization of model output). The original exception is chained via `from e`, so this is a wrapper around the model-call failure.","triggerScenarios":"The agent's generation step calls the model API and the model call or output handling throws — e.g. provider API error, invalid API key, context length exceeded, rate limit, or broken stream.","commonSituations":"Expired or wrong model provider API key; model name unavailable; prompt exceeding context window; transient provider outages; network drops mid-stream.","solutions":["Inspect the chained cause (`e.__cause__`) for the provider error detail (auth, rate limit, context length)","Validate the model provider API key and model name configuration","Reduce prompt/context size if the cause indicates a token-limit error","Add retry with backoff for transient provider/network failures"],"exampleFix":"// before\nagent.run(task)  # opaque AgentGenerationError on failure\n// after\ntry:\n    agent.run(task)\nexcept AgentGenerationError as e:\n    logger.error(f\"root cause: {e.__cause__}\")\n    if is_transient(e.__cause__):\n        retry_with_backoff()\n    raise","handlingStrategy":"try-catch","validationCode":"assert os.environ.get(\"MODEL_API_KEY\"), \"model provider API key missing\"\nassert len(prompt_tokens) < model_context_limit, \"prompt exceeds context window\"","typeGuard":"def provider_ready(cfg) -> bool:\n    return bool(cfg.api_key) and cfg.model_name in SUPPORTED_MODELS","tryCatchPattern":"try:\n    result = agent.run(task)\nexcept AgentGenerationError as e:\n    cause = e.__cause__\n    if is_rate_limit(cause) or is_transient(cause):\n        result = retry_with_backoff(lambda: agent.run(task))\n    else:\n        raise","preventionTips":["Validate provider API key and model name before running the agent","Monitor token counts to stay under the context window","Add retry/backoff for transient provider errors and alert on repeated generation failures"],"tags":["llm","agent","generation"],"backgroundTag":"upstream-api-error","analyzedSha":"2417e0b8b636d941ad5fb14c59b20dddfef5375d","analyzedAt":"2026-09-08T11:28:19.414Z","contentChangedAt":"2026-09-08T11:28:19.414Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}