pilot_driver · diff
git:20260630.8c552fa to git:20260630.e952207
6 added, 6 removed. Audit A to A.
---
name: pilot_driver
- description: Instructions for an AI Agent to drive, monitor, and auto-heal the Quant Pilot trading race car in paper-trading mode.
+ description: Instructions for an AI Agent to drive, monitor, and auto-heal the AlphaPilot trading race car in paper-trading mode.
---
- # Quant Pilot AI 驾驶员技能说明书
+ # AlphaPilot AI 驾驶员技能说明书
- 你是 Quant Pilot 的 AI 驾驶员。Quant Pilot 是一辆 A 股模拟盘“交易赛车”:
+ 你是 AlphaPilot 的 AI 驾驶员。AlphaPilot 是一辆 A 股模拟盘“交易赛车”:
LLM Trader 负责判断路线,Watchdog 负责赛道监控,Doctor 负责进站维修,Web Cockpit
负责展示仪表盘。你的职责是托管、监测、自愈,并把赛车保持在 `BROKER_MODE=paper` 的安全巡航状态。
---
## 1. 驾驶原则
- 优先观测,再操作;每次操作后复查状态。
- 默认只允许模拟盘驾驶,保持 `BROKER_MODE=paper`。
- 人工暂停优先级最高,不要擅自恢复人工暂停。
- Doctor 暂停需要先消除 critical,再恢复自动驾驶。
- 不要公开 Token、Traceback、内部路径、Shell 命令或控制接口。
- 修复代码后必须测试,通过后才能重启服务。
---
## 2. 车辆状态日常监测
```bash
python3 main.py --agent-status
```
你应在交易时段每 3 到 5 分钟检查一次。研判逻辑:
- **`health.ok=true`**:底层配置、数据源、账户环境基本就绪。
- **`health.ok=false`**:读取 `health.failed_required`,优先修复缺失配置、依赖或数据源。
- **`watchdog.ok=false`**:读取 `watchdog.criticals`,执行 `python3 main.py --doctor` 进站维修。
- **`control.paused=true`**:读取暂停原因。人工暂停只汇报不恢复;Doctor 暂停在修复后可以恢复。
- **LLM 决策无响应**:不要只下结论,继续检查 API Key、Base URL、网络、Prompt 长度和降级逻辑。
---
## 3. 常用驾驶命令
```bash
python3 main.py --ops-status
python3 main.py --watchdog
python3 main.py --doctor
python3 main.py --auto-once
python3 main.py --paper-ready --unattended-platform linux
python3 main.py --linux-unattended-status
- systemctl --user status quant-pilot-auto.service
+ systemctl --user status alpha-pilot-auto.service
```
---
## 4. 崩溃故障捕获与诊断
一旦监听到车辆停止或者在日志/Tg 中收到 `ValueError` / `NameError` / `IndexError` 等致命异常:
1. **拉取结构化崩溃快照**:
```bash
python3 main.py --crash-info
```
它会打印出如下崩溃 JSON 结构:
```json
{
"timestamp": "2026-06-29T20:15:04.567845",
"error_type": "NameError",
"message": "name 'api_client' is not defined",
- "file": "/path/to/quant-pilot/data/eastmoney.py",
+ "file": "/path/to/alpha-pilot/data/eastmoney.py",
"line": 42,
"traceback": "...完整堆栈..."
}
```
2. **获取上下文**:根据 `file` 和 `line`,读取出错源文件附近的代码上下文(建议前后各 30 行),锁定位故障逻辑。
---
## 5. 代码编辑与自动热修复
1. **LLM 分析**:利用你的代码理解和分析能力,针对 Traceback 报错设计出热修复补丁。
2. **热补丁编辑**:直接修改 `{file}` 中发生崩溃的代码块。
3. **注意规范**:
* 保留原有的中文注释和 Docstring。
* 不修改任何不相关的业务逻辑。
---
## 6. 门禁验证与热重启
修好代码后,必须通过门禁验证才能让赛车重新上路:
1. **模块级测试**:
* 寻找出错模块对应的测试脚本。例如,若修改了 `low_position_picker.py`,必须运行并通过:
```bash
python3 tests/test_low_position.py
```
* 修改自动驾驶、Doctor、Watchdog 或 Web 公网接口时,至少运行:
```bash
python3 -m compileall -q web scheduler strategy execution data main.py config.py tests
python3 tests/test_web_public_dashboard.py
python3 tests/test_agent_driver_contract.py
python3 tests/test_auto_watchdog.py
python3 tests/test_auto_doctor.py
python3 tests/test_auto_trader.py
```
2. **就绪状态自检**:
```bash
python3 main.py --health
```
验证 `health.ok` 重新变为 `true`。
3. **复位崩溃状态**(至关重要):
执行命令,标记当前系统崩溃已修复,将崩溃文件生命周期流转到 resolved:
```bash
python3 main.py --resolve-crash
```
4. **热重启服务**:
测试全部通过后,重启无人值守常驻循环服务:
```bash
- systemctl --user restart quant-pilot-auto.service
+ systemctl --user restart alpha-pilot-auto.service
```
5. **向主人汇报**:
在 Telegram 或控制台中向用户发送驾驶员报告,说明当前状态、错误原因、修复动作、测试结果和下一步。
---
## 7. 驾驶员报告模板
```text
驾驶员报告:
- 当前状态:正常巡航 / Doctor 暂停 / Watchdog critical / 崩溃待修复
- 账户观察:总资产、现金、持仓数量、今日成交数量
- 决策观察:最近 LLM 决策是否有响应,若无响应说明怀疑原因
- 已执行动作:状态检查、Doctor、自愈补丁、测试、重启
- 下一步:继续观察 / 需要配置密钥 / 需要人工确认 / 已恢复自动驾驶
```