Spaces:
Running
Running
Fin-DataPilot Deploy Bot commited on
Commit ·
36ef4c6
1
Parent(s): 6533267
ci: 9e3ea65
Browse files- app/agent/nodes/planner.py +13 -1
- app/agent/skill_necessity.py +10 -3
app/agent/nodes/planner.py
CHANGED
|
@@ -30,6 +30,7 @@ from langchain_core.messages import HumanMessage, SystemMessage
|
|
| 30 |
from app.agent.skill_necessity import (
|
| 31 |
is_direct_financial_data_query,
|
| 32 |
is_skill_necessary_for_query,
|
|
|
|
| 33 |
required_vertical_skills_for_query,
|
| 34 |
)
|
| 35 |
from app.agent.state import AgentState
|
|
@@ -432,6 +433,17 @@ async def planner_node(state: AgentState) -> dict[str, Any]:
|
|
| 432 |
if not clean_plan:
|
| 433 |
logger.warning("planner: every planned step was invalid, using research fallback")
|
| 434 |
clean_plan = _fallback_research_plan(user_query)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 435 |
clean_plan = _normalize_plan_for_query(user_query, clean_plan)
|
| 436 |
if not clean_plan:
|
| 437 |
logger.warning("planner: every planned step was unnecessary, using research fallback")
|
|
@@ -463,7 +475,7 @@ def _fallback_research_plan(user_query: str) -> list[dict[str, Any]]:
|
|
| 463 |
"股票", "股价", "行情", "市值", "涨", "跌", "资金", "走势", "分析",
|
| 464 |
"财报", "公告", "研报", "消息面", "基金", "债", "指数", "港股", "A股",
|
| 465 |
)
|
| 466 |
-
if any(marker.lower() in q.lower() for marker in financial_markers) and (
|
| 467 |
REGISTRY.get_spec("financial-query") and REGISTRY.is_enabled("financial-query")
|
| 468 |
):
|
| 469 |
financial_query = (
|
|
|
|
| 30 |
from app.agent.skill_necessity import (
|
| 31 |
is_direct_financial_data_query,
|
| 32 |
is_skill_necessary_for_query,
|
| 33 |
+
requests_financial_data,
|
| 34 |
required_vertical_skills_for_query,
|
| 35 |
)
|
| 36 |
from app.agent.state import AgentState
|
|
|
|
| 433 |
if not clean_plan:
|
| 434 |
logger.warning("planner: every planned step was invalid, using research fallback")
|
| 435 |
clean_plan = _fallback_research_plan(user_query)
|
| 436 |
+
if (
|
| 437 |
+
not prior_calls
|
| 438 |
+
and is_direct_financial_data_query(user_query)
|
| 439 |
+
and not any(step.get("target_skill") == "financial-query" for step in clean_plan)
|
| 440 |
+
and REGISTRY.get_spec("financial-query")
|
| 441 |
+
and REGISTRY.is_enabled("financial-query")
|
| 442 |
+
):
|
| 443 |
+
# A valid JSON plan can still choose the wrong capability. Structured
|
| 444 |
+
# metrics go to their owning tool first; web fallback remains available
|
| 445 |
+
# after an empty/failed financial result on subsequent planning cycles.
|
| 446 |
+
clean_plan = _fallback_research_plan(user_query) + clean_plan
|
| 447 |
clean_plan = _normalize_plan_for_query(user_query, clean_plan)
|
| 448 |
if not clean_plan:
|
| 449 |
logger.warning("planner: every planned step was unnecessary, using research fallback")
|
|
|
|
| 475 |
"股票", "股价", "行情", "市值", "涨", "跌", "资金", "走势", "分析",
|
| 476 |
"财报", "公告", "研报", "消息面", "基金", "债", "指数", "港股", "A股",
|
| 477 |
)
|
| 478 |
+
if (requests_financial_data(q) or any(marker.lower() in q.lower() for marker in financial_markers)) and (
|
| 479 |
REGISTRY.get_spec("financial-query") and REGISTRY.is_enabled("financial-query")
|
| 480 |
):
|
| 481 |
financial_query = (
|
app/agent/skill_necessity.py
CHANGED
|
@@ -38,7 +38,9 @@ _VERTICAL_SKILL_ORDER = (
|
|
| 38 |
_DIRECT_FINANCIAL_DATA_MARKERS = (
|
| 39 |
"股票", "股价", "行情", "市值", "涨停", "跌停", "涨幅", "跌幅",
|
| 40 |
"成交", "换手", "资金流", "走势", "技术面", "基金", "指数", "可转债", "期货",
|
| 41 |
-
"营收", "净利润", "财务指标", "交易日", "开盘",
|
|
|
|
|
|
|
| 42 |
)
|
| 43 |
|
| 44 |
|
|
@@ -108,10 +110,15 @@ def is_skill_necessary_for_query(user_query: str, skill: str) -> bool:
|
|
| 108 |
return True
|
| 109 |
|
| 110 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 111 |
def is_direct_financial_data_query(user_query: str) -> bool:
|
| 112 |
"""Whether one or more structured financial lookups can answer the query."""
|
| 113 |
-
|
| 114 |
-
if not any(marker.lower() in q for marker in _DIRECT_FINANCIAL_DATA_MARKERS):
|
| 115 |
return False
|
| 116 |
if has_cross_source_analysis_intent(user_query):
|
| 117 |
return False
|
|
|
|
| 38 |
_DIRECT_FINANCIAL_DATA_MARKERS = (
|
| 39 |
"股票", "股价", "行情", "市值", "涨停", "跌停", "涨幅", "跌幅",
|
| 40 |
"成交", "换手", "资金流", "走势", "技术面", "基金", "指数", "可转债", "期货",
|
| 41 |
+
"营收", "营业收入", "净利润", "财务指标", "交易日", "开盘",
|
| 42 |
+
"市盈率", "市净率", "股息率", "分红率", "毛利率", "净利率",
|
| 43 |
+
"每股收益", "净资产收益率", "资产负债率", "现金流",
|
| 44 |
)
|
| 45 |
|
| 46 |
|
|
|
|
| 110 |
return True
|
| 111 |
|
| 112 |
|
| 113 |
+
def requests_financial_data(user_query: str) -> bool:
|
| 114 |
+
"""Recognize financial metrics independently of news/analysis dimensions."""
|
| 115 |
+
q = (user_query or "").lower()
|
| 116 |
+
return any(marker.lower() in q for marker in _DIRECT_FINANCIAL_DATA_MARKERS)
|
| 117 |
+
|
| 118 |
+
|
| 119 |
def is_direct_financial_data_query(user_query: str) -> bool:
|
| 120 |
"""Whether one or more structured financial lookups can answer the query."""
|
| 121 |
+
if not requests_financial_data(user_query):
|
|
|
|
| 122 |
return False
|
| 123 |
if has_cross_source_analysis_intent(user_query):
|
| 124 |
return False
|