feat(agent): ext APIs, goldens, and docs for MCP/resume/small-llm routing
Wire mcp_connect/list/call, resume_*, and demote Jev in author docs. Offline goldens cover MCP client, resume, and small-llm/jev-alias route. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
c29d48f38c
commit
0ed57b6d54
13 files changed
+425
-16
No files matched your search
@@ -218,7 +218,7 @@ Install: `marqdo ext add agent` (ZH: `智能体`). Native: `cargo build --releas
|
||||
2. **Call site is first-class** — `build_step_context` injects path/function/line so the model knows where it is in the program.
|
||||
3. **Document is the knowledge base (OKF)** — writeback → promote/solidify → reuse / `llm_free`; MCP/corpus are evidence only.
|
||||
4. **Skill Compilation (v2)** — successful runs become `.mq.md` episodes; after enough evidence, `maybe_learn` compiles an executable skill (`llm_free`). Prefer `## run` over bare `## plan` when you want learning.
|
||||
5. **Adaptive Routing (P4)** — router is abstract (`marqdo` / `small-llm` / optional `jev` / `llm` / `auto`); Jev is never required. Policy Compilation writes `policies/router.mq.md`.
|
||||
5. **Adaptive Routing (P4)** — router is abstract (`marqdo` / `small-llm` / `llm` / `auto`); `jev` is a compat alias of `small-llm`. Decision via `router_model` (any llm handle). Policy Compilation writes `policies/router.mq.md`.
|
||||
|
||||
APIs: `# agent` / `# 智能体` → `## run` / `## route` / `## step` / `## plan` (+ `resolve` / `record_episode` / `maybe_learn` / `compile` / `compile_policy` / `metrics`). Context: standing + task + **call site** + tools + budgeted source/skill + act protocol (`CALL:` / `READ:`). Inspect without LLM: `dump_step_context`. Inside `writeback=` / `写回=` branches use `host_writeback_record` (param name shadows the writeback import).
|
||||
|
||||
|
||||
@@ -1,5 +1,15 @@
|
||||
# Changelog
|
||||
|
||||
## Unreleased
|
||||
|
||||
### Added
|
||||
- **`plugins/llm` Transport ABI** (`llm_chat_completions`): `ext/ai/llm/openai` prefers the native plugin when resolvable, else `lib/net` HTTP/SSE.
|
||||
- **Agent MCP stdio client** (`agent_mcp_client` / `mcp_connect` / `mcp_client_list` / `mcp_client_call`) plus offline golden against a Python mock server.
|
||||
- **Agent resume checkpoints** (`.marqdo/agent-resume/<id>.json` — save/load/clear/list; `run` can set `resume_id=`).
|
||||
|
||||
### Changed
|
||||
- Adaptive Routing: `jev` is a **compat alias** of `small-llm` (no `MARQDO_JEV` first-class path). Decision surface is `router_model` (any llm handle).
|
||||
|
||||
## v1.1.0 — 2026-09-23
|
||||
|
||||
### Highlights
|
||||
|
||||
@@ -184,7 +184,7 @@ ext/
|
||||
| `## 单步` | `## step` | 原子执行;注入源码 + 位置;可选工具;返回结构化 map;**默认自动写回**(`写回=` / `writeback=` 可关) |
|
||||
| `## 多步` | `## plan` | 建/续工作簿 → subtask 跑文件 → 修订循环 → 汇总(见 [ext-agent-plan.md](ext-agent-plan.md)) |
|
||||
| `## 解析` | `## resolve` | 技能解析:exact → alias → canonical → near |
|
||||
| `## 路由` | `## route` | **P4 Adaptive Routing**:`marqdo` \| `small-llm` \| `jev` \| `llm` \| `auto`(Jev 可选,非必选) |
|
||||
| `## 路由` | `## route` | **P4 Adaptive Routing**:`marqdo` \| `small-llm` \| `llm` \| `auto`(`jev` 为 `small-llm` 兼容别名) |
|
||||
| `## 应用路由` | `## route_apply` | 将小模型/大模型路由回复(`SKILL:<slug>` / `EXPLORE`)落到 kb 技能 |
|
||||
| `## 编译策略` | `## compile_policy` | Policy Compilation → `policies/router.mq.md` |
|
||||
| `## 记录情景` | `## record_episode` | 每次执行沉淀为 `.mq.md` episode(`.marqdo/agent-memory/`) |
|
||||
@@ -198,7 +198,7 @@ ext/
|
||||
|
||||
**LLM 成本**:`model_turn` 走 `model.ask` / `stream`+`collect`,把 `LLMResult.tokens` 写入 episode / `execution`。
|
||||
|
||||
**Adaptive Routing(P4,原「Jev Router」更名)**:Router 是抽象能力,backend = `marqdo`(已编译 `policies/router.mq.md`)/ `small-llm`(用户自备小参数模型)/ `jev`(可选)/ `llm` / `auto` 级联。**不依赖 Jev**。热路径在 **`plugins/agent`**(`route.rs`);**禁止**向 `src/host/` 加领域原语。设计:[doc/next/003.md](../next/003.md) · [doc/next/004.md](../next/004.md)。
|
||||
**Adaptive Routing(P4)**:Router 是抽象能力,backend = `marqdo`(已编译 `policies/router.mq.md`)/ `small-llm`(`router_model` 任意 llm 句柄)/ `llm` / `auto` 级联。`jev` 仅为 `small-llm` 兼容别名,**不进入框架专属设计**。热路径在 **`plugins/agent`**(`route.rs`);**禁止**向 `src/host/` 加领域原语。设计:[doc/next/003.md](../next/003.md) · [doc/next/004.md](../next/004.md)。
|
||||
|
||||
构造参数(v1):
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
|
||||
> **Document → Prompt → LLM → Agent → Skill → Policy → Executable Knowledge**
|
||||
|
||||
大模型负责探索,小模型/可选 Jev 负责决策,Marqdo 负责执行;经验编译进 `.mq.md` 后推理成本下降。
|
||||
大模型负责探索,小模型(`router_model` / 任意 llm 句柄)负责决策,Marqdo 负责执行;经验编译进 `.mq.md` 后推理成本下降。
|
||||
|
||||
## 2. 分层(勿混)
|
||||
|
||||
@@ -34,7 +34,7 @@
|
||||
| Prompt document:`prompt` / `prompt_load` + `type: prompt` 正文 | **done**(无参 `ask`/`stream` → `sys.module_source` + `prompt_body`) |
|
||||
| 拆 `ext/ai/llm/openai.mq.md` + `ollama` 后端 | **done** |
|
||||
| tool_calls 完整 Result | **done**(`openai.tool_calls_from` + `LLMResult.tool_calls`;`llm-tool-calls-offline`) |
|
||||
| Transport → 可选 ABI 插件 | 暂缓 |
|
||||
| Transport → 可选 ABI 插件 (`plugins/llm`) | **done** |
|
||||
| Artifact Metadata Binding(`${env.*}` / `secret` · `sys.meta`) | **done**(Phase 1 Metadata-only + Phase 2 scope lift;[binding.md](../design/binding.md)) |
|
||||
|
||||
作者面优先:
|
||||
@@ -52,14 +52,14 @@
|
||||
| 项 | 状态 |
|
||||
|----|------|
|
||||
| Skill Compilation:episode → maybe_learn → `llm_free` | **done** |
|
||||
| Adaptive Routing:`marqdo` \| `small-llm` \| `jev?` \| `llm` \| `auto` | **done** |
|
||||
| Adaptive Routing:`marqdo` \| `small-llm` \| `llm` \| `auto`(`jev`→`small-llm` 别名) | **done** |
|
||||
| Policy Compilation → `policies/router.mq.md` | **done** |
|
||||
| `run` 串联 route → execute → record → learn | **done** |
|
||||
| Agent 默认走 `model.ask` + Result.usage 记成本 | **done**(`model_turn`) |
|
||||
| Prompt artifact / document-as-prompt | **done**(经 llm `path=` / `prompt`) |
|
||||
| 零 LLM 执行(policy+skill → `llm_calls=0`) | **done** |
|
||||
| `plan` 不覆盖已有 `llm_free` resource | **done** |
|
||||
| 真 MCP client / resume / Jev 接线 / 小模型 live 路由 | 暂缓 |
|
||||
| 真 MCP client(stdio) / resume checkpoint / 小模型路由请求面 | **done**(live 路由仍可选 skip) |
|
||||
|
||||
## 5. 联调顺序
|
||||
|
||||
@@ -72,6 +72,6 @@
|
||||
|
||||
## 6. 验收金样
|
||||
|
||||
- Agent:`tests/ext/agent-v2-learn.mq.md` · `agent-p4-route.mq.md` · `agent-zero-llm.mq.md` · `agent-plan-preserve.mq.md` · `scripts/agent-harness.sh`
|
||||
- Agent:`tests/ext/agent-v2-learn.mq.md` · `agent-p4-route.mq.md` · `agent-zero-llm.mq.md` · `agent-plan-preserve.mq.md` · `agent-mcp-client.mq.md` · `agent-resume.mq.md` · `agent-small-llm-route.mq.md` · `scripts/agent-harness.sh`
|
||||
- LLM:`tests/ext/llm-ask-offline.mq.md` · `llm-stream-offline.mq.md` · `llm-ctor-offline.mq.md` · `llm-named-offline.mq.md` · `llm-meta-offline.mq.md` · `llm-entry-prompt-offline.mq.md` · `llm-tool-calls-offline.mq.md`
|
||||
- Binding:`tests/structure/meta-binding.mq.md` · `meta-lift.mq.md`
|
||||
@@ -42,6 +42,9 @@
|
||||
| **B1.5** | **Skill Compilation v2(Phase 1–3)**:episode → maybe_learn → compile → `llm_free`;`agent.run` / `resolve` / `metrics`;ABI 在 `plugins/agent`(`memory.rs`);金样 `agent-v2-learn` | **done** |
|
||||
| **B1.6 / P4** | **Adaptive Routing**(原 Jev Router 更名):`route` backends = `marqdo` \| `small-llm` \| `jev?` \| `llm` \| `auto`;Policy Compilation → `policies/router.mq.md`;金样 `agent-p4-route`;设计 [004.md](../next/004.md) | **done** |
|
||||
| **L0** | **LLM semantic surface(005)**:`ask` / `stream` / `collect` / `create`;`complete` 降为兼容;统一方案 [ai-stack.md](ai-stack.md) | **done** |
|
||||
| **B2–B5** | 真 MCP / resume+HITL / stats / 并行;小模型 live 路由;Jev 可选接线;LLM named models / prompt-document | 暂缓 |
|
||||
| **B2** | 真 MCP stdio client(`agent_mcp_client` + fixture 仍作离线证据) | **done** |
|
||||
| **B3** | resume checkpoint(`.marqdo/agent-resume/`;HITL view 仍暂缓) | **done**(HITL 暂缓) |
|
||||
| **B4–B5** | stats / 并行;小模型 live 路由金样(无 key skip) | 部分 |
|
||||
| — | LLM named models / prompt-document | **done** |
|
||||
|
||||
示例:`examples/agent-pong/` · `examples/agent-okf-flywheel/`。v2 设计:[doc/next/002.md](../next/002.md) · [doc/next/003.md](../next/003.md) · P4:[doc/next/004.md](../next/004.md) · LLM:[doc/next/005.md](../next/005.md)。
|
||||
+134
-2
@@ -455,6 +455,128 @@ Call a named tool from a MCP-shaped fixture (`results` / `calls` map). Optional
|
||||
|
||||
---
|
||||
|
||||
## mcp_connect
|
||||
+ `command`
|
||||
+ `args`=None
|
||||
+ `session`="default"
|
||||
+ `name`="mcp"
|
||||
|
||||
Open a stdio MCP client session (spawn `command` + `args`, JSON-RPC initialize). Evidence only — workbook remains authority.
|
||||
|
||||
**p = > plugin.native_path name="agent"**
|
||||
1. `p`
|
||||
> plugin.load path=`p`
|
||||
2. *
|
||||
> print text=ext/ai/agent: native agent plugin not found
|
||||
> sys.exit code=1
|
||||
|
||||
1. `args`
|
||||
*> agent_mcp_client action="connect" command=`command` args=`args` session=`session` name=`name`*
|
||||
2. *
|
||||
*> agent_mcp_client action="connect" command=`command` session=`session` name=`name`*
|
||||
|
||||
## mcp_client_list
|
||||
+ `session`="default"
|
||||
+ `command`=None
|
||||
+ `args`=None
|
||||
|
||||
List tools from an open MCP session, or one-shot when `command=` is set (no session retained).
|
||||
|
||||
1. `command`
|
||||
1. `args`
|
||||
*> agent_mcp_client action="list" command=`command` args=`args`*
|
||||
2. *
|
||||
*> agent_mcp_client action="list" command=`command`*
|
||||
2. *
|
||||
*> agent_mcp_client action="list" session=`session`*
|
||||
|
||||
## mcp_client_call
|
||||
+ `name`=None
|
||||
+ `session`="default"
|
||||
+ `arguments`=None
|
||||
+ `command`=None
|
||||
+ `args`=None
|
||||
+ `tool`=None
|
||||
|
||||
Call a tool on an open MCP session, or one-shot when `command=` is set. Prefer `tool=` for oneshot when `name` would collide with server name.
|
||||
|
||||
1. `command`
|
||||
1. `tool`
|
||||
**tn = tool**
|
||||
2. *
|
||||
**tn = name**
|
||||
1. `args`
|
||||
*> agent_mcp_client action="call" command=`command` args=`args` tool=`tn` arguments=`arguments`*
|
||||
2. *
|
||||
*> agent_mcp_client action="call" command=`command` tool=`tn` arguments=`arguments`*
|
||||
2. *
|
||||
*> agent_mcp_client action="call" session=`session` name=`name` arguments=`arguments`*
|
||||
|
||||
## mcp_disconnect
|
||||
+ `session`="default"
|
||||
|
||||
Close a stdio MCP client session.
|
||||
|
||||
*> agent_mcp_client action="close" session=`session`*
|
||||
|
||||
---
|
||||
|
||||
## resume_save
|
||||
+ `id`
|
||||
+ `goal`=None
|
||||
+ `task`=None
|
||||
+ `status`=running
|
||||
+ `round`=0
|
||||
+ `workbook`=None
|
||||
+ `events`=None
|
||||
+ `route`=None
|
||||
+ `result`=None
|
||||
+ `resume_dir`=.marqdo/agent-resume
|
||||
|
||||
Persist a plan/run checkpoint as `.marqdo/agent-resume/<id>.json`.
|
||||
|
||||
**p = > plugin.native_path name="agent"**
|
||||
1. `p`
|
||||
> plugin.load path=`p`
|
||||
2. *
|
||||
> print text=ext/ai/agent: native agent plugin not found
|
||||
> sys.exit code=1
|
||||
|
||||
*> agent_resume_save id=`id` goal=`goal` task=`task` status=`status` round=`round` workbook=`workbook` events=`events` route=`route` result=`result` resume_dir=`resume_dir`*
|
||||
|
||||
## resume_load
|
||||
+ `id`
|
||||
+ `resume_dir`=.marqdo/agent-resume
|
||||
|
||||
Load a resume checkpoint (or `{ok:false,found:false}`).
|
||||
|
||||
*> agent_resume_load id=`id` resume_dir=`resume_dir`*
|
||||
|
||||
## resume_clear
|
||||
+ `id`
|
||||
+ `resume_dir`=.marqdo/agent-resume
|
||||
|
||||
Delete a resume checkpoint.
|
||||
|
||||
*> agent_resume_clear id=`id` resume_dir=`resume_dir`*
|
||||
|
||||
## resume_list
|
||||
+ `resume_dir`=.marqdo/agent-resume
|
||||
|
||||
List checkpoint ids under `resume_dir`.
|
||||
|
||||
*> agent_resume_list resume_dir=`resume_dir`*
|
||||
|
||||
## resume
|
||||
+ `id`
|
||||
+ `resume_dir`=.marqdo/agent-resume
|
||||
|
||||
Author entry: load checkpoint for continuation. Returns the checkpoint map (`found`/`round`/`workbook`/…). Callers continue with `plan`/`run` using saved fields; clear when done.
|
||||
|
||||
*> resume_load id=`id` resume_dir=`resume_dir`*
|
||||
|
||||
---
|
||||
|
||||
## extract_call_args
|
||||
+ `reply`=None
|
||||
|
||||
@@ -1574,7 +1696,7 @@ Skill resolver (v2): exact → alias → canonical → near. Returns `mode` / `r
|
||||
+ `memory_dir`=.marqdo/agent-memory
|
||||
+ `threshold`=0.78
|
||||
|
||||
Adaptive Routing (Phase 4): abstract router — `marqdo` | `small-llm` | `jev` | `llm` | `auto`. Jev is optional. `auto` cascades policy → kb → optional jev → small-llm request. May return `needs_llm=True` + `prompt` for the caller to complete with a small/large model, then `route_apply`.
|
||||
Adaptive Routing (Phase 4): abstract router — `marqdo` | `small-llm` | `llm` | `auto`. `jev` is accepted as a **compat alias** of `small-llm` (not a first-class backend). `auto` cascades policy → kb → small-llm request. May return `needs_llm=True` + `prompt` for the caller to complete with `router_model` (any llm handle), then `route_apply`.
|
||||
|
||||
**tools = > json.get value=`self` key="tools"**
|
||||
*> agent_route task=`task` backend=`backend` kb_dir=`kb_dir` memory_dir=`memory_dir` threshold=`threshold` tools=`tools`*
|
||||
@@ -1682,8 +1804,10 @@ Reasoning amortization stats over recorded episodes (`avg_llm_calls`, `compiled_
|
||||
+ `force`=False
|
||||
+ `router`=auto
|
||||
+ `router_model`=None
|
||||
+ `resume_id`=None
|
||||
+ `resume_dir`=.marqdo/agent-resume
|
||||
|
||||
Primary author entry (v2 + P4): Adaptive `route` → execute (policy/kb skill) or `plan` → record episode → maybe_learn (skill + policy). `router` = `auto`|`marqdo`|`small-llm`|`jev`|`llm`. Optional `router_model` (llm handle) answers `needs_llm` prompts — small models welcome; Jev is never required.
|
||||
Primary author entry (v2 + P4): Adaptive `route` → execute (policy/kb skill) or `plan` → record episode → maybe_learn (skill + policy). `router` = `auto`|`marqdo`|`small-llm`|`llm` (`jev`→`small-llm` alias). Optional `router_model` (llm handle) answers `needs_llm` prompts — small models welcome.
|
||||
|
||||
**routed = > `self`.route task=`task` backend=`router` kb_dir=`kb_dir` memory_dir=`memory_dir` threshold=`near_threshold`**
|
||||
**route_matched = > json.get value=`routed` key="matched"**
|
||||
@@ -1856,6 +1980,12 @@ Primary author entry (v2 + P4): Adaptive `route` → execute (policy/kb skill) o
|
||||
2. *
|
||||
**_ = 1**
|
||||
|
||||
1. `resume_id`
|
||||
**_ckpt = > resume_save id=`resume_id` goal=`task` task=`task` status=`st` round=1 workbook=`wb_path` result=`res` route=`routed` resume_dir=`resume_dir`**
|
||||
**out = > json.set map=`out` key="resume" value=`_ckpt`**
|
||||
2. *
|
||||
**_ = 1**
|
||||
|
||||
*out*
|
||||
|
||||
## step
|
||||
@@ -1995,6 +2125,8 @@ With `stream=True`, the model call uses SSE; `echo=True` prints delta text to st
|
||||
+ `stream`=False
|
||||
+ `echo`=False
|
||||
+ `trace`=False
|
||||
+ `resume_id`=None
|
||||
+ `resume_dir`=.marqdo/agent-resume
|
||||
|
||||
Multi-step with OKF agent-kb. Default workbook is `kb_dir/resources/<slug>.mq.md`. While task file count `< explore_n` and skill is not llm_free, force a new explore variant under `kb_dir/explore/<slug>/`. Code-first: llm_free hits skip parent LLM. File children return via `# main`; `plan` exposes that as `result`.
|
||||
|
||||
|
||||
+2
-2
@@ -286,7 +286,7 @@ import json:lib/json.mq.md
|
||||
+ `路由`=auto
|
||||
+ `路由模型`=None
|
||||
|
||||
v2+P4 主入口:自适应路由 → 执行 → 记录情景 → 尝试学习(技能 + 策略)。`路由`=`auto`|`marqdo`|`small-llm`|`jev`|`llm`;Jev 可选,小模型可作决策器。
|
||||
v2+P4 主入口:自适应路由 → 执行 → 记录情景 → 尝试学习(技能 + 策略)。`路由`=`auto`|`marqdo`|`small-llm`|`llm`(`jev` 为 `small-llm` 兼容别名);决策器用 `路由模型`(任意 llm 句柄)。
|
||||
|
||||
**model = > json.get value=`self` key="model"**
|
||||
**tools = > json.get value=`self` key="tools"**
|
||||
@@ -301,7 +301,7 @@ v2+P4 主入口:自适应路由 → 执行 → 记录情景 → 尝试学习
|
||||
+ `记忆目录`=.marqdo/agent-memory
|
||||
+ `阈值`=0.78
|
||||
|
||||
自适应路由(阶段 4):`marqdo` / `small-llm` / `jev` / `llm` / `auto`。
|
||||
自适应路由(阶段 4):`marqdo` / `small-llm` / `llm` / `auto`(`jev`→别名)。
|
||||
|
||||
**model = > json.get value=`self` key="model"**
|
||||
**tools = > json.get value=`self` key="tools"**
|
||||
|
||||
@@ -32,6 +32,9 @@ run tests/ext/agent-context-budget-a3.mq.md
|
||||
run tests/ext/agent-workbook-patch-a0.mq.md
|
||||
run tests/ext/agent-v2-learn.mq.md
|
||||
run tests/ext/agent-p4-route.mq.md
|
||||
run tests/ext/agent-small-llm-route.mq.md
|
||||
run tests/ext/agent-mcp-client.mq.md
|
||||
run tests/ext/agent-resume.mq.md
|
||||
run tests/ext/agent-zero-llm.mq.md
|
||||
run tests/ext/agent-plan-preserve.mq.md
|
||||
run examples/agent-okf-flywheel/index.mq.md
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
---
|
||||
title: agent MCP stdio client (offline)
|
||||
description: Oneshoot list+call against python mock MCP server.
|
||||
import agent:ext/ai/agent.mq.md
|
||||
import plugin:lib/plugin.mq.md
|
||||
import sys:lib/sys.mq.md
|
||||
import json:lib/json.mq.md
|
||||
---
|
||||
|
||||
# main
|
||||
|
||||
**p = > plugin.native_path name="agent"**
|
||||
1. `p`
|
||||
> plugin.load path=`p`
|
||||
2. *
|
||||
> print text=no-agent-plugin
|
||||
> sys.exit code=1
|
||||
|
||||
**argv = > json.parse text=["tests/ext/fixtures/mcp-stdio-mock.py"]**
|
||||
**listed = > agent.mcp_client_list command="python3" args=`argv`**
|
||||
**tools = > json.get value=`listed` key="tools"**
|
||||
**n = > len value=`tools`**
|
||||
1. `n` == 1
|
||||
> print text=mcp-client-list-ok
|
||||
2. *
|
||||
> print text=mcp-client-list-fail
|
||||
> print text=`listed`
|
||||
|
||||
**call_args = > json.parse text={"msg":"hi"}**
|
||||
**called = > agent.mcp_client_call command="python3" args=`argv` tool="echo" arguments=`call_args`**
|
||||
**auth = > json.get value=`called` key="authority"**
|
||||
1. `auth` == "workbook"
|
||||
> print text=mcp-client-call-ok
|
||||
2. *
|
||||
> print text=mcp-client-call-fail
|
||||
> print text=`called`
|
||||
@@ -0,0 +1,65 @@
|
||||
---
|
||||
title: agent resume checkpoint (offline)
|
||||
description: save / load / list / clear under .marqdo/agent-resume-test
|
||||
import agent:ext/ai/agent.mq.md
|
||||
import plugin:lib/plugin.mq.md
|
||||
import sys:lib/sys.mq.md
|
||||
import json:lib/json.mq.md
|
||||
import fs:lib/fs.mq.md
|
||||
---
|
||||
|
||||
# main
|
||||
|
||||
**p = > plugin.native_path name="agent"**
|
||||
1. `p`
|
||||
> plugin.load path=`p`
|
||||
2. *
|
||||
> print text=no-agent-plugin
|
||||
> sys.exit code=1
|
||||
|
||||
**dir = ".marqdo/agent-resume-test"**
|
||||
**exists = > fs.exists path=`dir`**
|
||||
1. `exists`
|
||||
> fs.remove_tree path=`dir`
|
||||
2. *
|
||||
**_ = 1**
|
||||
|
||||
**saved = > agent.resume_save id="demo1" goal="ping" status="running" round=2 resume_dir=`dir`**
|
||||
**ok = > json.get value=`saved` key="ok"**
|
||||
1. `ok`
|
||||
> print text=resume-save-ok
|
||||
2. *
|
||||
> print text=resume-save-fail
|
||||
|
||||
**loaded = > agent.resume id="demo1" resume_dir=`dir`**
|
||||
**found = > json.get value=`loaded` key="found"**
|
||||
**round = > json.get value=`loaded` key="round"**
|
||||
1. `found`
|
||||
1. `round` == 2
|
||||
> print text=resume-load-ok
|
||||
2. *
|
||||
> print text=resume-round-fail
|
||||
2. *
|
||||
> print text=resume-load-fail
|
||||
|
||||
**listed = > agent.resume_list resume_dir=`dir`**
|
||||
**items = > json.get value=`listed` key="items"**
|
||||
**n = > len value=`items`**
|
||||
1. `n` == 1
|
||||
> print text=resume-list-ok
|
||||
2. *
|
||||
> print text=resume-list-fail
|
||||
|
||||
**cleared = > agent.resume_clear id="demo1" resume_dir=`dir`**
|
||||
**c = > json.get value=`cleared` key="cleared"**
|
||||
1. `c`
|
||||
> print text=resume-clear-ok
|
||||
2. *
|
||||
> print text=resume-clear-fail
|
||||
|
||||
**loaded2 = > agent.resume_load id="demo1" resume_dir=`dir`**
|
||||
**found2 = > json.get value=`loaded2` key="found"**
|
||||
1. not `found2`
|
||||
> print text=resume-gone-ok
|
||||
2. *
|
||||
> print text=resume-gone-fail
|
||||
@@ -0,0 +1,43 @@
|
||||
---
|
||||
title: agent small-llm route request (offline)
|
||||
description: router=small-llm returns needs_llm + prompt; jev alias same shape.
|
||||
import plugin:lib/plugin.mq.md
|
||||
import sys:lib/sys.mq.md
|
||||
import json:lib/json.mq.md
|
||||
---
|
||||
|
||||
# main
|
||||
|
||||
**p = > plugin.native_path name="agent"**
|
||||
1. `p`
|
||||
> plugin.load path=`p`
|
||||
2. *
|
||||
> print text=no-agent-plugin
|
||||
> sys.exit code=1
|
||||
|
||||
**r = > agent_route task="say hello" backend="small-llm" kb_dir=".marqdo/agent-kb-route-test" memory_dir=".marqdo/agent-memory-route-test"**
|
||||
**needs = > json.get value=`r` key="needs_llm"**
|
||||
**backend = > json.get value=`r` key="backend"**
|
||||
**prompt = > json.get value=`r` key="prompt"**
|
||||
1. `needs`
|
||||
1. `backend` == "small-llm"
|
||||
1. `prompt`
|
||||
> print text=small-llm-ok
|
||||
2. *
|
||||
> print text=small-llm-no-prompt
|
||||
2. *
|
||||
> print text=small-llm-backend-fail
|
||||
2. *
|
||||
> print text=small-llm-fail
|
||||
|
||||
**j = > agent_route task="say hello" backend="jev" kb_dir=".marqdo/agent-kb-route-test" memory_dir=".marqdo/agent-memory-route-test"**
|
||||
**jb = > json.get value=`j` key="backend"**
|
||||
**jn = > json.get value=`j` key="needs_llm"**
|
||||
1. `jn`
|
||||
1. `jb` == "small-llm"
|
||||
> print text=jev-alias-ok
|
||||
2. *
|
||||
> print text=jev-alias-backend-fail
|
||||
> print text=`jb`
|
||||
2. *
|
||||
> print text=jev-alias-fail
|
||||
Executable
+73
@@ -0,0 +1,73 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Minimal stdio MCP server for offline client goldens."""
|
||||
import json
|
||||
import sys
|
||||
|
||||
def read_msg():
|
||||
line = sys.stdin.readline()
|
||||
if not line:
|
||||
return None
|
||||
line = line.strip()
|
||||
if not line:
|
||||
return read_msg()
|
||||
return json.loads(line)
|
||||
|
||||
def write_msg(msg):
|
||||
sys.stdout.write(json.dumps(msg, separators=(",", ":")) + "\n")
|
||||
sys.stdout.flush()
|
||||
|
||||
TOOLS = [
|
||||
{
|
||||
"name": "echo",
|
||||
"description": "echo arguments",
|
||||
"inputSchema": {"type": "object", "properties": {}, "additionalProperties": True},
|
||||
}
|
||||
]
|
||||
|
||||
while True:
|
||||
msg = read_msg()
|
||||
if msg is None:
|
||||
break
|
||||
mid = msg.get("id")
|
||||
method = msg.get("method") or ""
|
||||
params = msg.get("params") or {}
|
||||
if mid is None and str(method).startswith("notifications/"):
|
||||
continue
|
||||
if method == "initialize":
|
||||
write_msg({
|
||||
"jsonrpc": "2.0",
|
||||
"id": mid,
|
||||
"result": {
|
||||
"protocolVersion": "2024-11-05",
|
||||
"capabilities": {"tools": {}},
|
||||
"serverInfo": {"name": "mock", "version": "0.1.0"},
|
||||
},
|
||||
})
|
||||
elif method in ("tools/list", "list_tools"):
|
||||
write_msg({"jsonrpc": "2.0", "id": mid, "result": {"tools": TOOLS}})
|
||||
elif method in ("tools/call", "call_tool"):
|
||||
name = params.get("name") or ""
|
||||
args = params.get("arguments") or {}
|
||||
if name != "echo":
|
||||
write_msg({
|
||||
"jsonrpc": "2.0",
|
||||
"id": mid,
|
||||
"error": {"code": -32000, "message": f"unknown tool {name}"},
|
||||
})
|
||||
else:
|
||||
write_msg({
|
||||
"jsonrpc": "2.0",
|
||||
"id": mid,
|
||||
"result": {
|
||||
"content": [{"type": "text", "text": json.dumps(args, separators=(",", ":"))}],
|
||||
"isError": False,
|
||||
},
|
||||
})
|
||||
elif method == "ping":
|
||||
write_msg({"jsonrpc": "2.0", "id": mid, "result": {}})
|
||||
else:
|
||||
write_msg({
|
||||
"jsonrpc": "2.0",
|
||||
"id": mid,
|
||||
"error": {"code": -32601, "message": f"method not found: {method}"},
|
||||
})
|
||||
+47
-3
@@ -136,10 +136,21 @@ fn ensure_agent_plugin_built() {
|
||||
} else {
|
||||
root.join("target").join("release").join("libagent.so")
|
||||
};
|
||||
let chosen = if release.is_file() {
|
||||
release
|
||||
// Prefer the debug artifact we just built; only fall back to release if
|
||||
// debug is missing (or release is strictly newer — local release workflows).
|
||||
let chosen = if lib.is_file() {
|
||||
if release.is_file() {
|
||||
let lib_m = std::fs::metadata(&lib).and_then(|m| m.modified()).ok();
|
||||
let rel_m = std::fs::metadata(&release).and_then(|m| m.modified()).ok();
|
||||
match (lib_m, rel_m) {
|
||||
(Some(l), Some(r)) if r > l => release,
|
||||
_ => lib,
|
||||
}
|
||||
} else {
|
||||
lib
|
||||
}
|
||||
} else {
|
||||
lib
|
||||
release
|
||||
};
|
||||
assert!(chosen.is_file(), "missing agent plugin at {}", chosen.display());
|
||||
// SAFETY: single-threaded Once; children inherit for the rest of the test process.
|
||||
@@ -2502,6 +2513,39 @@ mcp-fn-ok",
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ext_agent_mcp_client() {
|
||||
ensure_agent_plugin_built();
|
||||
assert_out(
|
||||
"tests/ext/agent-mcp-client.mq.md",
|
||||
"mcp-client-list-ok
|
||||
mcp-client-call-ok",
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ext_agent_resume() {
|
||||
ensure_agent_plugin_built();
|
||||
assert_out(
|
||||
"tests/ext/agent-resume.mq.md",
|
||||
"resume-save-ok
|
||||
resume-load-ok
|
||||
resume-list-ok
|
||||
resume-clear-ok
|
||||
resume-gone-ok",
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ext_agent_small_llm_route() {
|
||||
ensure_agent_plugin_built();
|
||||
assert_out(
|
||||
"tests/ext/agent-small-llm-route.mq.md",
|
||||
"small-llm-ok
|
||||
jev-alias-ok",
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ext_web_security_smoke() {
|
||||
ensure_web_plugin_built();
|
||||
|
||||
Reference in new issue
Block a user