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
@@ -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