袁聪的最后一次完善更新

This commit is contained in:
2026-09-14 18:13:10 +08:00
parent 54055b4328
commit 2548c39c6b
50 changed files with 2818 additions and 267 deletions
@@ -0,0 +1,38 @@
"""金融 NL2SQL 业务 Agent。"""
from typing import Any, cast
from app.core.contracts import AgentDefinition, AgentRequest, CoreResult, RequestContext
from app.service.agent.base import BaseAgent
TOOL_NAME = "query_financial_data"
INTENTS = ("financial_query", "general")
class FinancialNL2SQLAgent(BaseAgent):
"""把通用金融问题交给公共金融只读查询工具处理。"""
definition = AgentDefinition(
agent_type="financial_nl2sql",
version="1.0.0",
allowed_roles=("advisor", "operator", "admin", "super_admin"),
allowed_portals=("api",),
allowed_tools=(TOOL_NAME,),
supported_intents=INTENTS,
# 查询工具自身带有确定性规划与澄清机制,不需要依赖模型意图分类端点。
requires_model_intent_classification=False,
)
async def handle(self, request: AgentRequest, context: RequestContext) -> CoreResult:
result = cast(dict[str, Any], await self.call_tool(
TOOL_NAME,
{"question": request.message, "dry_run": False, "limit": 50},
intent="financial_query",
context=context,
))
data = result.get("data")
return CoreResult(
text=str(result.get("message", "金融查询未返回结果")),
data=data if isinstance(data, dict) else {},
sql=result.get("sql") if isinstance(result.get("sql"), str) else None,
)