feat: migrate advisor investment goals
This commit is contained in:
@@ -7,6 +7,7 @@ from sqlalchemy.ext.asyncio import AsyncSession
|
||||
from app.core.config import get_settings
|
||||
from app.core.errors import RecoverableAgentError
|
||||
from app.core.fund_contracts import FundQuoteQuery
|
||||
from app.core.investment_goal_contracts import InvestmentGoalQuery
|
||||
from app.infrastructure.fund_quote_cache import FundQuoteCache
|
||||
from app.infrastructure.memory_cache import MemoryCacheAdapter
|
||||
from app.infrastructure.vector_memory import VectorMemoryAdapter
|
||||
@@ -16,6 +17,7 @@ from app.service.agent.implementations.advisor import AdvisorAgent
|
||||
from app.service.agent.implementations.fund_query_demo import FundQueryDemoAgent
|
||||
from app.service.fund_quote_service import query_fund_quote_tool
|
||||
from app.service.intent_classifier import IntentClassifier
|
||||
from app.service.investment_goal_service import investment_goal_query_tool
|
||||
from app.service.memory_recall_service import MemoryRecallService
|
||||
from app.service.model_gateway import (
|
||||
DatabaseModelEndpointResolver,
|
||||
@@ -144,6 +146,13 @@ def get_agent_factory() -> AgentFactory:
|
||||
# (12s)与重试预算,多代码查询必然先撞工具超时。
|
||||
timeout_seconds=15,
|
||||
))
|
||||
registry.register(ToolDefinition(
|
||||
name="query_investment_goal",
|
||||
input_model=InvestmentGoalQuery,
|
||||
handler=cast(Any, investment_goal_query_tool),
|
||||
required_permission="investment-goal:read:self",
|
||||
allowed_roles=("customer", "advisor", "operator", "admin"),
|
||||
))
|
||||
model_service = get_model_service()
|
||||
endpoint_resolver = DatabaseModelEndpointResolver()
|
||||
factory = AgentFactory(
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
"""投顾 Agent 的迁移骨架。
|
||||
"""投顾 Agent 的公共底座实现。"""
|
||||
|
||||
当前阶段只接入新底座已有的场内基金行情只读能力;后续业务模块会按迁移 TODO
|
||||
逐项扩展 definition、工具白名单和处理逻辑。
|
||||
"""
|
||||
from typing import Any
|
||||
|
||||
from app.core.contracts import AgentDefinition
|
||||
from app.core.contracts import AgentDefinition, AgentRequest, CoreResult, RequestContext
|
||||
from app.service.agent.implementations.fund_query_demo import FundQueryDemoAgent
|
||||
|
||||
|
||||
@@ -16,6 +14,29 @@ class AdvisorAgent(FundQueryDemoAgent):
|
||||
version="0.1.0",
|
||||
allowed_roles=("customer", "advisor", "operator", "admin"),
|
||||
allowed_portals=("api",),
|
||||
allowed_tools=("query_fund_quote",),
|
||||
supported_intents=("fund_quote",),
|
||||
allowed_tools=("query_fund_quote", "query_investment_goal"),
|
||||
supported_intents=("fund_quote", "investment_goal"),
|
||||
)
|
||||
|
||||
async def handle(self, request: AgentRequest, context: RequestContext) -> CoreResult:
|
||||
if (
|
||||
self._classified_intent is not None
|
||||
and self._classified_intent.intent == "investment_goal"
|
||||
):
|
||||
output = await self.call_tool(
|
||||
"query_investment_goal", {}, intent="investment_goal", context=context
|
||||
)
|
||||
if not isinstance(output, dict):
|
||||
return CoreResult(text="当前没有已确认的投资目标,暂不能用于配置或产品推荐。")
|
||||
return CoreResult(text=self._describe_goal(output))
|
||||
return await super().handle(request, context)
|
||||
|
||||
@staticmethod
|
||||
def _describe_goal(goal: dict[str, Any]) -> str:
|
||||
return (
|
||||
f"当前投资目标:年化收益目标 {goal['annualized_return_lower_pct']}%-"
|
||||
f"{goal['annualized_return_upper_pct']}%,最大回撤 {goal['max_drawdown_pct']}%,"
|
||||
f"流动性要求 {goal['liquidity_requirement']},投资期限 "
|
||||
f"{goal['investment_horizon_months']} 个月,业绩比较基准 {goal['benchmark_name']}。"
|
||||
"以上为目标采集结果,不构成收益承诺或交易指令。"
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user