mirror of
https://gitcode.com/JianFeeeee/HomeAgent.git
synced 2026-09-21 17:38:10 +00:00
docs+test: Lua stage 写回能力文档与测试(与 C ABI v2 对齐)
This commit is contained in:
@ -594,6 +594,21 @@ The `sdk.*` API of Lua plugins is fully aligned with external plugins (C ABI / t
|
||||
|
||||
Stage handlers receive the full context (same as external plugins): `raw_message`, `user_id`, `group_id`, `phase`, `llm_text`, `final_text`, `no_memory`, `response` (when responded), `tool_calls`, `tool_results`.
|
||||
|
||||
**Stage writeback (ABI v2)**: the `ctx` table passed to the handler is a reference — mutating writable fields inside the handler syncs back to the core `StageContext` (aligned with the C ABI v2 external-plugin capability):
|
||||
|
||||
```lua
|
||||
sdk.register_stage("on_input", function(ctx)
|
||||
ctx.raw_message = "[clean]" .. ctx.raw_message -- modify input, adopted by core
|
||||
end)
|
||||
|
||||
sdk.register_stage("post_action", function(ctx)
|
||||
ctx.llm_text = ctx.llm_text .. "[tail]" -- modify LLM output
|
||||
ctx.tool_results = { { call_id = "x", result = "rewritten" } }
|
||||
end)
|
||||
```
|
||||
|
||||
Writable fields: `raw_message`, `llm_text`, `final_text`, `user_id`, `group_id`, `no_memory`, `response`, `tool_calls`, `tool_results`. Other fields are read-only.
|
||||
|
||||
**IO and config**
|
||||
|
||||
| Function | Description |
|
||||
|
||||
@ -593,6 +593,21 @@ Lua 插件的 `sdk.*` API 与外部插件(C ABI / 工具链编译的 `.so`/`.d
|
||||
|
||||
`register_stage` 的 handler 收到完整上下文(与外部插件一致):`raw_message`、`user_id`、`group_id`、`phase`、`llm_text`、`final_text`、`no_memory`、`response`(已响应时)、`tool_calls`、`tool_results`。
|
||||
|
||||
**Stage 写回(ABI v2)**:handler 收到的 `ctx` 是引用 table——在 handler 内直接修改可写回字段并同步至内核 `StageContext`(与 C ABI v2 外部插件能力对齐):
|
||||
|
||||
```lua
|
||||
sdk.register_stage("on_input", function(ctx)
|
||||
ctx.raw_message = "[清洗]" .. ctx.raw_message -- 修改输入,内核会采用
|
||||
end)
|
||||
|
||||
sdk.register_stage("post_action", function(ctx)
|
||||
ctx.llm_text = ctx.llm_text .. "[尾部标记]" -- 修改 LLM 输出
|
||||
ctx.tool_results = { { call_id = "x", result = "改写结果" } } -- 改写工具结果
|
||||
end)
|
||||
```
|
||||
|
||||
可写回字段:`raw_message`、`llm_text`、`final_text`、`user_id`、`group_id`、`no_memory`、`response`、`tool_calls`、`tool_results`。其余字段为只读。
|
||||
|
||||
**IO 与配置**
|
||||
|
||||
| 函数 | 说明 |
|
||||
|
||||
Reference in New Issue
Block a user