Add demo trading analyst with plan validation and sizing
The analyst prompts the model with trading rules, published skills, account sizing inputs and prefetched market data, exposes read-only tools plus submit_trade_plan, and validates and sizes the submitted plan in pure functions covered by pytest. Manual analyses run as dry runs while trading is stopped; the trading page shows the latest plan and an analysis detail drawer.
This commit is contained in:
1 parent
7536c9c5de
commit
78ca4422af
16 files changed
+1465
-151
No files matched your search
@@ -31,6 +31,8 @@ MAX_RETRIES = 2
|
||||
# 这些都由这里再重试,且只在还没有输出内容时重试
|
||||
STREAM_RETRIES = 3
|
||||
STREAM_RETRY_DELAY_SECONDS = 2
|
||||
# 输出被截断时回给模型的工具结果:参数不完整,不能执行
|
||||
TRUNCATED_RESULT = json.dumps({"error": "输出达到最大输出上限被截断,工具参数不完整,未执行。请精简内容后重新调用"}, ensure_ascii=False)
|
||||
|
||||
logger = logging.getLogger("alphapulse.ai.llm")
|
||||
|
||||
|
||||
@@ -50,14 +50,18 @@ async def data_overview(session: AsyncSession) -> str:
|
||||
return "\n".join(lines)
|
||||
|
||||
|
||||
async def build_system_prompt(session: AsyncSession) -> str:
|
||||
parts = [BASE_INSTRUCTIONS, "## 数据概况", await data_overview(session)]
|
||||
async def skills_section(session: AsyncSession) -> str:
|
||||
skills = await published_skills(session)
|
||||
parts.append("## Skills(按优先级从高到低)")
|
||||
parts = ["## Skills(按优先级从高到低)"]
|
||||
if skills:
|
||||
parts += [f"### 【优先级 {info.node.priority}】{info.path}\n\n{content}" for info, content in skills]
|
||||
else:
|
||||
parts.append("(暂无已发布的 skill)")
|
||||
return "\n\n".join(parts)
|
||||
|
||||
|
||||
async def build_system_prompt(session: AsyncSession) -> str:
|
||||
parts = [BASE_INSTRUCTIONS, "## 数据概况", await data_overview(session), await skills_section(session)]
|
||||
context = await current_context(session)
|
||||
parts += ["## CONTEXT.md", context.content if context and context.content.strip() else "(空)"]
|
||||
return "\n\n".join(parts)
|
||||
Reference in new issue
Block a user