datawhalechina/hello-agents · error · WorkflowExecutionError
需求文本不能超过 {MAX_REQUIREMENT_LENGTH} 个字符
Error message
需求文本不能超过 {MAX_REQUIREMENT_LENGTH} 个字符 What it means
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.
Source
Thrown at Co-creation-projects/zenith191-RequirementClarifierAgent/src/workflow.py:123
@staticmethod
def save_report(result: WorkflowResult, output_path: str | Path) -> Path:
"""以 UTF-8 保存最终 Markdown 报告。"""
path = Path(output_path)
path.parent.mkdir(parents=True, exist_ok=True)
path.write_text(result.report.rstrip() + "\n", encoding="utf-8")
return path
@staticmethod
def _validate_requirement(requirement: str) -> str:
if not isinstance(requirement, str):
raise WorkflowExecutionError("需求必须是字符串")
requirement = requirement.strip()
if not requirement:
raise WorkflowExecutionError("需求不能为空")
if len(requirement) > MAX_REQUIREMENT_LENGTH:
raise WorkflowExecutionError(
f"需求文本不能超过 {MAX_REQUIREMENT_LENGTH} 个字符"
)
return requirement
@staticmethod
def _run_agent(stage: str, agent: AgentLike, prompt: str) -> str:
try:
response = agent.run(prompt)
except Exception as exc:
raise WorkflowExecutionError(f"{stage}阶段执行失败:{exc}") from exc
if not isinstance(response, str) or not response.strip():
raise WorkflowExecutionError(f"{stage}阶段返回了空结果")
return response.strip()
def _run_tool(
self, name: str, parameters: dict[str, object], stage: str
) -> dict[str, object]:
"""通过官方 ToolRegistry 获取工具并解析其字符串协议。"""View on GitHub (pinned to 606a07d341)
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.
Example fix
# before
result = workflow.run(open('big_spec.md').read())
# after
text = open('big_spec.md').read()
result = workflow.run(text[:MAX_REQUIREMENT_LENGTH]) Defensive patterns
Strategy: validation
Validate before calling
from src.workflow import MAX_REQUIREMENT_LENGTH # or read from the error message
if len(requirement.strip()) > MAX_REQUIREMENT_LENGTH:
requirement = requirement.strip()[:MAX_REQUIREMENT_LENGTH]
# or reject: raise ValueError(f"max {MAX_REQUIREMENT_LENGTH} chars")
result = workflow.run(requirement) Type guard
def within_length_limit(v: str, limit: int) -> bool:
return isinstance(v, str) and 0 < len(v.strip()) <= limit Try / catch
try:
result = workflow.run(requirement)
except WorkflowExecutionError as e:
if "不能超过" in str(e):
raise HTTPException(413, "requirement too long — split into sections")
raise Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
AI-assisted analysis of datawhalechina/hello-agents@606a07d341 (2026-08-14).
Data as JSON: /api/errors/0df6a14be08cf861.
Report an issue: GitHub.