JitRL Sport Agent - 智能运动训练处方生成智能体
基于 JitRL(ICML 2026 论文,arXiv 2601.18510v3)的无梯度强化学习框架,实现智能运动训练处方生成智能体。
核心特性
-
无梯度持续学习:基于非参数记忆库 + Jaccard 检索 + 闭式策略更新,无需微调 LLM
-
六级约束优先级:动作风控 → 体能调度 → 肌群间隔 → 1RM换算 → 周期控制 → 时长增幅
-
多 LLM 后端:支持 Ollama、vLLM、Mock 三种后端,无缝切换
-
知识图谱集成:Neo4j 伤病-动作风控图谱,支持降级到 JSON 知识库
-
双接口:CLI 命令行 + FastAPI RESTful API
-
完整 Python 实现:Pydantic v2 数据模型,类型安全
快速开始
# 安装依赖
pip install -r requirements.txt
# 运行集成测试(Mock后端,无需LLM服务)
python tests/test_integration.py
# 生成处方
python cli/main.py generate -i data/sample_input.json -o output.json -f json
# 启动API服务
python cli/main.py server --port 8000
# 访问 http://localhost:8000/docs
切换 LLM 后端
编辑 config/default.yaml:
# Ollama
llm:
backend: "ollama"
model: "qwen2.5:14b"
ollama_base_url: "http://localhost:11434"
# vLLM
llm:
backend: "vllm"
model: "Qwen/Qwen2.5-14B-Instruct"
vllm_base_url: "http://localhost:8000"
token_level_logit: true
项目结构
src/ ├── models/ # Pydantic 数据模型 ├── llm/ # LLM 后端(ollama/vllm/mock) ├── jitrl/ # JitRL 核心算法 ├── constraints/ # 六大约束模块 ├── knowledge_graph/ # Neo4j 知识图谱 ├── prescription/ # 处方生成 └── utils/ # 工具 cli/ # CLI 接口 api/ # FastAPI 接口 docs/ # 4份Word文档 assets/ # 架构图/流程图/UML
JitRL 算法核心
1. 状态编码: s = encode(input) 2. 记忆检索: N(s) = top-k similar(s, M) 3. 状态价值: V(s) = mean(G_i for N(s)) 4. LLM候选: C_LLM = llm.generate(s) 5. 动作价值: Q(s,a) = mean(G_i for a_i=a) or V(s)+UCB 6. 优势: A(s,a) = Q(s,a) - V(s) 7. 归一化: Ã(s,a) = A / (max|A| + ε) 8. 策略更新: z'(s,a) = z(s,a) + β·Ã(s,a) 9. 采样: a* ~ Softmax(z') 10. 评估: r = Evaluator(prescription) 11. 记忆: M.add(s, a*, G_t)
文档
详见 docs/ 目录:
-
解决方案文档.docx
-
架构文档.docx
-
设计文档.docx
-
实现文档.docx
