@faapi/agent 0.0.0-canary.0 → 3.1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 faapi contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,87 @@
1
1
  # @faapi/agent
2
2
 
3
- Placeholder package for Trusted Publisher setup. Real content published via CI from https://github.com/faapi/faapi.
3
+ > faapi agent 运行时——在已扫描的 agent / tool 注册表之上提供 LLM 驱动的 ReAct 循环
4
+
5
+ `@faapi/agent` 组合 faapi 核心包已生成的 `faapi-agents.js` + `faapi-tools.js` 清单,提供:
6
+
7
+ - **LLM Provider 抽象**(Phase 3.2)—— 统一接口对接 OpenAI / Anthropic 等 provider
8
+ - **ReAct 循环引擎**(Phase 3.3)—— LLM 输出 → 调用 tool / 递归 sub-agent → 把结果回灌给 LLM,循环直到最终回答
9
+ - **Agent 类**(Phase 3.4)—— 按 `agent.name` 查找元数据、加载 handler、组装 agent.tools + sub-agent,提供 `run` / `stream` / `asTool`
10
+ - **递归防护** —— `maxTurns` + `maxAgentDepth`(来自 `config.agent` 或 agent 自身 `config` 块)
11
+
12
+ ## 与 faapi 核心的关系
13
+
14
+ ```
15
+ faapi 核心(@faapi/faapi) @faapi/agent(本包)
16
+ ──────────────────────────── ────────────────────────────
17
+ scanAgents → faapi-agents.js ──→ Agent.run / stream
18
+ scanTools → faapi-tools.js ──→ reactLoop 组装 tool 列表
19
+ agentRegistry / toolRegistry ──→ resolveAgentTools / resolveSubAgents / asTool
20
+ loadAgentModule / loadToolModule ──→ reactLoop 执行 tool / sub-agent
21
+ config.agent(llm / maxTurns …) ──→ Agent 类构造参数
22
+ ```
23
+
24
+ 核心包负责扫描与产物生成(dev/prod 一致),本包负责运行时编排——LLM 调用、tool 分发、递归控制、流式输出。
25
+
26
+ ## 安装
27
+
28
+ ```bash
29
+ pnpm add @faapi/agent
30
+ # 或
31
+ npm install @faapi/agent
32
+ ```
33
+
34
+ 要求 Node.js >= 24。
35
+
36
+ > 当前为 canary 阶段(Phase 3.x 持续开发中),API 可能在稳定前调整。
37
+
38
+ ## 启用方式
39
+
40
+ 在 `faapi.config.ts` 的 `plugins` 中声明即启用 agent 运行时(Phase 3.5 集成):
41
+
42
+ ```ts
43
+ import type { FaapiConfig } from '@faapi/faapi';
44
+
45
+ export default {
46
+ agent: {
47
+ llm: {
48
+ provider: 'openai',
49
+ apiKey: process.env.OPENAI_API_KEY,
50
+ model: 'gpt-4o',
51
+ },
52
+ defaultAgent: 'researcher',
53
+ maxTurns: 10,
54
+ maxAgentDepth: 3,
55
+ },
56
+ plugins: ['@faapi/agent'],
57
+ } satisfies FaapiConfig;
58
+ ```
59
+
60
+ CLI 启动时动态加载——未安装时自动跳过,不影响核心功能。需单独安装:`pnpm add @faapi/agent`。
61
+
62
+ ## 多 agent 组织
63
+
64
+ agent 与 tool 的目录约定(由 faapi 核心包扫描,详见 [AGENTS.md 5.4](../../../AGENTS.md)):
65
+
66
+ ```
67
+ src/
68
+ ├── tools/ ← 所有 tool(agent 通过 config.tools 显式引用)
69
+ │ └── weather/handler.ts
70
+ ├── agents/
71
+ │ ├── researcher/ ← agent "researcher"
72
+ │ │ └── handler.ts ← export const config / export function run
73
+ │ └── writer/
74
+ │ └── handler.ts ← config.agents: ['researcher'] → 可调用 researcher
75
+ ```
76
+
77
+ - tool 位置:`src/tools/**`(所有 tool 统一放此目录,无 agent 专属 tool 概念)
78
+ - agent 可用 tool:在 agent 的 `config.tools` 字段显式声明引用 tool 名
79
+ - sub-agent:在 agent 的 `config.agents` 字段声明可调用的其他 agent 名
80
+
81
+ ## 状态
82
+
83
+ Phase 3.1:包骨架初始化(按 [AGENTS.md 6.5](../../../AGENTS.md) 清单配置)。
84
+
85
+ ## 许可证
86
+
87
+ [MIT](https://github.com/faapi/faapi/blob/main/LICENSE)