datawhalechina/hello-agents · error · ValueError
无法从输出解析 note_id: {output}
Error message
无法从输出解析 note_id:
{output} What it means
outline_agent.py duplicates the extract_note_id helper: it regex-parses NoteTool output for r"ID:\s*(note_[0-9_]+)" and raises ValueError when the pattern is absent. For OutlineAgent this usually happens on the very first tool call of a run (outline creation), so the whole outline-generation flow aborts before any chapter work starts. Root cause is always the same: the text handed to the parser does not contain a parsable note-id line.
Source
Thrown at Co-creation-projects/lgs-only-NovelGenerator/agents/outline_agent.py:14
from dotenv import load_dotenv
load_dotenv()
from hello_agents import SimpleAgent, HelloAgentsLLM
from hello_agents.tools import NoteTool
from prompt import OUTLINE_PROMPT
import re
import os
def extract_note_id(output: str) -> str:
"""从 NoteTool 的输出文本中提取 note_id"""
match = re.search(r"ID:\s*(note_[0-9_]+)", output)
if not match:
raise ValueError(f"无法从输出解析 note_id:\n{output}")
return match.group(1)
class OutlineAgent(SimpleAgent):
"""小说大纲生成Agent"""
def __init__(self, name: str, llm: HelloAgentsLLM = HelloAgentsLLM(), **kwargs):
self.workspace = kwargs.pop("workspace", "./outputs")
super().__init__(name=name, llm=llm)
self.outline_length = 3000
self.note_tools = {}
def _ensure_tool(self, novel_id: str, title: str = None):
if not self.note_tools.get(novel_id):
if not title:
raise ValueError(f"Tool for novel_id {novel_id} not initialized and title not provided.")
self.note_tools[novel_id] = NoteTool(workspace=os.path.join(self.workspace, f"{title}-{novel_id}", 'outline'))
View on GitHub (pinned to 606a07d341)
Solutions
- Log the raw NoteTool output right before parsing to identify whether it is an error message or a format change.
- Ensure the note backend works: workspace directory exists and is writable, novel_id valid, NoteTool importable and initialized.
- Relax the regex to tolerate label/case/colon variations: r"(?:ID|note_id)\s*[::]?\s*(note_[0-9A-Za-z_-]+)" with re.IGNORECASE.
- Deduplicate: import one shared extract_note_id from a common module instead of the copies in outline_agent.py and chapter_generate_agent.py so a format fix lands everywhere at once.
- Pin hello-agents==<tested version> in requirements.
Example fix
# before match = re.search(r"ID:\s*(note_[0-9_]+)", output) # after match = re.search(r"(?:ID|note_id)\s*[::]?\s*(note_[0-9A-Za-z_-]+)", output, re.IGNORECASE)
Defensive patterns
Strategy: try-catch
Validate before calling
import re
NOTE_ID_RE = re.compile(r"ID:\s*(note_[0-9_]+)")
if not NOTE_ID_RE.search(tool_output):
raise RuntimeError(f"outline creation produced no note id: {tool_output!r}") Type guard
import re
from typing import Optional
def try_extract_note_id(output: str) -> Optional[str]:
m = re.search(r"ID:\s*(note_[0-9_]+)", output)
return m.group(1) if m else None Try / catch
try:
note_id = extract_note_id(output)
except ValueError as e:
# surface the tool output for diagnosis, then abort or retry generation
logger.exception("outline note_id extraction failed")
raise Prevention
- Deduplicate extract_note_id into one shared module
- Verify the note store is writable before generation runs
- Test the regex against a recorded NoteTool output snapshot
When it happens
Trigger: OutlineAgent.generate() captures the SimpleAgent transcript and the NoteTool output line with 'ID: note_...' is missing because creation failed; running against a different hello_agents version whose NoteTool format changed; the note id uses characters outside [0-9_]; output was localized (e.g. full-width ':' colon) so the regex misses.
Common situations: New environment where the note store is not writable (./outputs permissions); hello-agents upgraded between writing and running the agent; team shares prompts but not the pinned library version; empty workspace passed to OutlineAgent so NoteTool errors out.
Related errors
- 无法从输出解析 note_id: {output}
- Patch must start with '*** Begin Patch'
- Patch must end with '*** End Patch'
- 无法从输出解析 note_id: {output}
- 模型响应中没有完整的 JSON 对象
AI-assisted analysis of datawhalechina/hello-agents@606a07d341 (2026-08-14).
Data as JSON: /api/errors/4e78d0f116db86b2.
Report an issue: GitHub.