fix: per-node max_tokens + validation 502 guard + correct_jrxml output validity

- backend/llm.py: per-node max_tokens via get_llm(max_tokens=N), LLM_MAX_TOKENS env var (default 8192)
- agent/nodes.py: 5 generation nodes use max_tokens=32768, generate_skeleton retries at 65536
- agent/nodes.py: fix ns:field regex (<field → <[\w:]*field) to handle namespace prefixes
- agent/nodes.py: fix correct_jrxml never writing back to state["current_jrxml"]
- agent/nodes.py: correct_jrxml rejects non-JRXML output (no <jasperReport tag)
- agent/nodes.py: _strip_continuation_wrapper strips markdown/prefixes from continuation rounds
- agent/nodes.py: _extract_jrxml iterates multiple markdown code blocks, skips fragments
- agent/graph.py: route_after_validate skips correction loop when service_unavailable
- agent/graph.py: route_after_save skips validation for empty JRXML
- backend/validation.py: returns service_unavailable: True for ConnectError and HTTP 5xx
- Docs: CLAUDE.md v14 changelog, README.md LLM_MAX_TOKENS, .env.example LLM_MAX_TOKENS
This commit is contained in:
2026-05-24 15:20:25 +08:00
parent e362f530ea
commit 4e14334030
8 changed files with 388 additions and 32 deletions
+10 -1
View File
@@ -120,6 +120,9 @@ def route_after_save(state: AgentState) -> Literal["validate", "finalize"]:
intent = state.get("intent", "")
if intent in ("preview_report", "export_pdf", "export_jrxml"):
return "finalize"
# JRXML 为空时跳过验证/修正循环(生成失败等场景)
if not state.get("current_jrxml", "").strip():
return "finalize"
return "validate"
@@ -127,6 +130,12 @@ def route_after_save(state: AgentState) -> Literal["validate", "finalize"]:
def route_after_validate(state: AgentState) -> Literal["finalize", "explain_error"]:
if state.get("status") == "pass":
return "finalize"
# JRXML 为空时跳过 explain→correct 修正循环
if not state.get("current_jrxml", "").strip():
return "finalize"
# 验证服务不可用时跳过修正循环,避免对网络错误进行无效修正
if state.get("service_unavailable"):
return "finalize"
return "explain_error"
@@ -256,7 +265,7 @@ def build_graph(on_node_start=None) -> StateGraph:
workflow.add_conditional_edges(
"save_session",
route_after_save,
{"validate": "validate"},
{"validate": "validate", "finalize": "finalize"},
)
# ---- 验证 → 修正循环 ----