feat: add advisor recommendation review flow
This commit is contained in:
@@ -15,11 +15,18 @@ class AdvisorAgent(FundQueryDemoAgent):
|
||||
allowed_roles=("customer", "advisor", "operator", "admin"),
|
||||
allowed_portals=("api",),
|
||||
allowed_tools=(
|
||||
"query_fund_quote", "query_investment_goal", "analyze_portfolio",
|
||||
"query_fund_quote",
|
||||
"query_investment_goal",
|
||||
"analyze_portfolio",
|
||||
"generate_asset_allocation",
|
||||
"recommend_products",
|
||||
),
|
||||
supported_intents=(
|
||||
"fund_quote", "investment_goal", "portfolio_analysis", "asset_allocation",
|
||||
"fund_quote",
|
||||
"investment_goal",
|
||||
"portfolio_analysis",
|
||||
"asset_allocation",
|
||||
"product_recommend",
|
||||
),
|
||||
)
|
||||
|
||||
@@ -50,6 +57,14 @@ class AdvisorAgent(FundQueryDemoAgent):
|
||||
"generate_asset_allocation", {}, intent="asset_allocation", context=context
|
||||
)
|
||||
return CoreResult(text=self._describe_allocation(output))
|
||||
if (
|
||||
self._classified_intent is not None
|
||||
and self._classified_intent.intent == "product_recommend"
|
||||
):
|
||||
output = await self.call_tool(
|
||||
"recommend_products", {"limit": 3}, intent="product_recommend", context=context
|
||||
)
|
||||
return CoreResult(text=self._describe_recommendation(output))
|
||||
return await super().handle(request, context)
|
||||
|
||||
@staticmethod
|
||||
@@ -98,13 +113,33 @@ class AdvisorAgent(FundQueryDemoAgent):
|
||||
return "当前没有足够的场内基金数据生成资产配置。"
|
||||
parts = [
|
||||
f"{item.get('label', item.get('asset_class'))} {item.get('target_pct')}%"
|
||||
for item in allocation if isinstance(item, dict)
|
||||
for item in allocation
|
||||
if isinstance(item, dict)
|
||||
]
|
||||
optimization = result.get("optimization")
|
||||
dynamic = isinstance(optimization, dict) and bool(optimization.get("dynamic"))
|
||||
mode = "动态历史因子优化" if dynamic else "静态配置(历史数据覆盖不足)"
|
||||
return (
|
||||
f"资产配置分析完成({mode}):" + ",".join(parts)
|
||||
f"资产配置分析完成({mode}):"
|
||||
+ ",".join(parts)
|
||||
+ "。该结果综合考虑收益目标、最大回撤、流动性和投资期限,"
|
||||
"仅供分析参考,不构成交易指令。"
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def _describe_recommendation(result: object) -> str:
|
||||
if not isinstance(result, dict):
|
||||
return "产品推荐暂不可用,请稍后重试。"
|
||||
if result.get("status") == "profile_required":
|
||||
return "当前缺少有效风险画像,暂不能推荐产品。"
|
||||
if result.get("status") == "investment_goal_required":
|
||||
return "当前没有已确认的投资目标,暂不能推荐产品。"
|
||||
products = result.get("products")
|
||||
if not isinstance(products, list) or not products:
|
||||
return "当前没有通过适当性和证据校验的场内基金产品。"
|
||||
names = [
|
||||
f"{item.get('product_code')} {item.get('product_name')}"
|
||||
for item in products
|
||||
if isinstance(item, dict)
|
||||
]
|
||||
return "推荐分析结果:" + "、".join(names) + "。方案须经审核发布,不构成交易指令。"
|
||||
|
||||
Reference in New Issue
Block a user