qlogicagent 0.2.1 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +45 -45
- package/package.json +56 -42
- package/dist/agent/agent.d.ts +0 -43
- package/dist/agent/agent.js +0 -113
- package/dist/agent/tool-loop.d.ts +0 -64
- package/dist/agent/tool-loop.js +0 -575
- package/dist/agent/types.d.ts +0 -175
- package/dist/agent/types.js +0 -14
- package/dist/cli/main.d.ts +0 -11
- package/dist/cli/main.js +0 -23
- package/dist/cli/stdio-server.d.ts +0 -45
- package/dist/cli/stdio-server.js +0 -463
- package/dist/config/config.d.ts +0 -17
- package/dist/config/config.js +0 -21
- package/dist/contracts/hooks.d.ts +0 -120
- package/dist/contracts/hooks.js +0 -7
- package/dist/contracts/index.d.ts +0 -10
- package/dist/contracts/index.js +0 -10
- package/dist/contracts/planner.d.ts +0 -35
- package/dist/contracts/planner.js +0 -2
- package/dist/contracts/skill-candidate.d.ts +0 -63
- package/dist/contracts/skill-candidate.js +0 -195
- package/dist/contracts/todo.d.ts +0 -14
- package/dist/contracts/todo.js +0 -9
- package/dist/index.d.ts +0 -13
- package/dist/index.js +0 -15
- package/dist/llm/builtin-providers.d.ts +0 -10
- package/dist/llm/builtin-providers.js +0 -531
- package/dist/llm/index.d.ts +0 -15
- package/dist/llm/index.js +0 -14
- package/dist/llm/llm-client.d.ts +0 -43
- package/dist/llm/llm-client.js +0 -67
- package/dist/llm/model-catalog.d.ts +0 -53
- package/dist/llm/model-catalog.js +0 -191
- package/dist/llm/provider-def.d.ts +0 -59
- package/dist/llm/provider-def.js +0 -12
- package/dist/llm/provider-registry.d.ts +0 -54
- package/dist/llm/provider-registry.js +0 -147
- package/dist/llm/transport.d.ts +0 -62
- package/dist/llm/transport.js +0 -27
- package/dist/llm/transports/anthropic-messages.d.ts +0 -31
- package/dist/llm/transports/anthropic-messages.js +0 -293
- package/dist/llm/transports/openai-chat.d.ts +0 -36
- package/dist/llm/transports/openai-chat.js +0 -165
- package/dist/orchestration/agent-registry.d.ts +0 -41
- package/dist/orchestration/agent-registry.js +0 -116
- package/dist/orchestration/approval-aware-tool-plan.d.ts +0 -32
- package/dist/orchestration/approval-aware-tool-plan.js +0 -87
- package/dist/orchestration/context-compression.d.ts +0 -220
- package/dist/orchestration/context-compression.js +0 -583
- package/dist/orchestration/conversation-repair.d.ts +0 -61
- package/dist/orchestration/conversation-repair.js +0 -429
- package/dist/orchestration/curator-scheduler.d.ts +0 -119
- package/dist/orchestration/curator-scheduler.js +0 -135
- package/dist/orchestration/embedded-failover-policy.d.ts +0 -110
- package/dist/orchestration/embedded-failover-policy.js +0 -168
- package/dist/orchestration/error-classification.d.ts +0 -12
- package/dist/orchestration/error-classification.js +0 -77
- package/dist/orchestration/failover-classification.d.ts +0 -8
- package/dist/orchestration/failover-classification.js +0 -381
- package/dist/orchestration/failover-error.d.ts +0 -33
- package/dist/orchestration/failover-error.js +0 -198
- package/dist/orchestration/fork-subagent.d.ts +0 -100
- package/dist/orchestration/fork-subagent.js +0 -98
- package/dist/orchestration/index.d.ts +0 -120
- package/dist/orchestration/index.js +0 -267
- package/dist/orchestration/memory-flush-policy.d.ts +0 -57
- package/dist/orchestration/memory-flush-policy.js +0 -85
- package/dist/orchestration/memory-provider.d.ts +0 -14
- package/dist/orchestration/memory-provider.js +0 -2
- package/dist/orchestration/parallel-tool-calls.d.ts +0 -41
- package/dist/orchestration/parallel-tool-calls.js +0 -59
- package/dist/orchestration/prompt-cache-strategy.d.ts +0 -126
- package/dist/orchestration/prompt-cache-strategy.js +0 -228
- package/dist/orchestration/reactive-compact.d.ts +0 -73
- package/dist/orchestration/reactive-compact.js +0 -78
- package/dist/orchestration/retry-loop.d.ts +0 -22
- package/dist/orchestration/retry-loop.js +0 -24
- package/dist/orchestration/skill-candidate.d.ts +0 -52
- package/dist/orchestration/skill-candidate.js +0 -141
- package/dist/orchestration/skill-consolidation.d.ts +0 -123
- package/dist/orchestration/skill-consolidation.js +0 -220
- package/dist/orchestration/skill-improvement.d.ts +0 -59
- package/dist/orchestration/skill-improvement.js +0 -66
- package/dist/orchestration/skill-similarity.d.ts +0 -98
- package/dist/orchestration/skill-similarity.js +0 -131
- package/dist/orchestration/streaming-tool-executor.d.ts +0 -73
- package/dist/orchestration/streaming-tool-executor.js +0 -96
- package/dist/orchestration/team-orchestration.d.ts +0 -195
- package/dist/orchestration/team-orchestration.js +0 -369
- package/dist/orchestration/team-tool-loop-wiring.d.ts +0 -92
- package/dist/orchestration/team-tool-loop-wiring.js +0 -147
- package/dist/orchestration/tool-choice-policy.d.ts +0 -54
- package/dist/orchestration/tool-choice-policy.js +0 -164
- package/dist/orchestration/tool-loop-state.d.ts +0 -50
- package/dist/orchestration/tool-loop-state.js +0 -133
- package/dist/orchestration/tool-schema.d.ts +0 -39
- package/dist/orchestration/tool-schema.js +0 -297
- package/dist/orchestration/transcript-repair.d.ts +0 -42
- package/dist/orchestration/transcript-repair.js +0 -426
- package/dist/orchestration/turn-loop-guard.d.ts +0 -86
- package/dist/orchestration/turn-loop-guard.js +0 -92
- package/dist/orchestration/web-browser-policy.d.ts +0 -17
- package/dist/orchestration/web-browser-policy.js +0 -39
- package/dist/runtime/context-compression.d.ts +0 -61
- package/dist/runtime/context-compression.js +0 -274
- package/dist/runtime/hook-registry.d.ts +0 -12
- package/dist/runtime/hook-registry.js +0 -53
- package/dist/runtime/memory-hooks.d.ts +0 -23
- package/dist/runtime/memory-hooks.js +0 -65
- package/dist/runtime/tool-eligibility.d.ts +0 -59
- package/dist/runtime/tool-eligibility.js +0 -111
- package/dist/skills/index.d.ts +0 -108
- package/dist/skills/index.js +0 -82
- package/dist/skills/memory-extractor.d.ts +0 -64
- package/dist/skills/memory-extractor.js +0 -173
- package/dist/skills/memory-query-tool.d.ts +0 -43
- package/dist/skills/memory-query-tool.js +0 -127
- package/dist/skills/memory-store.d.ts +0 -66
- package/dist/skills/memory-store.js +0 -228
- package/dist/skills/memory-tool.d.ts +0 -67
- package/dist/skills/memory-tool.js +0 -192
- package/dist/skills/portable-tool.d.ts +0 -71
- package/dist/skills/portable-tool.js +0 -14
- package/dist/skills/qmemory-adapter.d.ts +0 -52
- package/dist/skills/qmemory-adapter.js +0 -165
- package/dist/skills/skill-frontmatter.d.ts +0 -19
- package/dist/skills/skill-frontmatter.js +0 -344
- package/dist/skills/skill-guard.d.ts +0 -23
- package/dist/skills/skill-guard.js +0 -229
- package/dist/skills/skill-loader.d.ts +0 -16
- package/dist/skills/skill-loader.js +0 -303
- package/dist/skills/skill-source.d.ts +0 -119
- package/dist/skills/skill-source.js +0 -126
- package/dist/skills/skill-types.d.ts +0 -199
- package/dist/skills/skill-types.js +0 -6
- package/dist/skills/think-tool.d.ts +0 -16
- package/dist/skills/think-tool.js +0 -59
- package/dist/skills/todo-tool.d.ts +0 -63
- package/dist/skills/todo-tool.js +0 -114
- package/dist/skills/tools/agent-tool.d.ts +0 -91
- package/dist/skills/tools/agent-tool.js +0 -142
- package/dist/skills/tools/apply-patch-tool.d.ts +0 -29
- package/dist/skills/tools/apply-patch-tool.js +0 -184
- package/dist/skills/tools/ask-user-tool.d.ts +0 -80
- package/dist/skills/tools/ask-user-tool.js +0 -121
- package/dist/skills/tools/brief-tool.d.ts +0 -74
- package/dist/skills/tools/brief-tool.js +0 -95
- package/dist/skills/tools/browser-tool.d.ts +0 -114
- package/dist/skills/tools/browser-tool.js +0 -155
- package/dist/skills/tools/checkpoint-tool.d.ts +0 -66
- package/dist/skills/tools/checkpoint-tool.js +0 -102
- package/dist/skills/tools/config-tool.d.ts +0 -63
- package/dist/skills/tools/config-tool.js +0 -143
- package/dist/skills/tools/cron-tool.d.ts +0 -116
- package/dist/skills/tools/cron-tool.js +0 -175
- package/dist/skills/tools/edit-tool.d.ts +0 -43
- package/dist/skills/tools/edit-tool.js +0 -70
- package/dist/skills/tools/exec-tool.d.ts +0 -102
- package/dist/skills/tools/exec-tool.js +0 -133
- package/dist/skills/tools/image-generate-tool.d.ts +0 -62
- package/dist/skills/tools/image-generate-tool.js +0 -67
- package/dist/skills/tools/instructions-tool.d.ts +0 -103
- package/dist/skills/tools/instructions-tool.js +0 -187
- package/dist/skills/tools/lsp-tool.d.ts +0 -153
- package/dist/skills/tools/lsp-tool.js +0 -227
- package/dist/skills/tools/mcp-client-types.d.ts +0 -269
- package/dist/skills/tools/mcp-client-types.js +0 -53
- package/dist/skills/tools/mcp-tool.d.ts +0 -249
- package/dist/skills/tools/mcp-tool.js +0 -503
- package/dist/skills/tools/memory-tool.d.ts +0 -74
- package/dist/skills/tools/memory-tool.js +0 -88
- package/dist/skills/tools/monitor-tool.d.ts +0 -113
- package/dist/skills/tools/monitor-tool.js +0 -131
- package/dist/skills/tools/music-generate-tool.d.ts +0 -55
- package/dist/skills/tools/music-generate-tool.js +0 -62
- package/dist/skills/tools/notify-tool.d.ts +0 -53
- package/dist/skills/tools/notify-tool.js +0 -62
- package/dist/skills/tools/patch-tool.d.ts +0 -45
- package/dist/skills/tools/patch-tool.js +0 -505
- package/dist/skills/tools/pdf-tool.d.ts +0 -66
- package/dist/skills/tools/pdf-tool.js +0 -88
- package/dist/skills/tools/plan-mode-tool.d.ts +0 -59
- package/dist/skills/tools/plan-mode-tool.js +0 -122
- package/dist/skills/tools/read-tool.d.ts +0 -51
- package/dist/skills/tools/read-tool.js +0 -84
- package/dist/skills/tools/repl-tool.d.ts +0 -70
- package/dist/skills/tools/repl-tool.js +0 -69
- package/dist/skills/tools/search-tool.d.ts +0 -112
- package/dist/skills/tools/search-tool.js +0 -225
- package/dist/skills/tools/send-message-tool.d.ts +0 -51
- package/dist/skills/tools/send-message-tool.js +0 -76
- package/dist/skills/tools/skill-list-tool.d.ts +0 -33
- package/dist/skills/tools/skill-list-tool.js +0 -54
- package/dist/skills/tools/skill-manage-tool.d.ts +0 -73
- package/dist/skills/tools/skill-manage-tool.js +0 -153
- package/dist/skills/tools/skill-view-tool.d.ts +0 -37
- package/dist/skills/tools/skill-view-tool.js +0 -72
- package/dist/skills/tools/sleep-tool.d.ts +0 -49
- package/dist/skills/tools/sleep-tool.js +0 -81
- package/dist/skills/tools/structured-output-tool.d.ts +0 -116
- package/dist/skills/tools/structured-output-tool.js +0 -176
- package/dist/skills/tools/task-tool.d.ts +0 -104
- package/dist/skills/tools/task-tool.js +0 -161
- package/dist/skills/tools/team-tool.d.ts +0 -89
- package/dist/skills/tools/team-tool.js +0 -105
- package/dist/skills/tools/tool-search-tool.d.ts +0 -51
- package/dist/skills/tools/tool-search-tool.js +0 -110
- package/dist/skills/tools/tts-tool.d.ts +0 -38
- package/dist/skills/tools/tts-tool.js +0 -45
- package/dist/skills/tools/video-edit-tool.d.ts +0 -69
- package/dist/skills/tools/video-edit-tool.js +0 -74
- package/dist/skills/tools/video-generate-tool.d.ts +0 -62
- package/dist/skills/tools/video-generate-tool.js +0 -66
- package/dist/skills/tools/video-merge-tool.d.ts +0 -105
- package/dist/skills/tools/video-merge-tool.js +0 -92
- package/dist/skills/tools/video-upscale-tool.d.ts +0 -45
- package/dist/skills/tools/video-upscale-tool.js +0 -52
- package/dist/skills/tools/web-fetch-tool.d.ts +0 -78
- package/dist/skills/tools/web-fetch-tool.js +0 -92
- package/dist/skills/tools/web-search-tool.d.ts +0 -57
- package/dist/skills/tools/web-search-tool.js +0 -86
- package/dist/skills/tools/worktree-tool.d.ts +0 -69
- package/dist/skills/tools/worktree-tool.js +0 -147
- package/dist/skills/tools/write-tool.d.ts +0 -45
- package/dist/skills/tools/write-tool.js +0 -81
package/README.md
CHANGED
|
@@ -1,45 +1,45 @@
|
|
|
1
|
-
# qlogicagent
|
|
2
|
-
|
|
3
|
-
CLI 子进程 Agent。小智 Claw 的本地 AI Agent 运行时,作为 openclaw Gateway 的子进程通过 **JSON-RPC over stdio** 通信。
|
|
4
|
-
|
|
5
|
-
## 职责
|
|
6
|
-
|
|
7
|
-
1. 接收 `agent.turn` JSON-RPC 请求,执行 Agent Loop(prompt → LLM → tool calls → iterate)。
|
|
8
|
-
2. 通过 stdout 流式输出 `turn.chunk`、`turn.tool_call`、`turn.done` 等 JSON-RPC 事件。
|
|
9
|
-
3. 工具执行委托回 Gateway(`turn.tool_call` → Gateway 执行 → `tool.result` 返回)。
|
|
10
|
-
4. 支持 failover、parallel tools、context compression、team orchestration 等编排策略。
|
|
11
|
-
5. 可选 qmemory 集成(memory hooks、skill learning、dream mechanism)。
|
|
12
|
-
|
|
13
|
-
## 不负责
|
|
14
|
-
|
|
15
|
-
1. HTTP/WebSocket 服务 — 由 qlogicagent-hub 负责。
|
|
16
|
-
2. 持久化存储 — Agent 是无状态子进程,Session/Skill/Plan 由 Gateway 管理。
|
|
17
|
-
3. LLM API Key 管理 — 配置通过 `agent.turn` 请求的 `config.llm` 字段传入。
|
|
18
|
-
4. 平台 API、订阅、计费 — 由 qlogicagent-hub + openclaw-admin 负责。
|
|
19
|
-
|
|
20
|
-
## 模块结构
|
|
21
|
-
|
|
22
|
-
```
|
|
23
|
-
src/
|
|
24
|
-
├── cli/ # JSON-RPC stdio 入口 (main.ts, stdio-server.ts)
|
|
25
|
-
├── agent/ # Agent 核心 (agent.ts, tool-loop.ts, types.ts)
|
|
26
|
-
├── llm/ # LLM provider 注册、传输层 (OpenAI, Anthropic)
|
|
27
|
-
├── orchestration/ # 编排策略 (failover, retry, parallel, compression, team)
|
|
28
|
-
├── skills/ # PortableTool 实现 + 外部 skill 加载
|
|
29
|
-
├── runtime/ # Hook registry, memory hooks, context compression
|
|
30
|
-
├── contracts/ # Hook / planner / skill candidate / todo 契约
|
|
31
|
-
└── config/ # 配置管理
|
|
32
|
-
```
|
|
33
|
-
|
|
34
|
-
## 运行命令
|
|
35
|
-
|
|
36
|
-
```bash
|
|
37
|
-
pnpm build # TypeScript 编译
|
|
38
|
-
pnpm test # vitest 测试
|
|
39
|
-
pnpm dev # tsx watch 开发
|
|
40
|
-
```
|
|
41
|
-
|
|
42
|
-
## 测试
|
|
43
|
-
|
|
44
|
-
- 单元测试:`test/` 目录,覆盖 LLM provider、orchestration、semantic turn tools。
|
|
45
|
-
- E2E 测试:`test/e2e/` 目录,spawn CLI 进程验证 JSON-RPC 协议行为。
|
|
1
|
+
# qlogicagent
|
|
2
|
+
|
|
3
|
+
CLI 子进程 Agent。小智 Claw 的本地 AI Agent 运行时,作为 openclaw Gateway 的子进程通过 **JSON-RPC over stdio** 通信。
|
|
4
|
+
|
|
5
|
+
## 职责
|
|
6
|
+
|
|
7
|
+
1. 接收 `agent.turn` JSON-RPC 请求,执行 Agent Loop(prompt → LLM → tool calls → iterate)。
|
|
8
|
+
2. 通过 stdout 流式输出 `turn.chunk`、`turn.tool_call`、`turn.done` 等 JSON-RPC 事件。
|
|
9
|
+
3. 工具执行委托回 Gateway(`turn.tool_call` → Gateway 执行 → `tool.result` 返回)。
|
|
10
|
+
4. 支持 failover、parallel tools、context compression、team orchestration 等编排策略。
|
|
11
|
+
5. 可选 qmemory 集成(memory hooks、skill learning、dream mechanism)。
|
|
12
|
+
|
|
13
|
+
## 不负责
|
|
14
|
+
|
|
15
|
+
1. HTTP/WebSocket 服务 — 由 qlogicagent-hub 负责。
|
|
16
|
+
2. 持久化存储 — Agent 是无状态子进程,Session/Skill/Plan 由 Gateway 管理。
|
|
17
|
+
3. LLM API Key 管理 — 配置通过 `agent.turn` 请求的 `config.llm` 字段传入。
|
|
18
|
+
4. 平台 API、订阅、计费 — 由 qlogicagent-hub + openclaw-admin 负责。
|
|
19
|
+
|
|
20
|
+
## 模块结构
|
|
21
|
+
|
|
22
|
+
```
|
|
23
|
+
src/
|
|
24
|
+
├── cli/ # JSON-RPC stdio 入口 (main.ts, stdio-server.ts)
|
|
25
|
+
├── agent/ # Agent 核心 (agent.ts, tool-loop.ts, types.ts)
|
|
26
|
+
├── llm/ # LLM provider 注册、传输层 (OpenAI, Anthropic)
|
|
27
|
+
├── orchestration/ # 编排策略 (failover, retry, parallel, compression, team)
|
|
28
|
+
├── skills/ # PortableTool 实现 + 外部 skill 加载
|
|
29
|
+
├── runtime/ # Hook registry, memory hooks, context compression
|
|
30
|
+
├── contracts/ # Hook / planner / skill candidate / todo 契约
|
|
31
|
+
└── config/ # 配置管理
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## 运行命令
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
pnpm build # TypeScript 编译
|
|
38
|
+
pnpm test # vitest 测试
|
|
39
|
+
pnpm dev # tsx watch 开发
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## 测试
|
|
43
|
+
|
|
44
|
+
- 单元测试:`test/` 目录,覆盖 LLM provider、orchestration、semantic turn tools。
|
|
45
|
+
- E2E 测试:`test/e2e/` 目录,spawn CLI 进程验证 JSON-RPC 协议行为。
|
package/package.json
CHANGED
|
@@ -1,43 +1,57 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "qlogicagent",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "XiaozhiClaw Agent CLI — subprocess architecture (JSON-RPC over stdio)",
|
|
5
|
-
"type": "module",
|
|
6
|
-
"main": "dist/index.js",
|
|
7
|
-
"bin": {
|
|
8
|
-
"qlogicagent": "dist/cli
|
|
9
|
-
},
|
|
10
|
-
"exports": {
|
|
11
|
-
".":
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
"
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
"
|
|
33
|
-
"
|
|
34
|
-
"
|
|
35
|
-
"
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
"
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
"
|
|
42
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "qlogicagent",
|
|
3
|
+
"version": "0.4.0",
|
|
4
|
+
"description": "XiaozhiClaw Agent CLI — subprocess architecture (JSON-RPC over stdio)",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"bin": {
|
|
8
|
+
"qlogicagent": "dist/cli.js"
|
|
9
|
+
},
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"types": "./dist/types/index.d.ts",
|
|
13
|
+
"default": "./dist/index.js"
|
|
14
|
+
},
|
|
15
|
+
"./agent": {
|
|
16
|
+
"types": "./dist/types/agent/agent.d.ts",
|
|
17
|
+
"default": "./dist/agent.js"
|
|
18
|
+
},
|
|
19
|
+
"./contracts": {
|
|
20
|
+
"types": "./dist/types/contracts/index.d.ts",
|
|
21
|
+
"default": "./dist/contracts.js"
|
|
22
|
+
},
|
|
23
|
+
"./orchestration": {
|
|
24
|
+
"types": "./dist/types/orchestration/index.d.ts",
|
|
25
|
+
"default": "./dist/orchestration.js"
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
"files": [
|
|
29
|
+
"dist/"
|
|
30
|
+
],
|
|
31
|
+
"scripts": {
|
|
32
|
+
"dev": "tsx watch src/index.ts",
|
|
33
|
+
"build": "node scripts/build.mjs",
|
|
34
|
+
"build:tsc": "tsc --noCheck",
|
|
35
|
+
"start": "node dist/cli/main.js",
|
|
36
|
+
"test": "vitest run",
|
|
37
|
+
"test:watch": "vitest",
|
|
38
|
+
"lint": "oxlint ."
|
|
39
|
+
},
|
|
40
|
+
"engines": {
|
|
41
|
+
"node": ">=22.0.0"
|
|
42
|
+
},
|
|
43
|
+
"dependencies": {
|
|
44
|
+
"dotenv": "^17.3.1",
|
|
45
|
+
"nanoid": "^5.1.5",
|
|
46
|
+
"pino": "^9.6.0",
|
|
47
|
+
"pino-pretty": "^13.0.0",
|
|
48
|
+
"qlogicagent-runtime-contracts": "^3.0.0"
|
|
49
|
+
},
|
|
50
|
+
"devDependencies": {
|
|
51
|
+
"@types/node": "^22.15.0",
|
|
52
|
+
"esbuild": "^0.28.0",
|
|
53
|
+
"tsx": "^4.19.0",
|
|
54
|
+
"typescript": "^5.9.0",
|
|
55
|
+
"vitest": "^3.1.0"
|
|
56
|
+
}
|
|
43
57
|
}
|
package/dist/agent/agent.d.ts
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Agent — clean agent execution loop for CLI subprocess mode.
|
|
3
|
-
*
|
|
4
|
-
* Thin wrapper around tool-loop.ts. Handles:
|
|
5
|
-
* - DI injection (LLMTransport, ToolInvoker, AgentLogger)
|
|
6
|
-
* - Turn lifecycle (start event + message repair + delegate to tool loop)
|
|
7
|
-
* - Top-level error handling
|
|
8
|
-
*
|
|
9
|
-
* The actual tool loop state machine (turn-loop-guard, tool-loop-state,
|
|
10
|
-
* parallel scheduling, sidechain filtering, etc.) lives in tool-loop.ts,
|
|
11
|
-
* ported faithfully from Hub's semantic-turn-tools.ts.
|
|
12
|
-
*
|
|
13
|
-
* Zero imports from express/pg/ioredis/ws.
|
|
14
|
-
*/
|
|
15
|
-
import type { AgentLogger, ToolInvoker, TurnEvent, TurnRequest, HookRegistry } from "./types.js";
|
|
16
|
-
import type { LLMTransport } from "../llm/transport.js";
|
|
17
|
-
export interface AgentConfig {
|
|
18
|
-
llmTransport: LLMTransport;
|
|
19
|
-
apiKey: string;
|
|
20
|
-
toolInvoker: ToolInvoker;
|
|
21
|
-
log: AgentLogger;
|
|
22
|
-
hooks?: HookRegistry;
|
|
23
|
-
maxRounds?: number;
|
|
24
|
-
verbose?: boolean;
|
|
25
|
-
}
|
|
26
|
-
export declare class Agent {
|
|
27
|
-
private transport;
|
|
28
|
-
private apiKey;
|
|
29
|
-
private toolInvoker;
|
|
30
|
-
private log;
|
|
31
|
-
private hooks?;
|
|
32
|
-
private maxRounds;
|
|
33
|
-
constructor(config: AgentConfig);
|
|
34
|
-
/**
|
|
35
|
-
* Execute an agent turn. Yields TurnEvent stream.
|
|
36
|
-
*
|
|
37
|
-
* 1. Emit start
|
|
38
|
-
* 2. Repair conversation history
|
|
39
|
-
* 3. Delegate to executeToolLoop() (full Hub-ported tool loop state machine)
|
|
40
|
-
* 4. Catch unhandled errors
|
|
41
|
-
*/
|
|
42
|
-
run(request: TurnRequest, signal?: AbortSignal): AsyncGenerator<TurnEvent>;
|
|
43
|
-
}
|
package/dist/agent/agent.js
DELETED
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Agent — clean agent execution loop for CLI subprocess mode.
|
|
3
|
-
*
|
|
4
|
-
* Thin wrapper around tool-loop.ts. Handles:
|
|
5
|
-
* - DI injection (LLMTransport, ToolInvoker, AgentLogger)
|
|
6
|
-
* - Turn lifecycle (start event + message repair + delegate to tool loop)
|
|
7
|
-
* - Top-level error handling
|
|
8
|
-
*
|
|
9
|
-
* The actual tool loop state machine (turn-loop-guard, tool-loop-state,
|
|
10
|
-
* parallel scheduling, sidechain filtering, etc.) lives in tool-loop.ts,
|
|
11
|
-
* ported faithfully from Hub's semantic-turn-tools.ts.
|
|
12
|
-
*
|
|
13
|
-
* Zero imports from express/pg/ioredis/ws.
|
|
14
|
-
*/
|
|
15
|
-
import { repairOpenAiChatConversation, classifyError, getRetryStrategy, } from "../orchestration/index.js";
|
|
16
|
-
import { executeToolLoop } from "./tool-loop.js";
|
|
17
|
-
const MAX_ROUNDS_LIMIT = 100;
|
|
18
|
-
export class Agent {
|
|
19
|
-
transport;
|
|
20
|
-
apiKey;
|
|
21
|
-
toolInvoker;
|
|
22
|
-
log;
|
|
23
|
-
hooks;
|
|
24
|
-
maxRounds;
|
|
25
|
-
constructor(config) {
|
|
26
|
-
this.transport = config.llmTransport;
|
|
27
|
-
this.apiKey = config.apiKey;
|
|
28
|
-
this.toolInvoker = config.toolInvoker;
|
|
29
|
-
this.log = config.log;
|
|
30
|
-
this.hooks = config.hooks;
|
|
31
|
-
this.maxRounds = Math.min(config.maxRounds ?? 25, MAX_ROUNDS_LIMIT);
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* Execute an agent turn. Yields TurnEvent stream.
|
|
35
|
-
*
|
|
36
|
-
* 1. Emit start
|
|
37
|
-
* 2. Repair conversation history
|
|
38
|
-
* 3. Delegate to executeToolLoop() (full Hub-ported tool loop state machine)
|
|
39
|
-
* 4. Catch unhandled errors
|
|
40
|
-
*/
|
|
41
|
-
async *run(request, signal) {
|
|
42
|
-
const { turnId, messages: inputMessages, tools, systemPrompt, config } = request;
|
|
43
|
-
const hookCtx = { sessionId: request.sessionId, turnId };
|
|
44
|
-
yield { type: "start", turnId };
|
|
45
|
-
// Hook: turn.submitted
|
|
46
|
-
this.hooks?.invoke("turn.submitted", {
|
|
47
|
-
...hookCtx,
|
|
48
|
-
prompt: inputMessages[inputMessages.length - 1]?.content ?? undefined,
|
|
49
|
-
}).catch(() => { });
|
|
50
|
-
// Repair malformed tool-call sequences in the input conversation history
|
|
51
|
-
const repairedMessages = repairOpenAiChatConversation(inputMessages);
|
|
52
|
-
// Build conversation: prepend system prompt if provided
|
|
53
|
-
const conversation = [];
|
|
54
|
-
if (systemPrompt) {
|
|
55
|
-
conversation.push({ role: "system", content: systemPrompt });
|
|
56
|
-
}
|
|
57
|
-
conversation.push(...repairedMessages);
|
|
58
|
-
const model = config?.model ?? "";
|
|
59
|
-
const maxRounds = Math.min(config?.maxRounds ?? this.maxRounds, MAX_ROUNDS_LIMIT);
|
|
60
|
-
try {
|
|
61
|
-
const toolLoopParams = {
|
|
62
|
-
turnId,
|
|
63
|
-
sessionId: request.sessionId,
|
|
64
|
-
messages: conversation,
|
|
65
|
-
tools,
|
|
66
|
-
model,
|
|
67
|
-
apiKey: config?.apiKey ?? this.apiKey,
|
|
68
|
-
temperature: config?.temperature,
|
|
69
|
-
maxRounds,
|
|
70
|
-
contextWindowTokens: config?.contextWindowTokens,
|
|
71
|
-
maxOutputTokens: config?.maxOutputTokens,
|
|
72
|
-
modelMaxOutputTokens: config?.modelMaxOutputTokens,
|
|
73
|
-
toolChoice: config?.toolChoice,
|
|
74
|
-
parentDepth: config?.parentDepth,
|
|
75
|
-
hooks: this.hooks,
|
|
76
|
-
signal,
|
|
77
|
-
};
|
|
78
|
-
let lastEvent;
|
|
79
|
-
for await (const event of executeToolLoop(toolLoopParams, this.transport, this.toolInvoker, this.log)) {
|
|
80
|
-
lastEvent = event;
|
|
81
|
-
yield event;
|
|
82
|
-
}
|
|
83
|
-
// Hook: turn.completed / turn.failed based on final event
|
|
84
|
-
if (lastEvent?.type === "end") {
|
|
85
|
-
this.hooks?.invoke("turn.completed", { ...hookCtx }).catch(() => { });
|
|
86
|
-
}
|
|
87
|
-
else if (lastEvent?.type === "error") {
|
|
88
|
-
this.hooks?.invoke("turn.failed", {
|
|
89
|
-
...hookCtx,
|
|
90
|
-
code: lastEvent.code,
|
|
91
|
-
error: lastEvent.error,
|
|
92
|
-
}).catch(() => { });
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
catch (err) {
|
|
96
|
-
if (signal?.aborted) {
|
|
97
|
-
this.hooks?.invoke("turn.failed", { ...hookCtx, code: "ABORTED", error: "Turn aborted" }).catch(() => { });
|
|
98
|
-
yield { type: "error", turnId, error: "Turn aborted", code: "ABORTED" };
|
|
99
|
-
}
|
|
100
|
-
else {
|
|
101
|
-
const message = err instanceof Error ? err.message : String(err);
|
|
102
|
-
const status = typeof err?.status === "number"
|
|
103
|
-
? err.status
|
|
104
|
-
: undefined;
|
|
105
|
-
const category = classifyError(status, message);
|
|
106
|
-
const strategy = getRetryStrategy(category);
|
|
107
|
-
this.log.error(`turn ${turnId} error [${category}, retryable=${strategy.retryable}]: ${message}`);
|
|
108
|
-
this.hooks?.invoke("turn.failed", { ...hookCtx, code: category, error: message }).catch(() => { });
|
|
109
|
-
yield { type: "error", turnId, error: message, code: category };
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
}
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Tool loop state machine — faithful port of Hub's semantic-turn-tools.ts.
|
|
3
|
-
*
|
|
4
|
-
* Replaces Hub infrastructure with DI abstractions:
|
|
5
|
-
* - invokeGatewayTool() (WS) → ToolInvoker.invoke()
|
|
6
|
-
* - createAdminInferProxyClient().stream() → LLMTransport.stream()
|
|
7
|
-
* - SemanticTurnDeps (PG/Redis) → in-memory state
|
|
8
|
-
* - sidechain DB depth → in-memory depth counter
|
|
9
|
-
* - Hub approval flow → skipped (CLI is local, all tools pre-authorized)
|
|
10
|
-
*
|
|
11
|
-
* Keeps ALL orchestration strategy calls from Hub:
|
|
12
|
-
* - turn-loop-guard (abort, token budget, output escalation)
|
|
13
|
-
* - tool-loop-state (advance/settle/recover)
|
|
14
|
-
* - parallel/serial tool call scheduling
|
|
15
|
-
* - sidechain tool access policy filtering
|
|
16
|
-
* - consecutive failure early exit
|
|
17
|
-
* - API error recovery
|
|
18
|
-
* - message repair
|
|
19
|
-
* - skill learning evaluation
|
|
20
|
-
*
|
|
21
|
-
* Zero imports from express/pg/ioredis/ws.
|
|
22
|
-
*/
|
|
23
|
-
import type { AgentLogger, ChatMessage, ToolDefinition, ToolInvoker, TurnEvent, HookRegistry } from "./types.js";
|
|
24
|
-
import type { LLMTransport } from "../llm/transport.js";
|
|
25
|
-
export interface ToolLoopParams {
|
|
26
|
-
turnId: string;
|
|
27
|
-
sessionId: string;
|
|
28
|
-
messages: ChatMessage[];
|
|
29
|
-
tools: ToolDefinition[];
|
|
30
|
-
model: string;
|
|
31
|
-
apiKey: string;
|
|
32
|
-
temperature?: number;
|
|
33
|
-
maxRounds?: number;
|
|
34
|
-
/** Context window size in tokens (for turn-loop-guard budget checks) */
|
|
35
|
-
contextWindowTokens?: number;
|
|
36
|
-
/** Max output tokens for current model */
|
|
37
|
-
maxOutputTokens?: number;
|
|
38
|
-
/** Model's absolute max output tokens (escalation ceiling) */
|
|
39
|
-
modelMaxOutputTokens?: number;
|
|
40
|
-
/** Tool choice strategy (default "auto") */
|
|
41
|
-
toolChoice?: "auto" | "none" | "required";
|
|
42
|
-
/** Parent sidechain depth (0 = top-level) */
|
|
43
|
-
parentDepth?: number;
|
|
44
|
-
/** Tool eligibility context for policy-based filtering */
|
|
45
|
-
toolEligibilityContext?: import("../runtime/tool-eligibility.js").ToolEligibilityContext;
|
|
46
|
-
/** Hook registry for lifecycle events (optional, fire-and-forget) */
|
|
47
|
-
hooks?: HookRegistry;
|
|
48
|
-
signal?: AbortSignal;
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
|
-
* Execute the tool loop — faithful port of Hub's orchestrateAgentTurnWithGatewayTools().
|
|
52
|
-
*
|
|
53
|
-
* Yields TurnEvent stream. The caller (Agent class) wraps this with
|
|
54
|
-
* start/end lifecycle and error handling.
|
|
55
|
-
*
|
|
56
|
-
* Events yielded:
|
|
57
|
-
* - delta: streaming text from LLM
|
|
58
|
-
* - tool_call: LLM requested a tool call
|
|
59
|
-
* - tool_result: tool execution completed
|
|
60
|
-
* - skill_instruction: skill learning evaluation result
|
|
61
|
-
* - end: turn completed successfully
|
|
62
|
-
* - error: unrecoverable error
|
|
63
|
-
*/
|
|
64
|
-
export declare function executeToolLoop(params: ToolLoopParams, transport: LLMTransport, toolInvoker: ToolInvoker, log: AgentLogger): AsyncGenerator<TurnEvent>;
|