@jackchen_me/open-multi-agent 0.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 +21 -0
- package/README.md +280 -0
- package/dist/agent/agent.d.ts +121 -0
- package/dist/agent/agent.d.ts.map +1 -0
- package/dist/agent/agent.js +294 -0
- package/dist/agent/agent.js.map +1 -0
- package/dist/agent/pool.d.ts +128 -0
- package/dist/agent/pool.d.ts.map +1 -0
- package/dist/agent/pool.js +236 -0
- package/dist/agent/pool.js.map +1 -0
- package/dist/agent/runner.d.ts +120 -0
- package/dist/agent/runner.d.ts.map +1 -0
- package/dist/agent/runner.js +274 -0
- package/dist/agent/runner.js.map +1 -0
- package/dist/index.d.ts +73 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +87 -0
- package/dist/index.js.map +1 -0
- package/dist/llm/adapter.d.ts +38 -0
- package/dist/llm/adapter.d.ts.map +1 -0
- package/dist/llm/adapter.js +46 -0
- package/dist/llm/adapter.js.map +1 -0
- package/dist/llm/anthropic.d.ts +56 -0
- package/dist/llm/anthropic.d.ts.map +1 -0
- package/dist/llm/anthropic.js +307 -0
- package/dist/llm/anthropic.js.map +1 -0
- package/dist/llm/openai.d.ts +62 -0
- package/dist/llm/openai.d.ts.map +1 -0
- package/dist/llm/openai.js +424 -0
- package/dist/llm/openai.js.map +1 -0
- package/dist/memory/shared.d.ts +86 -0
- package/dist/memory/shared.d.ts.map +1 -0
- package/dist/memory/shared.js +155 -0
- package/dist/memory/shared.js.map +1 -0
- package/dist/memory/store.d.ts +64 -0
- package/dist/memory/store.d.ts.map +1 -0
- package/dist/memory/store.js +103 -0
- package/dist/memory/store.js.map +1 -0
- package/dist/orchestrator/orchestrator.d.ts +173 -0
- package/dist/orchestrator/orchestrator.d.ts.map +1 -0
- package/dist/orchestrator/orchestrator.js +698 -0
- package/dist/orchestrator/orchestrator.js.map +1 -0
- package/dist/orchestrator/scheduler.d.ts +112 -0
- package/dist/orchestrator/scheduler.d.ts.map +1 -0
- package/dist/orchestrator/scheduler.js +282 -0
- package/dist/orchestrator/scheduler.js.map +1 -0
- package/dist/task/queue.d.ts +160 -0
- package/dist/task/queue.d.ts.map +1 -0
- package/dist/task/queue.js +337 -0
- package/dist/task/queue.js.map +1 -0
- package/dist/task/task.d.ts +86 -0
- package/dist/task/task.d.ts.map +1 -0
- package/dist/task/task.js +201 -0
- package/dist/task/task.js.map +1 -0
- package/dist/team/messaging.d.ts +106 -0
- package/dist/team/messaging.d.ts.map +1 -0
- package/dist/team/messaging.js +182 -0
- package/dist/team/messaging.js.map +1 -0
- package/dist/team/team.d.ts +141 -0
- package/dist/team/team.d.ts.map +1 -0
- package/dist/team/team.js +282 -0
- package/dist/team/team.js.map +1 -0
- package/dist/tool/built-in/bash.d.ts +12 -0
- package/dist/tool/built-in/bash.d.ts.map +1 -0
- package/dist/tool/built-in/bash.js +133 -0
- package/dist/tool/built-in/bash.js.map +1 -0
- package/dist/tool/built-in/file-edit.d.ts +14 -0
- package/dist/tool/built-in/file-edit.d.ts.map +1 -0
- package/dist/tool/built-in/file-edit.js +130 -0
- package/dist/tool/built-in/file-edit.js.map +1 -0
- package/dist/tool/built-in/file-read.d.ts +12 -0
- package/dist/tool/built-in/file-read.d.ts.map +1 -0
- package/dist/tool/built-in/file-read.js +82 -0
- package/dist/tool/built-in/file-read.js.map +1 -0
- package/dist/tool/built-in/file-write.d.ts +11 -0
- package/dist/tool/built-in/file-write.d.ts.map +1 -0
- package/dist/tool/built-in/file-write.js +70 -0
- package/dist/tool/built-in/file-write.js.map +1 -0
- package/dist/tool/built-in/grep.d.ts +15 -0
- package/dist/tool/built-in/grep.d.ts.map +1 -0
- package/dist/tool/built-in/grep.js +287 -0
- package/dist/tool/built-in/grep.js.map +1 -0
- package/dist/tool/built-in/index.d.ts +36 -0
- package/dist/tool/built-in/index.d.ts.map +1 -0
- package/dist/tool/built-in/index.js +45 -0
- package/dist/tool/built-in/index.js.map +1 -0
- package/dist/tool/executor.d.ts +71 -0
- package/dist/tool/executor.d.ts.map +1 -0
- package/dist/tool/executor.js +116 -0
- package/dist/tool/executor.js.map +1 -0
- package/dist/tool/framework.d.ts +143 -0
- package/dist/tool/framework.d.ts.map +1 -0
- package/dist/tool/framework.js +371 -0
- package/dist/tool/framework.js.map +1 -0
- package/dist/types.d.ts +285 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +8 -0
- package/dist/types.js.map +1 -0
- package/dist/utils/semaphore.d.ts +47 -0
- package/dist/utils/semaphore.d.ts.map +1 -0
- package/dist/utils/semaphore.js +85 -0
- package/dist/utils/semaphore.js.map +1 -0
- package/examples/01-single-agent.ts +131 -0
- package/examples/02-team-collaboration.ts +167 -0
- package/examples/03-task-pipeline.ts +201 -0
- package/examples/04-multi-model-team.ts +261 -0
- package/package.json +49 -0
- package/src/agent/agent.ts +364 -0
- package/src/agent/pool.ts +278 -0
- package/src/agent/runner.ts +413 -0
- package/src/index.ts +166 -0
- package/src/llm/adapter.ts +74 -0
- package/src/llm/anthropic.ts +388 -0
- package/src/llm/openai.ts +522 -0
- package/src/memory/shared.ts +181 -0
- package/src/memory/store.ts +124 -0
- package/src/orchestrator/orchestrator.ts +851 -0
- package/src/orchestrator/scheduler.ts +352 -0
- package/src/task/queue.ts +394 -0
- package/src/task/task.ts +232 -0
- package/src/team/messaging.ts +230 -0
- package/src/team/team.ts +334 -0
- package/src/tool/built-in/bash.ts +187 -0
- package/src/tool/built-in/file-edit.ts +154 -0
- package/src/tool/built-in/file-read.ts +105 -0
- package/src/tool/built-in/file-write.ts +81 -0
- package/src/tool/built-in/grep.ts +362 -0
- package/src/tool/built-in/index.ts +50 -0
- package/src/tool/executor.ts +178 -0
- package/src/tool/framework.ts +557 -0
- package/src/types.ts +362 -0
- package/src/utils/semaphore.ts +89 -0
- package/tsconfig.json +25 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 open-multi-agent 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
ADDED
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
# Open Multi-Agent
|
|
2
|
+
|
|
3
|
+
Build AI agent teams that work together. One agent plans, another implements, a third reviews — the framework handles task scheduling, dependencies, and communication automatically.
|
|
4
|
+
|
|
5
|
+
[](https://github.com/JackChen-me/open-multi-agent/stargazers)
|
|
6
|
+
[](./LICENSE)
|
|
7
|
+
[](https://www.typescriptlang.org/)
|
|
8
|
+
|
|
9
|
+
## Why Open Multi-Agent?
|
|
10
|
+
|
|
11
|
+
- **Multi-Agent Teams** — Define agents with different roles, tools, and even different models. They collaborate through a message bus and shared memory.
|
|
12
|
+
- **Task DAG Scheduling** — Tasks have dependencies. The framework resolves them topologically — dependent tasks wait, independent tasks run in parallel.
|
|
13
|
+
- **Model Agnostic** — Claude and GPT in the same team. Swap models per agent. Bring your own adapter for any LLM.
|
|
14
|
+
- **In-Process Execution** — No subprocess overhead. Everything runs in one Node.js process. Deploy to serverless, Docker, CI/CD.
|
|
15
|
+
|
|
16
|
+
## Quick Start
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
npm install @jackchen_me/open-multi-agent
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
Set `ANTHROPIC_API_KEY` (and optionally `OPENAI_API_KEY`) in your environment.
|
|
23
|
+
|
|
24
|
+
```typescript
|
|
25
|
+
import { OpenMultiAgent } from '@jackchen_me/open-multi-agent'
|
|
26
|
+
|
|
27
|
+
const orchestrator = new OpenMultiAgent({ defaultModel: 'claude-sonnet-4-6' })
|
|
28
|
+
|
|
29
|
+
// One agent, one task
|
|
30
|
+
const result = await orchestrator.runAgent(
|
|
31
|
+
{
|
|
32
|
+
name: 'coder',
|
|
33
|
+
model: 'claude-sonnet-4-6',
|
|
34
|
+
tools: ['bash', 'file_write'],
|
|
35
|
+
},
|
|
36
|
+
'Write a TypeScript function that reverses a string, save it to /tmp/reverse.ts, and run it.',
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
console.log(result.output)
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## Multi-Agent Team
|
|
43
|
+
|
|
44
|
+
This is where it gets interesting. Three agents, one goal:
|
|
45
|
+
|
|
46
|
+
```typescript
|
|
47
|
+
import { OpenMultiAgent } from '@jackchen_me/open-multi-agent'
|
|
48
|
+
import type { AgentConfig } from '@jackchen_me/open-multi-agent'
|
|
49
|
+
|
|
50
|
+
const architect: AgentConfig = {
|
|
51
|
+
name: 'architect',
|
|
52
|
+
model: 'claude-sonnet-4-6',
|
|
53
|
+
systemPrompt: 'You design clean API contracts and file structures.',
|
|
54
|
+
tools: ['file_write'],
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const developer: AgentConfig = {
|
|
58
|
+
name: 'developer',
|
|
59
|
+
model: 'claude-sonnet-4-6',
|
|
60
|
+
systemPrompt: 'You implement what the architect designs.',
|
|
61
|
+
tools: ['bash', 'file_read', 'file_write', 'file_edit'],
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const reviewer: AgentConfig = {
|
|
65
|
+
name: 'reviewer',
|
|
66
|
+
model: 'claude-sonnet-4-6',
|
|
67
|
+
systemPrompt: 'You review code for correctness and clarity.',
|
|
68
|
+
tools: ['file_read', 'grep'],
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const orchestrator = new OpenMultiAgent({
|
|
72
|
+
defaultModel: 'claude-sonnet-4-6',
|
|
73
|
+
onProgress: (event) => console.log(event.type, event.agent ?? event.task ?? ''),
|
|
74
|
+
})
|
|
75
|
+
|
|
76
|
+
const team = orchestrator.createTeam('api-team', {
|
|
77
|
+
name: 'api-team',
|
|
78
|
+
agents: [architect, developer, reviewer],
|
|
79
|
+
sharedMemory: true,
|
|
80
|
+
})
|
|
81
|
+
|
|
82
|
+
// Describe a goal — the framework breaks it into tasks and orchestrates execution
|
|
83
|
+
const result = await orchestrator.runTeam(team, 'Create a REST API for a todo list in /tmp/todo-api/')
|
|
84
|
+
|
|
85
|
+
console.log(`Success: ${result.success}`)
|
|
86
|
+
console.log(`Tokens: ${result.totalTokenUsage.output_tokens} output tokens`)
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
## More Examples
|
|
90
|
+
|
|
91
|
+
<details>
|
|
92
|
+
<summary><b>Task Pipeline</b> — explicit control over task graph and assignments</summary>
|
|
93
|
+
|
|
94
|
+
```typescript
|
|
95
|
+
const result = await orchestrator.runTasks(team, [
|
|
96
|
+
{
|
|
97
|
+
title: 'Design the data model',
|
|
98
|
+
description: 'Write a TypeScript interface spec to /tmp/spec.md',
|
|
99
|
+
assignee: 'architect',
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
title: 'Implement the module',
|
|
103
|
+
description: 'Read /tmp/spec.md and implement the module in /tmp/src/',
|
|
104
|
+
assignee: 'developer',
|
|
105
|
+
dependsOn: ['Design the data model'], // blocked until design completes
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
title: 'Write tests',
|
|
109
|
+
description: 'Read the implementation and write Vitest tests.',
|
|
110
|
+
assignee: 'developer',
|
|
111
|
+
dependsOn: ['Implement the module'],
|
|
112
|
+
},
|
|
113
|
+
{
|
|
114
|
+
title: 'Review code',
|
|
115
|
+
description: 'Review /tmp/src/ and produce a structured code review.',
|
|
116
|
+
assignee: 'reviewer',
|
|
117
|
+
dependsOn: ['Implement the module'], // can run in parallel with tests
|
|
118
|
+
},
|
|
119
|
+
])
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
</details>
|
|
123
|
+
|
|
124
|
+
<details>
|
|
125
|
+
<summary><b>Custom Tools</b> — define tools with Zod schemas</summary>
|
|
126
|
+
|
|
127
|
+
```typescript
|
|
128
|
+
import { z } from 'zod'
|
|
129
|
+
import { defineTool, Agent, ToolRegistry, ToolExecutor, registerBuiltInTools } from '@jackchen_me/open-multi-agent'
|
|
130
|
+
|
|
131
|
+
const searchTool = defineTool({
|
|
132
|
+
name: 'web_search',
|
|
133
|
+
description: 'Search the web and return the top results.',
|
|
134
|
+
inputSchema: z.object({
|
|
135
|
+
query: z.string().describe('The search query.'),
|
|
136
|
+
maxResults: z.number().optional().describe('Number of results (default 5).'),
|
|
137
|
+
}),
|
|
138
|
+
execute: async ({ query, maxResults = 5 }) => {
|
|
139
|
+
const results = await mySearchProvider(query, maxResults)
|
|
140
|
+
return { data: JSON.stringify(results), isError: false }
|
|
141
|
+
},
|
|
142
|
+
})
|
|
143
|
+
|
|
144
|
+
const registry = new ToolRegistry()
|
|
145
|
+
registerBuiltInTools(registry)
|
|
146
|
+
registry.register(searchTool)
|
|
147
|
+
|
|
148
|
+
const executor = new ToolExecutor(registry)
|
|
149
|
+
const agent = new Agent(
|
|
150
|
+
{ name: 'researcher', model: 'claude-sonnet-4-6', tools: ['web_search'] },
|
|
151
|
+
registry,
|
|
152
|
+
executor,
|
|
153
|
+
)
|
|
154
|
+
|
|
155
|
+
const result = await agent.run('Find the three most recent TypeScript releases.')
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
</details>
|
|
159
|
+
|
|
160
|
+
<details>
|
|
161
|
+
<summary><b>Multi-Model Teams</b> — mix Claude and GPT in one workflow</summary>
|
|
162
|
+
|
|
163
|
+
```typescript
|
|
164
|
+
const claudeAgent: AgentConfig = {
|
|
165
|
+
name: 'strategist',
|
|
166
|
+
model: 'claude-opus-4-6',
|
|
167
|
+
provider: 'anthropic',
|
|
168
|
+
systemPrompt: 'You plan high-level approaches.',
|
|
169
|
+
tools: ['file_write'],
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
const gptAgent: AgentConfig = {
|
|
173
|
+
name: 'implementer',
|
|
174
|
+
model: 'gpt-5.4',
|
|
175
|
+
provider: 'openai',
|
|
176
|
+
systemPrompt: 'You implement plans as working code.',
|
|
177
|
+
tools: ['bash', 'file_read', 'file_write'],
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
const team = orchestrator.createTeam('mixed-team', {
|
|
181
|
+
name: 'mixed-team',
|
|
182
|
+
agents: [claudeAgent, gptAgent],
|
|
183
|
+
sharedMemory: true,
|
|
184
|
+
})
|
|
185
|
+
|
|
186
|
+
const result = await orchestrator.runTeam(team, 'Build a CLI tool that converts JSON to CSV.')
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
</details>
|
|
190
|
+
|
|
191
|
+
<details>
|
|
192
|
+
<summary><b>Streaming Output</b></summary>
|
|
193
|
+
|
|
194
|
+
```typescript
|
|
195
|
+
import { Agent, ToolRegistry, ToolExecutor, registerBuiltInTools } from '@jackchen_me/open-multi-agent'
|
|
196
|
+
|
|
197
|
+
const registry = new ToolRegistry()
|
|
198
|
+
registerBuiltInTools(registry)
|
|
199
|
+
const executor = new ToolExecutor(registry)
|
|
200
|
+
|
|
201
|
+
const agent = new Agent(
|
|
202
|
+
{ name: 'writer', model: 'claude-sonnet-4-6', maxTurns: 3 },
|
|
203
|
+
registry,
|
|
204
|
+
executor,
|
|
205
|
+
)
|
|
206
|
+
|
|
207
|
+
for await (const event of agent.stream('Explain monads in two sentences.')) {
|
|
208
|
+
if (event.type === 'text' && typeof event.data === 'string') {
|
|
209
|
+
process.stdout.write(event.data)
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
</details>
|
|
215
|
+
|
|
216
|
+
## Architecture
|
|
217
|
+
|
|
218
|
+
```
|
|
219
|
+
┌─────────────────────────────────────────────────────────────────┐
|
|
220
|
+
│ OpenMultiAgent (Orchestrator) │
|
|
221
|
+
│ │
|
|
222
|
+
│ createTeam() runTeam() runTasks() runAgent() getStatus() │
|
|
223
|
+
└──────────────────────┬──────────────────────────────────────────┘
|
|
224
|
+
│
|
|
225
|
+
┌──────────▼──────────┐
|
|
226
|
+
│ Team │
|
|
227
|
+
│ - AgentConfig[] │
|
|
228
|
+
│ - MessageBus │
|
|
229
|
+
│ - TaskQueue │
|
|
230
|
+
│ - SharedMemory │
|
|
231
|
+
└──────────┬──────────┘
|
|
232
|
+
│
|
|
233
|
+
┌─────────────┴─────────────┐
|
|
234
|
+
│ │
|
|
235
|
+
┌────────▼──────────┐ ┌───────────▼───────────┐
|
|
236
|
+
│ AgentPool │ │ TaskQueue │
|
|
237
|
+
│ - Semaphore │ │ - dependency graph │
|
|
238
|
+
│ - runParallel() │ │ - auto unblock │
|
|
239
|
+
└────────┬──────────┘ │ - cascade failure │
|
|
240
|
+
│ └───────────────────────┘
|
|
241
|
+
┌────────▼──────────┐
|
|
242
|
+
│ Agent │
|
|
243
|
+
│ - run() │ ┌──────────────────────┐
|
|
244
|
+
│ - prompt() │───►│ LLMAdapter │
|
|
245
|
+
│ - stream() │ │ - AnthropicAdapter │
|
|
246
|
+
└────────┬──────────┘ │ - OpenAIAdapter │
|
|
247
|
+
│ └──────────────────────┘
|
|
248
|
+
┌────────▼──────────┐
|
|
249
|
+
│ AgentRunner │ ┌──────────────────────┐
|
|
250
|
+
│ - conversation │───►│ ToolRegistry │
|
|
251
|
+
│ loop │ │ - defineTool() │
|
|
252
|
+
│ - tool dispatch │ │ - 5 built-in tools │
|
|
253
|
+
└───────────────────┘ └──────────────────────┘
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
## Built-in Tools
|
|
257
|
+
|
|
258
|
+
| Tool | Description |
|
|
259
|
+
|------|-------------|
|
|
260
|
+
| `bash` | Execute shell commands. Returns stdout + stderr. Supports timeout and cwd. |
|
|
261
|
+
| `file_read` | Read file contents at an absolute path. Supports offset/limit for large files. |
|
|
262
|
+
| `file_write` | Write or create a file. Auto-creates parent directories. |
|
|
263
|
+
| `file_edit` | Edit a file by replacing an exact string match. |
|
|
264
|
+
| `grep` | Search file contents with regex. Uses ripgrep when available, falls back to Node.js. |
|
|
265
|
+
|
|
266
|
+
## Contributing
|
|
267
|
+
|
|
268
|
+
Issues, feature requests, and PRs are welcome. Some areas where contributions would be especially valuable:
|
|
269
|
+
|
|
270
|
+
- **LLM Adapters** — Ollama, llama.cpp, vLLM, Gemini. The `LLMAdapter` interface requires just two methods: `chat()` and `stream()`.
|
|
271
|
+
- **Examples** — Real-world workflows and use cases.
|
|
272
|
+
- **Documentation** — Guides, tutorials, and API docs.
|
|
273
|
+
|
|
274
|
+
## Star History
|
|
275
|
+
|
|
276
|
+
[](https://star-history.com/#JackChen-me/open-multi-agent&Date)
|
|
277
|
+
|
|
278
|
+
## License
|
|
279
|
+
|
|
280
|
+
MIT
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview High-level Agent class for open-multi-agent.
|
|
3
|
+
*
|
|
4
|
+
* {@link Agent} is the primary interface most consumers interact with.
|
|
5
|
+
* It wraps {@link AgentRunner} with:
|
|
6
|
+
* - Persistent conversation history (`prompt()`)
|
|
7
|
+
* - Fresh-conversation semantics (`run()`)
|
|
8
|
+
* - Streaming support (`stream()`)
|
|
9
|
+
* - Dynamic tool registration at runtime
|
|
10
|
+
* - Full lifecycle state tracking (`idle → running → completed | error`)
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* const agent = new Agent({
|
|
15
|
+
* name: 'researcher',
|
|
16
|
+
* model: 'claude-opus-4-6',
|
|
17
|
+
* systemPrompt: 'You are a rigorous research assistant.',
|
|
18
|
+
* tools: ['web_search', 'read_file'],
|
|
19
|
+
* })
|
|
20
|
+
*
|
|
21
|
+
* const result = await agent.run('Summarise the last 3 IPCC reports.')
|
|
22
|
+
* console.log(result.output)
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
import type { AgentConfig, AgentState, AgentRunResult, LLMMessage, StreamEvent, ToolUseContext } from '../types.js';
|
|
26
|
+
import type { ToolDefinition as FrameworkToolDefinition, ToolRegistry } from '../tool/framework.js';
|
|
27
|
+
import type { ToolExecutor } from '../tool/executor.js';
|
|
28
|
+
/**
|
|
29
|
+
* High-level wrapper around {@link AgentRunner} that manages conversation
|
|
30
|
+
* history, state transitions, and tool lifecycle.
|
|
31
|
+
*/
|
|
32
|
+
export declare class Agent {
|
|
33
|
+
readonly name: string;
|
|
34
|
+
readonly config: AgentConfig;
|
|
35
|
+
private runner;
|
|
36
|
+
private state;
|
|
37
|
+
private readonly _toolRegistry;
|
|
38
|
+
private readonly _toolExecutor;
|
|
39
|
+
private messageHistory;
|
|
40
|
+
/**
|
|
41
|
+
* @param config - Static configuration for this agent.
|
|
42
|
+
* @param toolRegistry - Registry used to resolve and manage tools.
|
|
43
|
+
* @param toolExecutor - Executor that dispatches tool calls.
|
|
44
|
+
*
|
|
45
|
+
* `toolRegistry` and `toolExecutor` are injected rather than instantiated
|
|
46
|
+
* internally so that teams of agents can share a single registry.
|
|
47
|
+
*/
|
|
48
|
+
constructor(config: AgentConfig, toolRegistry: ToolRegistry, toolExecutor: ToolExecutor);
|
|
49
|
+
/**
|
|
50
|
+
* Lazily create the {@link AgentRunner}.
|
|
51
|
+
*
|
|
52
|
+
* The adapter is created asynchronously (it may lazy-import provider SDKs),
|
|
53
|
+
* so we defer construction until the first `run` / `prompt` / `stream` call.
|
|
54
|
+
*/
|
|
55
|
+
private getRunner;
|
|
56
|
+
/**
|
|
57
|
+
* Run `prompt` in a fresh conversation (history is NOT used).
|
|
58
|
+
*
|
|
59
|
+
* Equivalent to constructing a brand-new messages array `[{ role:'user', … }]`
|
|
60
|
+
* and calling the runner once. The agent's persistent history is not modified.
|
|
61
|
+
*
|
|
62
|
+
* Use this for one-shot queries where past context is irrelevant.
|
|
63
|
+
*/
|
|
64
|
+
run(prompt: string): Promise<AgentRunResult>;
|
|
65
|
+
/**
|
|
66
|
+
* Run `prompt` as part of the ongoing conversation.
|
|
67
|
+
*
|
|
68
|
+
* Appends the user message to the persistent history, runs the agent, then
|
|
69
|
+
* appends the resulting messages to the history for the next call.
|
|
70
|
+
*
|
|
71
|
+
* Use this for multi-turn interactions.
|
|
72
|
+
*/
|
|
73
|
+
prompt(message: string): Promise<AgentRunResult>;
|
|
74
|
+
/**
|
|
75
|
+
* Stream a fresh-conversation response, yielding {@link StreamEvent}s.
|
|
76
|
+
*
|
|
77
|
+
* Like {@link run}, this does not use or update the persistent history.
|
|
78
|
+
*/
|
|
79
|
+
stream(prompt: string): AsyncGenerator<StreamEvent>;
|
|
80
|
+
/** Return a snapshot of the current agent state (does not clone nested objects). */
|
|
81
|
+
getState(): AgentState;
|
|
82
|
+
/** Return a copy of the persistent message history. */
|
|
83
|
+
getHistory(): LLMMessage[];
|
|
84
|
+
/**
|
|
85
|
+
* Clear the persistent conversation history and reset state to `idle`.
|
|
86
|
+
* Does NOT discard the runner instance — the adapter connection is reused.
|
|
87
|
+
*/
|
|
88
|
+
reset(): void;
|
|
89
|
+
/**
|
|
90
|
+
* Register a new tool with this agent's tool registry at runtime.
|
|
91
|
+
*
|
|
92
|
+
* The tool becomes available to the next LLM call — no restart required.
|
|
93
|
+
*/
|
|
94
|
+
addTool(tool: FrameworkToolDefinition): void;
|
|
95
|
+
/**
|
|
96
|
+
* Deregister a tool by name.
|
|
97
|
+
* If the tool is not registered this is a no-op (no error is thrown).
|
|
98
|
+
*/
|
|
99
|
+
removeTool(name: string): void;
|
|
100
|
+
/** Return the names of all currently registered tools. */
|
|
101
|
+
getTools(): string[];
|
|
102
|
+
/**
|
|
103
|
+
* Shared execution path used by both `run` and `prompt`.
|
|
104
|
+
* Handles state transitions and error wrapping.
|
|
105
|
+
*/
|
|
106
|
+
private executeRun;
|
|
107
|
+
/**
|
|
108
|
+
* Shared streaming path used by `stream`.
|
|
109
|
+
* Handles state transitions and error wrapping.
|
|
110
|
+
*/
|
|
111
|
+
private executeStream;
|
|
112
|
+
private transitionTo;
|
|
113
|
+
private transitionToError;
|
|
114
|
+
private toAgentRunResult;
|
|
115
|
+
/**
|
|
116
|
+
* Build a {@link ToolUseContext} that identifies this agent.
|
|
117
|
+
* Exposed so team orchestrators can inject richer context (e.g. `TeamInfo`).
|
|
118
|
+
*/
|
|
119
|
+
buildToolContext(abortSignal?: AbortSignal): ToolUseContext;
|
|
120
|
+
}
|
|
121
|
+
//# sourceMappingURL=agent.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent.d.ts","sourceRoot":"","sources":["../../src/agent/agent.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,OAAO,KAAK,EACV,WAAW,EACX,UAAU,EACV,cAAc,EACd,UAAU,EACV,WAAW,EAEX,cAAc,EACf,MAAM,aAAa,CAAA;AACpB,OAAO,KAAK,EAAE,cAAc,IAAI,uBAAuB,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAA;AACnG,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAA;AAqBvD;;;GAGG;AACH,qBAAa,KAAK;IAChB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,MAAM,EAAE,WAAW,CAAA;IAE5B,OAAO,CAAC,MAAM,CAA2B;IACzC,OAAO,CAAC,KAAK,CAAY;IACzB,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAc;IAC5C,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAc;IAC5C,OAAO,CAAC,cAAc,CAAmB;IAEzC;;;;;;;OAOG;gBAED,MAAM,EAAE,WAAW,EACnB,YAAY,EAAE,YAAY,EAC1B,YAAY,EAAE,YAAY;IAkB5B;;;;;OAKG;YACW,SAAS;IAiCvB;;;;;;;OAOG;IACG,GAAG,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC;IAQlD;;;;;;;OAOG;IACG,MAAM,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC;IAkBtD;;;;OAIG;IACI,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,cAAc,CAAC,WAAW,CAAC;IAY1D,oFAAoF;IACpF,QAAQ,IAAI,UAAU;IAItB,uDAAuD;IACvD,UAAU,IAAI,UAAU,EAAE;IAI1B;;;OAGG;IACH,KAAK,IAAI,IAAI;IAab;;;;OAIG;IACH,OAAO,CAAC,IAAI,EAAE,uBAAuB,GAAG,IAAI;IAI5C;;;OAGG;IACH,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAI9B,0DAA0D;IAC1D,QAAQ,IAAI,MAAM,EAAE;IAQpB;;;OAGG;YACW,UAAU;IA+BxB;;;OAGG;YACY,aAAa;IA+B5B,OAAO,CAAC,YAAY;IAIpB,OAAO,CAAC,iBAAiB;IAQzB,OAAO,CAAC,gBAAgB;IAiBxB;;;OAGG;IACH,gBAAgB,CAAC,WAAW,CAAC,EAAE,WAAW,GAAG,cAAc;CAU5D"}
|