{"record":{"id":"0df6a14be08cf861","repo":"datawhalechina/hello-agents","slug":"max-requirement-length","errorCode":null,"errorMessage":"需求文本不能超过 {MAX_REQUIREMENT_LENGTH} 个字符","messagePattern":"需求文本不能超过 (.+?) 个字符","errorType":"exception","errorClass":"WorkflowExecutionError","httpStatus":null,"severity":"error","filePath":"Co-creation-projects/zenith191-RequirementClarifierAgent/src/workflow.py","lineNumber":123,"sourceCode":"\n    @staticmethod\n    def save_report(result: WorkflowResult, output_path: str | Path) -> Path:\n        \"\"\"以 UTF-8 保存最终 Markdown 报告。\"\"\"\n\n        path = Path(output_path)\n        path.parent.mkdir(parents=True, exist_ok=True)\n        path.write_text(result.report.rstrip() + \"\\n\", encoding=\"utf-8\")\n        return path\n\n    @staticmethod\n    def _validate_requirement(requirement: str) -> str:\n        if not isinstance(requirement, str):\n            raise WorkflowExecutionError(\"需求必须是字符串\")\n        requirement = requirement.strip()\n        if not requirement:\n            raise WorkflowExecutionError(\"需求不能为空\")\n        if len(requirement) > MAX_REQUIREMENT_LENGTH:\n            raise WorkflowExecutionError(\n                f\"需求文本不能超过 {MAX_REQUIREMENT_LENGTH} 个字符\"\n            )\n        return requirement\n\n    @staticmethod\n    def _run_agent(stage: str, agent: AgentLike, prompt: str) -> str:\n        try:\n            response = agent.run(prompt)\n        except Exception as exc:\n            raise WorkflowExecutionError(f\"{stage}阶段执行失败：{exc}\") from exc\n        if not isinstance(response, str) or not response.strip():\n            raise WorkflowExecutionError(f\"{stage}阶段返回了空结果\")\n        return response.strip()\n\n    def _run_tool(\n        self, name: str, parameters: dict[str, object], stage: str\n    ) -> dict[str, object]:\n        \"\"\"通过官方 ToolRegistry 获取工具并解析其字符串协议。\"\"\"","sourceCodeStart":105,"sourceCodeEnd":141,"githubUrl":"https://github.com/datawhalechina/hello-agents/blob/606a07d341a47be773fab7f4b71177f53f96b2c3/Co-creation-projects/zenith191-RequirementClarifierAgent/src/workflow.py#L105-L141","documentation":"Raised by _validate_requirement when the stripped requirement exceeds MAX_REQUIREMENT_LENGTH characters. The cap bounds prompt size and cost per run. The message interpolates the actual constant, so the limit in force is always stated in the error itself.","triggerScenarios":"Passing a full RFC/document/paste-dump as the requirement; concatenating many smaller requirements into one call; feeding a log file instead of a one-line requirement statement.","commonSituations":"Users paste entire spec documents; automated pipelines forward unbounded upstream text; the limit differs between versions so previously-working long inputs start failing after upgrade.","solutions":["Shorten the requirement to a concise statement under the limit stated in the message.","Split large documents into sections and run the workflow per section, merging reports afterward.","Pre-truncate or summarize long input programmatically before calling run() if completeness matters less than throughput."],"exampleFix":"# before\nresult = workflow.run(open('big_spec.md').read())\n\n# after\ntext = open('big_spec.md').read()\nresult = workflow.run(text[:MAX_REQUIREMENT_LENGTH])","handlingStrategy":"validation","validationCode":"from src.workflow import MAX_REQUIREMENT_LENGTH  # or read from the error message\n\nif len(requirement.strip()) > MAX_REQUIREMENT_LENGTH:\n    requirement = requirement.strip()[:MAX_REQUIREMENT_LENGTH]\n    # or reject: raise ValueError(f\"max {MAX_REQUIREMENT_LENGTH} chars\")\nresult = workflow.run(requirement)","typeGuard":"def within_length_limit(v: str, limit: int) -> bool:\n    return isinstance(v, str) and 0 < len(v.strip()) <= limit","tryCatchPattern":"try:\n    result = workflow.run(requirement)\nexcept WorkflowExecutionError as e:\n    if \"不能超过\" in str(e):\n        raise HTTPException(413, \"requirement too long — split into sections\")\n    raise","preventionTips":["Set a client-side maxlength matching MAX_REQUIREMENT_LENGTH.","Show a live character counter on long-input UIs.","For documents, summarize or chunk before invoking the workflow."],"tags":["python","validation","input-length","workflow"],"backgroundTag":null,"analyzedSha":"606a07d341a47be773fab7f4b71177f53f96b2c3","analyzedAt":"2026-08-14T22:57:27.446Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}