Files
marqdo/doc/next/004.md
cflmyandCursor a9ee858f53 feat(agent): Skill Compilation + Adaptive Routing (v2/P4)
Episode → maybe_learn → llm_free skills, plus abstract router backends
(marqdo/small-llm/jev?/llm/auto) via plugins/agent; no core host changes.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-24 13:28:50 +08:00

542 lines
7.9 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
有时候可能用户不太好接入Jev,所以阶段4应该要允许用户使用小参数的模型代替,你认为呢?
我非常赞同,而且我甚至建议**不要把 Jev 作为阶段 4 的必选组件**。
更准确的设计应该是:
> **Jev 是一种可选的决策器(Decision Engine),小参数模型是另一种可选实现;Marqdo Agent 本身只规定“需要一个 Router/Policy”,而不规定 Router 必须由什么实现。**
这样会让整个框架开放很多。
### 1. 阶段 4 应该改成“Adaptive Routing”
原来的:
```text
Phase 4
↓
Jev Router
```
我建议改成:
```text
Phase 4: Adaptive Routing
│
┌─────────┼─────────┐
↓ ↓ ↓
Marqdo Rule Jev Small LLM
│ │ │
└─────────┼─────────┘
↓
Route Policy
```
甚至还可以允许:
```text
Rule
Small Model
Jev
Full LLM
```
混合使用。
---
# 2. 为什么这个设计更合理
因为用户真正需要的不是:
> “我要接入 Jev。”
而是:
> “我希望 Agent 学会以后,不要每次都调用大模型。”
这两个概念应该分开。
所以 Marqdo 只定义接口:
```text
agent.route(task, candidates)
```
至于内部怎么实现,可以是:
### A. 纯 Marqdo
```text
if task.type == "json":
return json-repair
if task.type == "search":
return corpus-search
```
完全不需要模型。
---
### B. 小参数模型
比如用户已经有:
```text
Qwen 0.5B
Qwen 1.5B
Llama 1B
某个本地模型
```
就可以:
```text
task
↓
small model
↓
"json-repair"
```
甚至可以让用户直接配置:
```yaml
router:
type: llm
provider: openai-compatible
base_url: ...
api_key: ...
model: ...
```
这和你之前设计 AI 斗蛐蛐时提出的 **OpenAI-compatible URL + Key** 思路其实也很契合。
---
### C. Jev
如果用户安装了 Jev:
```text
task
↓
Jev
↓
policy
```
那么就用 Jev。
---
### D. 大模型
甚至最开始没有任何 Router:
```text
task
↓
large LLM
↓
decide
```
也是合法的。
所以:
> **Router 是抽象能力,不是具体模型。**
---
# 3. 更重要的是:Router 本身也可以被学习
这里我觉得还能进一步提升你的设计。
一开始:
```text
Task
↓
Large LLM
↓
选择 skill
```
系统观察:
```text
task A → json-repair
task B → json-repair
task C → json-repair
task D → corpus-search
```
之后可以自动生成:
```text
router.mq.md
```
例如:
```markdown
---
type: policy
status: compiled
---
## route
1. `task.type` == "json"
*"json-repair"*
2. `task.type` == "search"
*"corpus-search"*
3. *
*"llm"*
```
那么你甚至不需要 Jev。
**Marqdo 自己的控制流就是 Router。**
---
# 4. 所以我会重新设计 Cost Ladder
之前的:
```text
L0 deterministic
L1 rule
L2 small model
L3 small LLM
L4 large LLM
L5 exploration
```
我建议改成:
```text
┌────────────────────────┐
│ Adaptive Router │
└───────────┬────────────┘
│
┌─────────────────┼─────────────────┐
↓ ↓ ↓
Deterministic Small Model Large LLM
│ │ │
↓ ↓ ↓
L0/L1 L2/L3 L4
│
↓
Exploration L5
```
这里最关键的是:
> **L2/L3 不应该规定具体模型。**
可以是:
```text
Marqdo rules
OR
Jev
OR
0.5B model
OR
1B model
OR
3B model
```
---
# 5. 我甚至建议用户可以配置多个 Router
例如:
```yaml
router:
candidates:
- name: rules
type: marqdo
- name: local
type: llm
model: qwen-0.5b
- name: jev
type: jev
- name: cloud
type: llm
model: ...
```
然后 Agent 自己选择:
```text
Task
↓
Router Resolver
↓
rules?
↓
confidence insufficient
↓
small model?
↓
confidence insufficient
↓
Jev?
↓
confidence insufficient
↓
large LLM
```
这就形成一个**分级决策系统**。
---
# 6. 最漂亮的地方:Router 也可以被编译
最终甚至可以:
```text
第一次:
LLM
↓
决定调用 Skill A
第二次:
LLM
↓
决定调用 Skill A
第三次:
LLM
↓
决定调用 Skill A
Learning
↓
发现稳定模式
Compile
↓
router.mq.md
```
以后:
```text
Task
↓
router.mq.md
↓
skill A
↓
execute
```
**0 LLM。**
于是整个 Agent 的学习就不只是:
```text
学习如何解决任务
```
而是同时学习:
```text
1. 学习如何解决任务
2. 学习什么时候使用什么技能
3. 学习什么时候需要大模型
```
这三个层次组合起来,我认为比单纯引入 Jev 更有意思。
---
# 7. 最终可以形成三级编译
我现在反而觉得你的 Agent Framework 可以把整个“学习”定义成三个阶段:
```text
Experience
↓
Skill Compilation
↓
Policy Compilation
↓
Execution Compilation
```
### 第一层:Skill Compilation
```text
LLM experience
↓
skill.mq.md
```
解决:
> **怎么做?**
### 第二层:Policy Compilation
```text
many task → skill mappings
↓
policy.mq.md
```
解决:
> **什么时候做什么?**
### 第三层:Execution Compilation
```text
skill + policy
↓
pure Marqdo execution
```
解决:
> **能不能完全不思考直接执行?**
这时候整个 Agent 就变成:
```text
Large LLM
│
Exploration
↓
Experience
↓
┌───────────────┐
│ Skill Compile │
└───────┬───────┘
↓
Skill MQ
│
┌───────┴───────┐
↓ ↓
Policy Compile Direct Execute
↓
Router MQ
│
↓
Skill Selection
│
↓
Execute
```
---
# 8. 因此 Phase 4 我建议正式改名
不要叫:
> Jev Router
而叫:
> **Adaptive Policy / Routing Layer**
然后提供四种 backend:
```text
router.backend = marqdo
router.backend = small-llm
router.backend = jev
router.backend = llm
```
甚至:
```text
router.backend = auto
```
让 Agent 根据可用环境自动选择。
---
## 9. 用户体验也会好很多
用户第一次安装 Marqdo:
```text
marqdo agent run ...
```
没有 Jev,也没有小模型。
完全没问题:
```text
→ 使用配置的大模型
```
用户后来配置:
```yaml
router:
backend: small-llm
provider: openai-compatible
model: qwen-0.5b
```
Agent 就自动变成:
```text
大模型:负责复杂推理 / 学习
小模型:负责日常路由
Marqdo:负责确定性执行
```
如果用户安装 Jev:
```yaml
router:
backend: jev
```
则:
```text
Jev:负责路由
大模型:负责复杂任务
Marqdo:负责执行
```
**用户完全不需要改变 Agent 的上层 API。**
---
我认为这个调整非常重要,因为它让 **Marqdo Agent 的核心创新从“依赖某个新模型”变成“模型无关的认知编译架构”**。
最终可以浓缩成一句话:
> **大模型负责探索,小模型/Jev 负责决策,Marqdo 负责执行;随着经验积累,探索和决策逐渐被编译成可执行的 `.mq.md`。**
这其实比“接入 Jev”本身更符合你最开始提出的 **Think → Execute → Learn → Compile → Reuse** 路线。