feat: add dynamic advisor asset allocation

This commit is contained in:
Windows
2026-09-11 14:44:29 +08:00
parent 8ffd08b4ce
commit ff71a1a724
15 changed files with 652 additions and 22 deletions
+42 -2
View File
@@ -14,8 +14,13 @@ class AdvisorAgent(FundQueryDemoAgent):
version="0.1.0",
allowed_roles=("customer", "advisor", "operator", "admin"),
allowed_portals=("api",),
allowed_tools=("query_fund_quote", "query_investment_goal", "analyze_portfolio"),
supported_intents=("fund_quote", "investment_goal", "portfolio_analysis"),
allowed_tools=(
"query_fund_quote", "query_investment_goal", "analyze_portfolio",
"generate_asset_allocation",
),
supported_intents=(
"fund_quote", "investment_goal", "portfolio_analysis", "asset_allocation",
),
)
async def handle(self, request: AgentRequest, context: RequestContext) -> CoreResult:
@@ -37,6 +42,14 @@ class AdvisorAgent(FundQueryDemoAgent):
"analyze_portfolio", {}, intent="portfolio_analysis", context=context
)
return CoreResult(text=self._describe_portfolio(output))
if (
self._classified_intent is not None
and self._classified_intent.intent == "asset_allocation"
):
output = await self.call_tool(
"generate_asset_allocation", {}, intent="asset_allocation", context=context
)
return CoreResult(text=self._describe_allocation(output))
return await super().handle(request, context)
@staticmethod
@@ -68,3 +81,30 @@ class AdvisorAgent(FundQueryDemoAgent):
f"总市值 {summary.get('total_market_value')},产品集中度 HHI 为 {hhi}。"
"分析结果仅供参考,不生成交易指令。"
)
@staticmethod
def _describe_allocation(result: object) -> str:
if not isinstance(result, dict):
return "资产配置分析暂不可用,请稍后重试。"
status = result.get("status")
if status == "profile_required":
return "当前缺少有效风险画像,暂不能生成资产配置。"
if status == "investment_goal_required":
return "当前没有已确认的投资目标,暂不能生成资产配置。"
if status != "ready":
return "资产配置分析数据不完整,请稍后重试。"
allocation = result.get("allocation")
if not isinstance(allocation, list) or not allocation:
return "当前没有足够的场内基金数据生成资产配置。"
parts = [
f"{item.get('label', item.get('asset_class'))} {item.get('target_pct')}%"
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)
+ "。该结果综合考虑收益目标、最大回撤、流动性和投资期限,"
"仅供分析参考,不构成交易指令。"
)