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:
1 parent
c4ffb9473f
commit
92d88fe761
29 files changed
+1019
-558
No files matched your search
-117
@@ -1,117 +0,0 @@
|
||||
---
|
||||
title: ext/agent
|
||||
description: Agent development framework (layout ABI + match/assign). Compose with ext/llm.
|
||||
> lib/plugin.mq.md
|
||||
> ext/llm.mq.md
|
||||
---
|
||||
|
||||
## load_native
|
||||
|
||||
Load `plugins/agent` shared library. Order: env `MARQDO_AGENT_PLUGIN`, then `marqdo ext add agent` (`host_ext_native_path`).
|
||||
|
||||
*`envp` = > env_get name=MARQDO_AGENT_PLUGIN *
|
||||
+ `envp`
|
||||
**> load path=`envp`**
|
||||
+ *
|
||||
*`np` = > host_ext_native_path name=agent *
|
||||
+ `np`
|
||||
**> load path=`np`**
|
||||
+ *
|
||||
> print text=ext/agent: set MARQDO_AGENT_PLUGIN or run marqdo ext add agent
|
||||
> exit code=1
|
||||
|
||||
# agent
|
||||
- root
|
||||
|
||||
Workspace handle. Optional `root=`; else `agent_find_root` from cwd.
|
||||
|
||||
+ `root`
|
||||
*`r` = `root`*
|
||||
+ *
|
||||
*`start` = > cwd *
|
||||
*`r` = > agent_find_root start=`start` markers=agents,runbooks,marqdo.agent.json *
|
||||
|
||||
*`t` = > parse text={"p":"{\"_type\":\"agent\",\"root\":","s":"}"} *
|
||||
*`qr` = > quote text=`r` *
|
||||
*`p` = > get value=`t` key=p *
|
||||
*`s` = > get value=`t` key=s *
|
||||
*`raw` = `p` + `qr` + `s` *
|
||||
**> parse text=`raw`**
|
||||
|
||||
## probe
|
||||
|
||||
*`root` = > get value=`self` key=root *
|
||||
**> agent_probe root=`root`**
|
||||
|
||||
## ensure_layout
|
||||
|
||||
*`root` = > get value=`self` key=root *
|
||||
**> agent_ensure_layout root=`root`**
|
||||
|
||||
## scaffold
|
||||
- name
|
||||
- template
|
||||
- dest
|
||||
|
||||
*`root` = > get value=`self` key=root *
|
||||
**> agent_scaffold root=`root` name=`name` template=`template` dest=`dest`**
|
||||
|
||||
## match_skill
|
||||
- skill
|
||||
- members
|
||||
|
||||
Deterministic skill match over a list of member maps (`技能`/`skills`, `负载`/`load`). Picks lowest load among matches. Returns member map or `None`.
|
||||
|
||||
**> agent_match_skill skill=`skill` members=`members`**
|
||||
|
||||
## assign_task
|
||||
- task_id
|
||||
- assignee
|
||||
|
||||
Record a successful assignment (map). Caller updates load separately.
|
||||
|
||||
*`t` = > parse text={"p":"{\"success\":true,\"task_id\":","m":",\"assignee\":","s":"}"} *
|
||||
*`qid` = > quote text=`task_id` *
|
||||
*`qa` = > stringify value=`assignee` *
|
||||
*`p` = > get value=`t` key=p *
|
||||
*`m` = > get value=`t` key=m *
|
||||
*`s` = > get value=`t` key=s *
|
||||
*`raw` = `p` + `qid` + `m` + `qa` + `s` *
|
||||
**> parse text=`raw`**
|
||||
|
||||
## update_load
|
||||
- member
|
||||
- delta
|
||||
|
||||
**> agent_bump_load member=`member` delta=`delta`**
|
||||
|
||||
## create_ticket
|
||||
- title
|
||||
- detail
|
||||
|
||||
Stub ticket: ensure layout, write `ticket-stub.txt` under cwd (sandbox). Returns the filename.
|
||||
|
||||
*`_n` = > `self`.ensure_layout *
|
||||
*`body` = `title` *
|
||||
*`out` = ticket.txt *
|
||||
> host_write_text path=ticket.txt text=`body`
|
||||
**`out`**
|
||||
|
||||
## notify
|
||||
- to
|
||||
- text
|
||||
|
||||
Stub channel: print a notification line.
|
||||
|
||||
> print text=notify
|
||||
> print text=`to`
|
||||
> print text=`text`
|
||||
****
|
||||
|
||||
## draft_message
|
||||
- model
|
||||
- prompt
|
||||
|
||||
Optional LLM helper: `model` is an `ext/llm` handle.
|
||||
|
||||
**> `model`.complete prompt=`prompt`**
|
||||
@@ -0,0 +1,111 @@
|
||||
---
|
||||
title: ext/ai/agent
|
||||
description: Thin agent framework — ctor, run, clear_history only.
|
||||
> ext/ai/llm.mq.md
|
||||
---
|
||||
|
||||
## build_agent_context
|
||||
- agent
|
||||
- extra
|
||||
|
||||
Internal: assemble prompt (user prompt, extra, tool list, source, call site, history, Marqdo skill).
|
||||
|
||||
*`user_prompt` = > get value=`agent` key=user_prompt *
|
||||
+ `user_prompt`
|
||||
*`up` = `user_prompt`*
|
||||
+ *
|
||||
*`up` = None*
|
||||
|
||||
*`tools` = > get value=`agent` key=tools *
|
||||
*`tools_s` = > host_format_tools_for_llm tools=`tools` *
|
||||
*`src` = > host_module_source *
|
||||
*`site` = > host_call_site *
|
||||
*`site_s` = > stringify value=`site` *
|
||||
*`id` = > get value=`agent` key=id *
|
||||
*`hist` = > host_agent_history_get id=`id` *
|
||||
*`hist_s` = > stringify value=`hist` *
|
||||
*`skill` = > host_marqdo_skill *
|
||||
*`extra_s` = > stringify value=`extra` *
|
||||
|
||||
*`sep` = > parse text={"a":"\n\n--- standing ---\n","b":"\n\n--- extra ---\n","c":"\n\n--- tools ---\n","d":"\n\n--- call site ---\n","e":"\n\n--- source ---\n","f":"\n\n--- history ---\n","g":"\n\n--- marqdo skill ---\n"} *
|
||||
*`a` = > get value=`sep` key=a *
|
||||
*`b` = > get value=`sep` key=b *
|
||||
*`c` = > get value=`sep` key=c *
|
||||
*`d` = > get value=`sep` key=d *
|
||||
*`e` = > get value=`sep` key=e *
|
||||
*`f` = > get value=`sep` key=f *
|
||||
*`g` = > get value=`sep` key=g *
|
||||
|
||||
*`tool_proto` = \n\n--- tool protocol ---\nEach tool is a zero-arg Marqdo function in this module (see tools list). To call one, reply with exactly one line: TOOL:<name>. No other text on that line.\nAfter the tool runs you will get its output and should answer the user.\n *
|
||||
|
||||
*`p` = You are a Marqdo agent. Follow Marqdo skill rules when reading or writing .mq.md. *
|
||||
*`p` = `p` + `a` + `up` + `b` + `extra_s` + `c` + `tool_proto` + `tools_s` + `d` + `site_s` + `e` + `src` + `f` + `hist_s` + `g` + `skill` *
|
||||
**`p`**
|
||||
|
||||
# agent
|
||||
- model
|
||||
- tools
|
||||
- user_prompt
|
||||
|
||||
*`id` = > host_agent_alloc *
|
||||
*`h` = > parse text={"_type":"agent"} *
|
||||
*`h` = > map_set map=`h` key=id value=`id` *
|
||||
*`h` = > map_set map=`h` key=model value=`model` *
|
||||
*`h` = > map_set map=`h` key=tools value=`tools` *
|
||||
|
||||
+ `user_prompt`
|
||||
*`h` = > map_set map=`h` key=user_prompt value=`user_prompt` *
|
||||
+ *
|
||||
*`_` = 1*
|
||||
|
||||
**`h`**
|
||||
|
||||
## clear_history
|
||||
|
||||
*`id` = > get value=`self` key=id *
|
||||
> host_agent_history_clear id=`id`
|
||||
****
|
||||
|
||||
## run
|
||||
- extra
|
||||
|
||||
*`ctx` = > build_agent_context agent=`self` extra=`extra` *
|
||||
*`id` = > get value=`self` key=id *
|
||||
|
||||
*`user_turn` = > parse text={"role":"user"} *
|
||||
*`user_turn` = > map_set map=`user_turn` key=content value=`extra` *
|
||||
> host_agent_history_append id=`id` item=`user_turn`
|
||||
|
||||
*`model` = > get value=`self` key=model *
|
||||
*`reply` = > `model`.complete prompt=`ctx` *
|
||||
*`tools` = > get value=`self` key=tools *
|
||||
*`reply` = > trim value=`reply` *
|
||||
|
||||
*`parts` = > split value=`reply` sep=: *
|
||||
*`head` = > at value=`parts` index=0 *
|
||||
*`tool_name` = > at value=`parts` index=1 *
|
||||
*`tool_name` = > trim value=`tool_name` *
|
||||
|
||||
+ `head` == TOOL
|
||||
*`allowed` = > host_tool_allowed tools=`tools` name=`tool_name` *
|
||||
+ `allowed`
|
||||
*`tool_out` = > call_fn name=`tool_name` *
|
||||
*`tool_s` = > stringify value=`tool_out` *
|
||||
*`extra_s` = > stringify value=`extra` *
|
||||
*`fp` = The user asked: *
|
||||
*`fp` = `fp` + `extra_s` *
|
||||
*`fp` = `fp` + . You invoked tool *
|
||||
*`fp` = `fp` + `tool_name` *
|
||||
*`fp` = `fp` + which returned: *
|
||||
*`fp` = `fp` + `tool_s` *
|
||||
*`fp` = `fp` + . Reply to the user in one brief sentence. *
|
||||
*`reply` = > `model`.complete prompt=`fp` *
|
||||
+ *
|
||||
*`reply` = Tool not allowed: `tool_name` *
|
||||
+ *
|
||||
*`_` = 1*
|
||||
|
||||
*`as_turn` = > parse text={"role":"assistant"} *
|
||||
*`as_turn` = > map_set map=`as_turn` key=content value=`reply` *
|
||||
> host_agent_history_append id=`id` item=`as_turn`
|
||||
**`reply`**
|
||||
@@ -1,6 +1,6 @@
|
||||
---
|
||||
title: ext/llm
|
||||
description: Official OpenAI-compatible LLM object (English). Not stdlib — import ext/llm.mq.md.
|
||||
title: ext/ai/llm
|
||||
description: OpenAI-compatible LLM object (English). Import ext/ai/llm.mq.md.
|
||||
> lib/sys.mq.md
|
||||
> lib/net.mq.md
|
||||
> lib/json.mq.md
|
||||
@@ -26,7 +26,7 @@ Construct an LLM handle from `OPENAI_*` / `MARQDO_LLM_*` (default base OpenAI v1
|
||||
+ `api_key`
|
||||
*`_k` = 1*
|
||||
+ *
|
||||
> print text=ext/llm: set OPENAI_API_KEY or MARQDO_LLM_API_KEY
|
||||
> print text=ext/ai/llm: set OPENAI_API_KEY or MARQDO_LLM_API_KEY
|
||||
> exit code=1
|
||||
|
||||
*`base_url` = > env_get name=OPENAI_BASE_URL *
|
||||
@@ -115,7 +115,7 @@ Chat completion using `self` / `自` handle fields.
|
||||
*`content` = > get value=`message` key=content *
|
||||
**`content`**
|
||||
+ *
|
||||
> print text=ext/llm: HTTP error
|
||||
> print text=ext/ai/llm: HTTP error
|
||||
> print text=`status`
|
||||
> print text=`raw`
|
||||
> exit code=1
|
||||
@@ -1,6 +1,6 @@
|
||||
---
|
||||
title: ext/大模型
|
||||
description: 官方 OpenAI 兼容大模型对象(中文)。非标准库 — 导入 ext/大模型.mq.md。
|
||||
title: ext/ai/大模型
|
||||
description: OpenAI 兼容大模型对象(中文)。导入 ext/ai/大模型.mq.md。
|
||||
> lib/系统.mq.md
|
||||
> lib/网络.mq.md
|
||||
> lib/json.mq.md
|
||||
@@ -26,7 +26,7 @@ description: 官方 OpenAI 兼容大模型对象(中文)。非标准库 —
|
||||
+ `api_key`
|
||||
*`_k` = 1*
|
||||
+ *
|
||||
> 打印 内容=ext/大模型: 请设置 OPENAI_API_KEY 或 MARQDO_LLM_API_KEY
|
||||
> 打印 内容=ext/ai/大模型: 请设置 OPENAI_API_KEY 或 MARQDO_LLM_API_KEY
|
||||
> 退出 码=1
|
||||
|
||||
*`base_url` = > 取环境 名=OPENAI_BASE_URL *
|
||||
@@ -115,7 +115,7 @@ description: 官方 OpenAI 兼容大模型对象(中文)。非标准库 —
|
||||
*`content` = > get value=`message` key=content *
|
||||
**`content`**
|
||||
+ *
|
||||
> 打印 内容=ext/大模型: HTTP 错误
|
||||
> 打印 内容=ext/ai/大模型: HTTP 错误
|
||||
> 打印 内容=`status`
|
||||
> 打印 内容=`raw`
|
||||
> 退出 码=1
|
||||
@@ -0,0 +1,111 @@
|
||||
---
|
||||
title: ext/ai/智能体
|
||||
description: 薄智能体框架 — 仅构造、执行、清空历史。
|
||||
> ext/ai/大模型.mq.md
|
||||
---
|
||||
|
||||
## 构建上下文
|
||||
- 智能体
|
||||
- 额外信息
|
||||
|
||||
内部:组装提示(用户提示、额外信息、工具列表、源码、位置、历史、Marqdo skill)。
|
||||
|
||||
*`user_prompt` = > get value=`智能体` key=user_prompt *
|
||||
+ `user_prompt`
|
||||
*`up` = `user_prompt`*
|
||||
+ *
|
||||
*`up` = 空*
|
||||
|
||||
*`tools` = > get value=`智能体` key=tools *
|
||||
*`tools_s` = > host_format_tools_for_llm tools=`tools` *
|
||||
*`src` = > host_module_source *
|
||||
*`site` = > host_call_site *
|
||||
*`site_s` = > stringify value=`site` *
|
||||
*`id` = > get value=`智能体` key=id *
|
||||
*`hist` = > host_agent_history_get id=`id` *
|
||||
*`hist_s` = > stringify value=`hist` *
|
||||
*`skill` = > host_marqdo_skill *
|
||||
*`extra_s` = > stringify value=`额外信息` *
|
||||
|
||||
*`sep` = > parse text={"a":"\n\n--- standing ---\n","b":"\n\n--- extra ---\n","c":"\n\n--- tools ---\n","d":"\n\n--- call site ---\n","e":"\n\n--- source ---\n","f":"\n\n--- history ---\n","g":"\n\n--- marqdo skill ---\n"} *
|
||||
*`a` = > get value=`sep` key=a *
|
||||
*`b` = > get value=`sep` key=b *
|
||||
*`c` = > get value=`sep` key=c *
|
||||
*`d` = > get value=`sep` key=d *
|
||||
*`e` = > get value=`sep` key=e *
|
||||
*`f` = > get value=`sep` key=f *
|
||||
*`g` = > get value=`sep` key=g *
|
||||
|
||||
*`tool_proto` = \n\n--- tool protocol ---\nEach tool is a zero-arg Marqdo function in this module (see tools list). To call one, reply with exactly one line: TOOL:<name>. No other text on that line.\nAfter the tool runs you will get its output and should answer the user.\n *
|
||||
|
||||
*`p` = You are a Marqdo agent. Follow Marqdo skill rules when reading or writing .mq.md. *
|
||||
*`p` = `p` + `a` + `up` + `b` + `extra_s` + `c` + `tool_proto` + `tools_s` + `d` + `site_s` + `e` + `src` + `f` + `hist_s` + `g` + `skill` *
|
||||
**`p`**
|
||||
|
||||
# 智能体
|
||||
- 大模型
|
||||
- 工具
|
||||
- 用户提示信息
|
||||
|
||||
*`id` = > host_agent_alloc *
|
||||
*`h` = > parse text={"_type":"智能体"} *
|
||||
*`h` = > map_set map=`h` key=id value=`id` *
|
||||
*`h` = > map_set map=`h` key=model value=`大模型` *
|
||||
*`h` = > map_set map=`h` key=tools value=`工具` *
|
||||
|
||||
+ `用户提示信息`
|
||||
*`h` = > map_set map=`h` key=user_prompt value=`用户提示信息` *
|
||||
+ *
|
||||
*`_` = 1*
|
||||
|
||||
**`h`**
|
||||
|
||||
## 清空历史
|
||||
|
||||
*`id` = > get value=`自` key=id *
|
||||
> host_agent_history_clear id=`id`
|
||||
****
|
||||
|
||||
## 执行
|
||||
- 额外信息
|
||||
|
||||
*`ctx` = > 构建上下文 智能体=`自` 额外信息=`额外信息` *
|
||||
*`id` = > get value=`自` key=id *
|
||||
|
||||
*`user_turn` = > parse text={"role":"user"} *
|
||||
*`user_turn` = > map_set map=`user_turn` key=content value=`额外信息` *
|
||||
> host_agent_history_append id=`id` item=`user_turn`
|
||||
|
||||
*`model` = > get value=`自` key=model *
|
||||
*`reply` = > `model`.运行 提示=`ctx` *
|
||||
*`tools` = > get value=`自` key=tools *
|
||||
*`reply` = > trim value=`reply` *
|
||||
|
||||
*`parts` = > split value=`reply` sep=: *
|
||||
*`head` = > at value=`parts` index=0 *
|
||||
*`tool_name` = > at value=`parts` index=1 *
|
||||
*`tool_name` = > trim value=`tool_name` *
|
||||
|
||||
+ `head` == TOOL
|
||||
*`allowed` = > host_tool_allowed tools=`tools` name=`tool_name` *
|
||||
+ `allowed`
|
||||
*`tool_out` = > 调用 名=`tool_name` *
|
||||
*`tool_s` = > stringify value=`tool_out` *
|
||||
*`extra_s` = > stringify value=`额外信息` *
|
||||
*`fp` = The user asked: *
|
||||
*`fp` = `fp` + `extra_s` *
|
||||
*`fp` = `fp` + . You invoked tool *
|
||||
*`fp` = `fp` + `tool_name` *
|
||||
*`fp` = `fp` + which returned: *
|
||||
*`fp` = `fp` + `tool_s` *
|
||||
*`fp` = `fp` + . Reply to the user in one brief sentence. *
|
||||
*`reply` = > `model`.运行 提示=`fp` *
|
||||
+ *
|
||||
*`reply` = Tool not allowed: `tool_name` *
|
||||
+ *
|
||||
*`_` = 1*
|
||||
|
||||
*`as_turn` = > parse text={"role":"assistant"} *
|
||||
*`as_turn` = > map_set map=`as_turn` key=content value=`reply` *
|
||||
> host_agent_history_append id=`id` item=`as_turn`
|
||||
**`reply`**
|
||||
-105
@@ -1,105 +0,0 @@
|
||||
---
|
||||
title: ext/智能体
|
||||
description: 智能体开发框架(布局 ABI + 匹配/派发)。可组合 ext/大模型。
|
||||
> lib/插件.mq.md
|
||||
> ext/大模型.mq.md
|
||||
---
|
||||
|
||||
## 加载原生
|
||||
|
||||
加载 `plugins/agent`。顺序:`MARQDO_AGENT_PLUGIN`,否则 `marqdo ext add agent`。
|
||||
|
||||
*`环境路径` = > 取环境 名=MARQDO_AGENT_PLUGIN *
|
||||
+ `环境路径`
|
||||
**> 加载 路径=`环境路径`**
|
||||
+ *
|
||||
*`原生` = > host_ext_native_path name=agent *
|
||||
+ `原生`
|
||||
**> 加载 路径=`原生`**
|
||||
+ *
|
||||
> 打印 内容=ext/智能体: 请设置 MARQDO_AGENT_PLUGIN 或执行 marqdo ext add agent
|
||||
> 退出 码=1
|
||||
|
||||
# 智能体
|
||||
- 根
|
||||
|
||||
+ `根`
|
||||
*`r` = `根`*
|
||||
+ *
|
||||
*`起点` = > 工作目录 *
|
||||
*`r` = > agent_find_root start=`起点` markers=agents,runbooks,marqdo.agent.json *
|
||||
|
||||
*`t` = > parse text={"p":"{\"_type\":\"智能体\",\"root\":","s":"}"} *
|
||||
*`qr` = > quote text=`r` *
|
||||
*`p` = > get value=`t` key=p *
|
||||
*`s` = > get value=`t` key=s *
|
||||
*`raw` = `p` + `qr` + `s` *
|
||||
**> parse text=`raw`**
|
||||
|
||||
## 探测
|
||||
|
||||
*`root` = > get value=`自` key=root *
|
||||
**> agent_probe root=`root`**
|
||||
|
||||
## 确保布局
|
||||
|
||||
*`root` = > get value=`自` key=root *
|
||||
**> agent_ensure_layout root=`root`**
|
||||
|
||||
## 脚手架
|
||||
- 名
|
||||
- 模板
|
||||
- 目标
|
||||
|
||||
*`root` = > get value=`自` key=root *
|
||||
**> agent_scaffold root=`root` name=`名` template=`模板` dest=`目标`**
|
||||
|
||||
## 技能匹配
|
||||
- 技能
|
||||
- 成员表
|
||||
|
||||
**> agent_match_skill skill=`技能` members=`成员表`**
|
||||
|
||||
## 分配任务
|
||||
- 任务ID
|
||||
- 分配给
|
||||
|
||||
*`t` = > parse text={"p":"{\"success\":true,\"task_id\":","m":",\"assignee\":","s":"}"} *
|
||||
*`qid` = > quote text=`任务ID` *
|
||||
*`qa` = > stringify value=`分配给` *
|
||||
*`p` = > get value=`t` key=p *
|
||||
*`m` = > get value=`t` key=m *
|
||||
*`s` = > get value=`t` key=s *
|
||||
*`raw` = `p` + `qid` + `m` + `qa` + `s` *
|
||||
**> parse text=`raw`**
|
||||
|
||||
## 更新负载
|
||||
- 成员
|
||||
- 变化
|
||||
|
||||
**> agent_bump_load member=`成员` delta=`变化`**
|
||||
|
||||
## 创建工单
|
||||
- 标题
|
||||
- 详情
|
||||
|
||||
*`_n` = > `自`.确保布局 *
|
||||
*`body` = `标题` *
|
||||
*`out` = ticket.txt *
|
||||
> host_write_text path=ticket.txt text=`body`
|
||||
**`out`**
|
||||
|
||||
## 通知
|
||||
- 收件人
|
||||
- 内容
|
||||
|
||||
> 打印 内容=notify
|
||||
> 打印 内容=`收件人`
|
||||
> 打印 内容=`内容`
|
||||
****
|
||||
|
||||
## 起草消息
|
||||
- 模型
|
||||
- 提示
|
||||
|
||||
**> `模型`.运行 提示=`提示`**
|
||||
Reference in new issue
Block a user