feat(application-form-fill): 接入自动填表工作流触发

This commit is contained in:
2026-06-07 18:26:37 +08:00
parent e48d44f832
commit 8694f2d43e
6 changed files with 511 additions and 9 deletions

View File

@@ -8,6 +8,7 @@ from .file_summary.workflow_trigger import (
evaluate_attachment_reader_trigger,
evaluate_file_summary_trigger,
)
from .application_form_fill.constants import FORM_FILL_TRIGGER_KEYWORDS, WORKFLOW_TYPE as FORM_FILL_WORKFLOW_TYPE
from .llm import LLMConfigurationError, LLMRequestError, generate_completion
from .models import Conversation, FileAttachment
@@ -16,6 +17,7 @@ logger = logging.getLogger(__name__)
ROUTE_ACTIONS = {"normal_chat", "attachment_reader", "file_summary"}
ROUTE_ACTIONS.add("regulatory_review")
ROUTE_ACTIONS.add(FORM_FILL_WORKFLOW_TYPE)
@dataclass(frozen=True)
@@ -39,6 +41,10 @@ class SkillRoute:
def starts_regulatory_review(self) -> bool:
return self.action == "regulatory_review"
@property
def starts_application_form_fill(self) -> bool:
return self.action == FORM_FILL_WORKFLOW_TYPE
@property
def is_normal_chat(self) -> bool:
return self.action == "normal_chat"
@@ -105,7 +111,7 @@ def _route_with_llm(
return SkillRoute(
action=action,
skill_name="attachment_reader" if action == "attachment_reader" else "",
workflow_type=action if action in {"file_summary", "regulatory_review"} else "",
workflow_type=action if action in {"file_summary", "regulatory_review", FORM_FILL_WORKFLOW_TYPE} else "",
confidence=_float_or_zero(payload.get("confidence")),
reason=str(payload.get("reason") or ""),
source="llm",
@@ -113,6 +119,15 @@ def _route_with_llm(
def _route_with_rules(conversation: Conversation, content: str) -> SkillRoute:
if _matches_application_form_fill(content):
return SkillRoute(
action=FORM_FILL_WORKFLOW_TYPE,
workflow_type=FORM_FILL_WORKFLOW_TYPE,
confidence=0.7,
reason="命中申报文件自动填表关键词。",
source="rule_fallback",
)
if _matches_regulatory_review(content):
return SkillRoute(
action="regulatory_review",
@@ -162,10 +177,11 @@ def _router_system_prompt() -> str:
return (
"你是审核智能体的工具路由器,只判断是否需要调用工具,不直接回答用户。"
"你必须只输出 JSON 对象,不要输出 Markdown。"
"可选 actionnormal_chat、attachment_reader、file_summary、regulatory_review。"
"可选 actionnormal_chat、attachment_reader、file_summary、regulatory_review、application_form_fill"
"attachment_reader 用于用户要求阅读、提取、分析、总结、查看上传附件内容。"
"file_summary 用于用户要求自动汇总文件目录、页数、清单或生成目录页数报告。"
"regulatory_review 用于用户要求法规核查、NMPA核查、完整性核查、章节一致性核查、风险预警或整改建议。"
"application_form_fill 用于用户要求填注册证、生成申报模板、填写对应表格、安全和性能基本原则清单或自动填表。"
"normal_chat 用于不需要读取附件或执行工作流的一般问答。"
"输出字段action、confidence、reason。"
)
@@ -217,3 +233,8 @@ def _matches_regulatory_review(content: str) -> bool:
"一致性核查",
]
return any(keyword in normalized for keyword in keywords)
def _matches_application_form_fill(content: str) -> bool:
normalized = content.lower()
return any(keyword.lower() in normalized for keyword in FORM_FILL_TRIGGER_KEYWORDS)