feat(llm): sys.module_source + entry prompt / meta offline paths
Expose entry source via sys.module_source; ask/stream fall back to prompt_body of the entry document. Add meta-binding and entry-prompt golds. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
88dc6d5a54
commit
81a14f9b38
8 files changed
+117
-13
No files matched your search
@@ -31,7 +31,7 @@
|
||||
| `create` 工厂;handle 带 `backend` | **done** |
|
||||
| LLMResult:`text` / `model` / `finish` / `backend` / `usage` / `tokens` | **done** |
|
||||
| Named models(`llm.fast` / `llm.reasoning`) | **done** |
|
||||
| Prompt document:`prompt` / `prompt_load` + `type: prompt` 正文 | **done**(`llm.ask` 无参吃当前入口文档仍暂缓,需 `sys.module_source`) |
|
||||
| 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 | 暂缓 |
|
||||
| Transport → 可选 ABI 插件 | 暂缓 |
|
||||
@@ -65,11 +65,12 @@
|
||||
|
||||
1. **LLM Result → Agent metrics** — **done**
|
||||
2. **Named handles** — **done**
|
||||
3. **Prompt document** — **done**(`type: prompt` 剥 frontmatter;无参 `ask` 仍暂缓)
|
||||
3. **Prompt document** — **done**(`type: prompt` 剥 frontmatter;无参 `ask`/`stream` 经 `sys.module_source`)
|
||||
4. **Backend split** — **done**
|
||||
5. **Execution compilation** — **done**(`agent-zero-llm` 金样 + harness)
|
||||
6. **Metadata Binding** — **done**(Phase 1;`llm-meta-offline`)
|
||||
|
||||
## 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`
|
||||
- LLM:`tests/ext/llm-ask-offline.mq.md` · `llm-stream-offline.mq.md` · `llm-ctor-offline.mq.md` · `llm-named-offline.mq.md`
|
||||
- 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`
|
||||
+21
-9
@@ -151,15 +151,19 @@ Prompt artifact helper: `path=` loads a file; `text=` strips `type: prompt` fron
|
||||
+ `base_url`=None
|
||||
+ `api_key`=None
|
||||
|
||||
Module convenience: create a default handle and return **answer text**. Pass `path=` to load a prompt document, or `prompt=` text.
|
||||
Module convenience: create a default handle and return **answer text**. Pass `path=` to load a prompt document, `prompt=` text, or omit both to use the entry `.mq.md` as a prompt artifact (`type: prompt` body via `sys.module_source`).
|
||||
|
||||
1. `path`
|
||||
**p = > prompt_load path=`path`**
|
||||
2. `prompt`
|
||||
**p = prompt**
|
||||
3. *
|
||||
> print text=ext/ai/llm.ask: pass prompt= or path=
|
||||
> sys.exit code=1
|
||||
**raw = > sys.module_source**
|
||||
1. not `raw`
|
||||
> print text=ext/ai/llm.ask: pass prompt= or path= (or run a prompt document as entry)
|
||||
> sys.exit code=1
|
||||
2. *
|
||||
**p = > prompt_body src=`raw`**
|
||||
|
||||
**m = > create model=`model` base_url=`base_url` api_key=`api_key`**
|
||||
**r = > m.ask prompt=`p`**
|
||||
@@ -260,15 +264,19 @@ Resolution: explicit args → entry Artifact Metadata (`sys.meta_get`) → `sys.
|
||||
+ `prompt`=None
|
||||
+ `path`=None
|
||||
|
||||
Semantic ask → **LLMResult** (`text`, `model`, `finish`, `backend`, `usage`, `name`). Prefer `[text](result)` for the answer string.
|
||||
Semantic ask → **LLMResult** (`text`, `model`, `finish`, `backend`, `usage`, `name`). Prefer `[text](result)` for the answer string. Omit `prompt=` / `path=` to use the entry document (`sys.module_source` + `prompt_body`).
|
||||
|
||||
1. `path`
|
||||
**p = > prompt_load path=`path`**
|
||||
2. `prompt`
|
||||
**p = prompt**
|
||||
3. *
|
||||
> print text=ext/ai/llm: ask needs prompt= or path=
|
||||
> sys.exit code=1
|
||||
**raw = > sys.module_source**
|
||||
1. not `raw`
|
||||
> print text=ext/ai/llm: ask needs prompt= or path= (or entry prompt document)
|
||||
> sys.exit code=1
|
||||
2. *
|
||||
**p = > prompt_body src=`raw`**
|
||||
|
||||
**pack = > self.complete_result prompt=`p` stream=False echo=False**
|
||||
**text = > json.get value=`pack` key="text"**
|
||||
@@ -288,15 +296,19 @@ Semantic ask → **LLMResult** (`text`, `model`, `finish`, `backend`, `usage`, `
|
||||
+ `path`=None
|
||||
+ `echo`=False
|
||||
|
||||
Semantic stream: return the event list (use `llm.collect` to reduce to text).
|
||||
Semantic stream: return the event list (use `llm.collect` to reduce to text). Omit `prompt=` / `path=` to use the entry document.
|
||||
|
||||
1. `path`
|
||||
**p = > prompt_load path=`path`**
|
||||
2. `prompt`
|
||||
**p = prompt**
|
||||
3. *
|
||||
> print text=ext/ai/llm: stream needs prompt= or path=
|
||||
> sys.exit code=1
|
||||
**raw = > sys.module_source**
|
||||
1. not `raw`
|
||||
> print text=ext/ai/llm: stream needs prompt= or path= (or entry prompt document)
|
||||
> sys.exit code=1
|
||||
2. *
|
||||
**p = > prompt_body src=`raw`**
|
||||
|
||||
*> self.complete prompt=`p` stream=True echo=`echo`*
|
||||
|
||||
|
||||
@@ -52,6 +52,12 @@ Lookup one metadata key; missing → None.
|
||||
|
||||
*> host_meta_get key=`key`*
|
||||
|
||||
## module_source
|
||||
|
||||
Entry `.mq.md` source text (for document-as-prompt). Empty string if unset.
|
||||
|
||||
*> host_module_source*
|
||||
|
||||
## exit
|
||||
+ `code`
|
||||
|
||||
|
||||
@@ -52,6 +52,12 @@ description: 中文系统包装(加载环境 可选 路径=)
|
||||
|
||||
*> host_meta_get key=`键`*
|
||||
|
||||
## 模块源码
|
||||
|
||||
入口 `.mq.md` 全文(供 document-as-prompt)。未设置时为空文本。
|
||||
|
||||
*> host_module_source*
|
||||
|
||||
## 退出
|
||||
+ `码`
|
||||
|
||||
|
||||
@@ -200,6 +200,7 @@ pub enum HostFn {
|
||||
StatsStdev = 191,
|
||||
Meta = 192,
|
||||
MetaGet = 193,
|
||||
ModuleSource = 194,
|
||||
}
|
||||
|
||||
|
||||
@@ -390,6 +391,7 @@ impl HostFn {
|
||||
191 => Self::StatsStdev,
|
||||
192 => Self::Meta,
|
||||
193 => Self::MetaGet,
|
||||
194 => Self::ModuleSource,
|
||||
_ => return None,
|
||||
})
|
||||
}
|
||||
@@ -583,6 +585,7 @@ impl HostFn {
|
||||
"host_stats_stdev" | "stats_stdev" => Self::StatsStdev,
|
||||
"host_meta" | "meta" => Self::Meta,
|
||||
"host_meta_get" | "meta_get" => Self::MetaGet,
|
||||
"host_module_source" | "module_source" => Self::ModuleSource,
|
||||
_ => return None,
|
||||
})
|
||||
}
|
||||
@@ -763,6 +766,7 @@ impl HostFn {
|
||||
Self::StatsStdev => "host_stats_stdev",
|
||||
Self::Meta => "host_meta",
|
||||
Self::MetaGet => "host_meta_get",
|
||||
Self::ModuleSource => "host_module_source",
|
||||
Self::WritebackRecord => "host_writeback_record",
|
||||
Self::WritebackGet => "host_writeback_get",
|
||||
Self::WritebackClear => "host_writeback_clear",
|
||||
@@ -786,7 +790,9 @@ impl HostFn {
|
||||
&["path"]
|
||||
}
|
||||
Self::WriteText | Self::AppendText => &["path", "text"],
|
||||
Self::NowUnix | Self::NowMs | Self::Args | Self::Cwd | Self::Meta => &[],
|
||||
Self::NowUnix | Self::NowMs | Self::Args | Self::Cwd | Self::Meta | Self::ModuleSource => {
|
||||
&[]
|
||||
}
|
||||
Self::FormatTime => &["unix", "pattern"],
|
||||
Self::ParseTime => &["text", "pattern"],
|
||||
Self::SleepMs => &["ms"],
|
||||
@@ -991,6 +997,7 @@ pub fn call_host(
|
||||
HostFn::Cwd => sys::cwd(ctx),
|
||||
HostFn::Meta => sys::meta(ctx),
|
||||
HostFn::MetaGet => sys::meta_get(ctx, require(bound, "key")?),
|
||||
HostFn::ModuleSource => crate::host::agent_rt::module_source(ctx),
|
||||
HostFn::Exit => sys::exit(ctx, require(bound, "code")?),
|
||||
HostFn::Exec => sys::exec(
|
||||
ctx,
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
---
|
||||
type: prompt
|
||||
title: entry prompt offline
|
||||
import llm:ext/ai/llm.mq.md
|
||||
import sys:lib/sys.mq.md
|
||||
---
|
||||
|
||||
Say hello to Marqdo.
|
||||
|
||||
# main
|
||||
|
||||
**raw = > sys.module_source**
|
||||
**p = > llm.prompt_body src=`raw`**
|
||||
> print text=`p`
|
||||
@@ -0,0 +1,14 @@
|
||||
---
|
||||
title: llm meta binding offline
|
||||
description: Create handle from Artifact Metadata (model / api_key); no network.
|
||||
type: llm
|
||||
model: ${env.MARQDO_LLM_META_MODEL ?? "meta-model"}
|
||||
api_key: ${secret.OPENAI_API_KEY ?? "sk-test"}
|
||||
import llm:ext/ai/llm.mq.md
|
||||
---
|
||||
|
||||
# main
|
||||
|
||||
**h = > llm.llm**
|
||||
> print text=[model](`h`)
|
||||
> print text=[api_key](`h`)
|
||||
@@ -3994,6 +3994,50 @@ fn ext_llm_ask_offline() {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ext_llm_meta_offline() {
|
||||
let root = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR"));
|
||||
let output = Command::new(env!("CARGO_BIN_EXE_marqdo"))
|
||||
.args(["run", "tests/ext/llm-meta-offline.mq.md"])
|
||||
.env("OPENAI_API_KEY", "sk-test")
|
||||
.env("MARQDO_EXT", root.join("ext"))
|
||||
.env_remove("OPENAI_MODEL")
|
||||
.env_remove("MARQDO_LLM_MODEL")
|
||||
.env_remove("MARQDO_LLM_META_MODEL")
|
||||
.current_dir(&root)
|
||||
.output()
|
||||
.expect("run llm-meta-offline");
|
||||
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, "llm-meta-offline stderr={stderr}");
|
||||
assert_eq!(
|
||||
stdout.trim_end(),
|
||||
"meta-model\n<secret>",
|
||||
"stdout={stdout}"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ext_llm_entry_prompt_offline() {
|
||||
let root = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR"));
|
||||
let output = Command::new(env!("CARGO_BIN_EXE_marqdo"))
|
||||
.args(["run", "tests/ext/llm-entry-prompt-offline.mq.md"])
|
||||
.env("MARQDO_EXT", root.join("ext"))
|
||||
.current_dir(&root)
|
||||
.output()
|
||||
.expect("run llm-entry-prompt-offline");
|
||||
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, "llm-entry-prompt-offline stderr={stderr}");
|
||||
assert_eq!(
|
||||
stdout.trim_end(),
|
||||
"Say hello to Marqdo.\n\n# main\n\n**raw = > sys.module_source**\n**p = > llm.prompt_body src=`raw`**\n> print text=`p`",
|
||||
"stdout={stdout}"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ext_llm_ctor_offline() {
|
||||
let root = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR"));
|
||||
|
||||
Reference in new issue
Block a user