Move LLM and agent into ext/ai with host tool catalog and call_fn.

Consolidate official AI extensions under ext/ai/, add agent history/context host APIs, dynamic call_fn, and a first-pass TOOL:name loop so runbooks can list zero-arg tools in a table.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
cflmyandCursor committed 2026-08-06 15:28:39 +08:00
1 parent c4ffb9473f
commit 92d88fe761
29 files changed
+1019 -558

No files matched your search

-35
View File
@@ -1,35 +0,0 @@
---
title: ext/agent match and assign
description: Multi-column tables + skill match (needs MARQDO_AGENT_PLUGIN).
> ext/agent.mq.md
---
# main
> load_native
*`cwd` = > cwd *
*`bot` = > agent root=`cwd` *
`技能表` =
| 成员 | 技能 | 负载 |
|------|------|------|
| 张三 | Python, ML | 2 |
| 李四 | 前端, UX | 1 |
| 王五 | 后端, 运维 | 3 |
| 赵六 | 数据分析 | 0 |
*`m` = > `bot`.match_skill skill=Python members=`技能表` *
*`name` = > get value=`m` key=成员 *
> print text=`name`
*`m2` = > `bot`.match_skill skill=安全审计 members=`技能表` *
+ `m2`
> print text=unexpected-match
+ *
*`path` = > `bot`.create_ticket title=no_owner detail=security *
> print text=`path`
*`m3` = > `bot`.update_load member=`m` delta=1 *
*`load` = > get value=`m3` key=负载 *
> print text=`load`
+40
View File
@@ -0,0 +1,40 @@
---
title: ext/agent run live (DeepSeek)
description: Real 执行 via tests/ext/.env (gitignored). Skipped in CI when .env missing.
> ext/ai/agent.mq.md
> lib/time.mq.md
---
## 获取时间
*`u` = > now_unix *
**> format unix=`u` pattern=%Y%m%d **
# main
> load_env
*`模型` = > llm *
`工具表` =
| 工具 |
|------|
| 获取时间 |
*`助手` = > agent model=`模型` tools=`工具表` user_prompt=你是测试助手。需要工具时,必须只回复一行 TOOL:函数名,不要其它文字。 *
*`id` = > get value=`助手` key=id *
*`回复` = > `助手`.run extra=请调用获取时间工具,并把当前日期告诉用户。 *
> print text=`回复`
*`历史1` = > host_agent_history_get id=`id` *
*`条数1` = > len value=`历史1` *
> print text=`条数1`
> `助手`.clear_history
*`历史2` = > host_agent_history_get id=`id` *
*`条数2` = > len value=`历史2` *
> print text=`条数2`
-30
View File
@@ -1,30 +0,0 @@
---
title: ext/agent layout scaffold
description: Requires MARQDO_AGENT_PLUGIN (set by gold harness).
> ext/agent.mq.md
> lib/fs.mq.md
---
# main
> load_native
*`cwd` = > cwd *
*`ws` = > agent root=`cwd` *
*`_n` = > `ws`.ensure_layout *
*`info` = > `ws`.probe *
*`ok` = > get value=`info` key=has_agents *
> print text=`ok`
> write_text path=skel.mq.md text={{name}}
*`_p` = > `ws`.scaffold name=demo template=skel.mq.md dest=out-demo.mq.md *
*`body` = > read_text path=out-demo.mq.md *
> print text=`body`
+60
View File
@@ -0,0 +1,60 @@
---
title: ext/agent framework smoke (offline)
description: Ctor, context, clear_history — no network. Gold suite.
> ext/ai/agent.mq.md
---
# main
`工具表` =
| 工具 |
|------|
| 获取时间 |
*`占位模型` = > parse text={"_type":"llm"} *
*`助手` = > agent model=`占位模型` tools=`工具表` user_prompt=you are a dispatcher *
*`id` = > get value=`助手` key=id *
*`ctx` = > build_agent_context agent=`助手` extra=probe *
*`has_skill` = > split value=`ctx` sep=Marqdo *
*`sk_n` = > len value=`has_skill` *
+ `sk_n` > 1
> print text=skill-ok
+ *
> print text=skill-missing
*`has_tools` = > split value=`ctx` sep=获取时间 *
*`tool_n` = > len value=`has_tools` *
+ `tool_n` > 1
> print text=tools-ok
+ *
> print text=tools-missing
*`src` = > host_module_source *
*`has_src` = > split value=`src` sep=probe *
*`src_n` = > len value=`has_src` *
+ `src_n` > 1
> print text=source-ok
+ *
> print text=source-missing
*`turn` = > parse text={"role":"user","content":"one"} *
> host_agent_history_append id=`id` item=`turn`
*`turn2` = > parse text={"role":"assistant","content":"two"} *
> host_agent_history_append id=`id` item=`turn2`
*`h1` = > host_agent_history_get id=`id` *
*`n1` = > len value=`h1` *
> print text=`n1`
> `助手`.clear_history
*`h2` = > host_agent_history_get id=`id` *
*`n2` = > len value=`h2` *
> print text=`n2`
*`site` = > host_call_site *
*`fn` = > get value=`site` key=function *
> print text=`fn`
+1 -1
View File
@@ -1,7 +1,7 @@
---
title: ext llm DeepSeek complete (live)
description: Live OpenAI-compatible chat via DeepSeek. Needs tests/ext/.env (gitignored). Not in gold suite.
> ext/llm.mq.md
> ext/ai/llm.mq.md
---
# main
+1 -1
View File
@@ -1,6 +1,6 @@
---
title: ext llm import
> ext/llm.mq.md
> ext/ai/llm.mq.md
---
# main
+37 -90
View File
@@ -642,7 +642,7 @@ fn lib_plugin_demo() {
fn ext_cli_add_list_remove_llm() {
let tmp = tempfile_dir("marqdo-ext-cli");
let src = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("ext");
assert!(src.join("llm.mq.md").is_file());
assert!(src.join("ai").join("llm.mq.md").is_file());
let bin = env!("CARGO_BIN_EXE_marqdo");
let status = Command::new(bin)
@@ -654,8 +654,8 @@ fn ext_cli_add_list_remove_llm() {
.status()
.expect("ext add");
assert!(status.success(), "ext add llm failed");
assert!(tmp.join("llm.mq.md").is_file());
assert!(tmp.join("大模型.mq.md").is_file());
assert!(tmp.join("ai").join("llm.mq.md").is_file());
assert!(tmp.join("ai").join("大模型.mq.md").is_file());
let out = Command::new(bin)
.args(["ext", "list"])
@@ -669,7 +669,7 @@ fn ext_cli_add_list_remove_llm() {
let mq = tmp.join("smoke.mq.md");
std::fs::write(
&mq,
"---\n> ext/llm.mq.md\n---\n\n# main\n\n> print text=ext-cli-ok\n",
"---\n> ext/ai/llm.mq.md\n---\n\n# main\n\n> print text=ext-cli-ok\n",
)
.unwrap();
let run = Command::new(bin)
@@ -694,17 +694,11 @@ fn ext_cli_add_list_remove_llm() {
.status()
.expect("ext remove");
assert!(status.success());
assert!(!tmp.join("llm.mq.md").is_file());
assert!(!tmp.join("ai").join("llm.mq.md").is_file());
}
#[test]
fn ext_cli_add_agent_with_native() {
let status = Command::new(env!("CARGO"))
.args(["build", "-p", "marqdo_plugin_agent"])
.status()
.expect("build agent plugin");
assert!(status.success());
fn ext_cli_add_agent() {
let tmp = tempfile_dir("marqdo-ext-agent");
let src = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("ext");
let bin = env!("CARGO_BIN_EXE_marqdo");
@@ -716,99 +710,52 @@ fn ext_cli_add_agent_with_native() {
.status()
.expect("ext add agent");
assert!(status.success(), "ext add agent failed");
assert!(tmp.join("agent.mq.md").is_file());
let lib_name = if cfg!(windows) {
"agent.dll"
} else if cfg!(target_os = "macos") {
"libagent.dylib"
} else {
"libagent.so"
};
assert!(tmp.join("native").join(lib_name).is_file());
assert!(tmp.join("agent.plugin").is_file());
assert!(tmp.join("ai").join("agent.mq.md").is_file());
assert!(tmp.join("ai").join("智能体.mq.md").is_file());
}
#[test]
fn ext_agent_assign() {
let status = Command::new(env!("CARGO"))
.args(["build", "-p", "marqdo_plugin_agent"])
.status()
.expect("cargo build plugin agent");
assert!(status.success(), "failed to build marqdo_plugin_agent");
let lib_name = if cfg!(windows) {
"agent.dll"
} else if cfg!(target_os = "macos") {
"libagent.dylib"
} else {
"libagent.so"
};
let built = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR"))
.join("target")
.join("debug")
.join(lib_name);
let ext_dir = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR"))
.join("tests")
.join("ext");
let plugin = ext_dir.join(lib_name);
std::fs::copy(&built, &plugin).expect("copy agent plugin");
let _ = std::fs::remove_file(ext_dir.join("ticket.txt"));
let _ = std::fs::remove_file(ext_dir.join("ticket-stub.txt"));
fn ext_agent_framework_smoke() {
let output = Command::new(env!("CARGO_BIN_EXE_marqdo"))
.args(["run", "tests/ext/agent-assign.mq.md"])
.env("MARQDO_AGENT_PLUGIN", lib_name)
.args(["run", "tests/ext/agent-smoke.mq.md"])
.output()
.expect("run agent-assign");
.expect("run agent-smoke");
let code = output.status.code().unwrap_or(1);
let stdout = String::from_utf8_lossy(&output.stdout);
let stderr = String::from_utf8_lossy(&output.stderr);
assert_eq!(code, 0, "agent-assign stderr={stderr}");
assert_eq!(stdout.trim_end(), "张三\nticket.txt\n3", "agent-assign");
}
#[test]
fn ext_agent_scaffold() {
let status = Command::new(env!("CARGO"))
.args(["build", "-p", "marqdo_plugin_agent"])
.status()
.expect("cargo build plugin agent");
assert!(status.success(), "failed to build marqdo_plugin_agent");
let lib_name = if cfg!(windows) {
"agent.dll"
} else if cfg!(target_os = "macos") {
"libagent.dylib"
} else {
"libagent.so"
};
let built = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR"))
.join("target")
.join("debug")
.join(lib_name);
assert!(
built.is_file(),
"missing plugin artifact {}",
built.display()
assert_eq!(code, 0, "agent-smoke stderr={stderr}");
assert_eq!(
stdout.trim_end(),
"skill-ok\ntools-ok\nsource-ok\n2\n0\nmain",
"agent-smoke"
);
let ext_dir = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR"))
.join("tests")
.join("ext");
let plugin = ext_dir.join(lib_name);
std::fs::copy(&built, &plugin).expect("copy agent plugin into tests/ext");
let _ = std::fs::remove_file(ext_dir.join("skel.mq.md"));
let _ = std::fs::remove_file(ext_dir.join("out-demo.mq.md"));
}
#[test]
fn ext_agent_run_live() {
let env_file = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("tests/ext/.env");
if !env_file.is_file() {
eprintln!("skip ext_agent_run_live: missing {}", env_file.display());
return;
}
let output = Command::new(env!("CARGO_BIN_EXE_marqdo"))
.args(["run", "tests/ext/agent-scaffold.mq.md"])
.env("MARQDO_AGENT_PLUGIN", lib_name)
.args(["run", "tests/ext/agent-run-live.mq.md"])
.output()
.expect("failed to run marqdo");
.expect("run agent-run-live");
let code = output.status.code().unwrap_or(1);
let stdout = String::from_utf8_lossy(&output.stdout);
let stderr = String::from_utf8_lossy(&output.stderr);
assert_eq!(code, 0, "agent-scaffold stderr={stderr}");
assert_eq!(stdout.trim_end(), "True\ndemo", "agent-scaffold");
assert_eq!(code, 0, "agent-run-live stderr={stderr}");
let lines: Vec<&str> = stdout.trim_end().lines().collect();
assert!(lines.len() >= 3, "agent-run-live stdout={stdout}");
assert!(
lines[0].contains('-') && lines[0].chars().any(|c| c.is_ascii_digit()),
"expected time in reply, got {:?}",
lines[0]
);
assert_eq!(lines[1], "2", "history after run");
assert_eq!(lines[2], "0", "history after clear");
}
#[test]
+1
View File
@@ -0,0 +1 @@
MARQDO_DOTENV_FIXTURE=loaded