@jackchen_me/open-multi-agent 1.0.0 → 1.0.1
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/package.json +8 -2
- package/.github/ISSUE_TEMPLATE/bug_report.md +0 -40
- package/.github/ISSUE_TEMPLATE/feature_request.md +0 -23
- package/.github/pull_request_template.md +0 -14
- package/.github/workflows/ci.yml +0 -23
- package/CLAUDE.md +0 -80
- package/CODE_OF_CONDUCT.md +0 -48
- package/CONTRIBUTING.md +0 -72
- package/DECISIONS.md +0 -43
- package/README_zh.md +0 -277
- package/SECURITY.md +0 -17
- package/examples/01-single-agent.ts +0 -131
- package/examples/02-team-collaboration.ts +0 -167
- package/examples/03-task-pipeline.ts +0 -201
- package/examples/04-multi-model-team.ts +0 -261
- package/examples/05-copilot-test.ts +0 -49
- package/examples/06-local-model.ts +0 -200
- package/examples/07-fan-out-aggregate.ts +0 -209
- package/examples/08-gemma4-local.ts +0 -192
- package/examples/09-structured-output.ts +0 -73
- package/examples/10-task-retry.ts +0 -132
- package/examples/11-trace-observability.ts +0 -133
- package/examples/12-grok.ts +0 -154
- package/examples/13-gemini.ts +0 -48
- package/src/agent/agent.ts +0 -622
- package/src/agent/loop-detector.ts +0 -137
- package/src/agent/pool.ts +0 -285
- package/src/agent/runner.ts +0 -542
- package/src/agent/structured-output.ts +0 -126
- package/src/index.ts +0 -182
- package/src/llm/adapter.ts +0 -98
- package/src/llm/anthropic.ts +0 -389
- package/src/llm/copilot.ts +0 -552
- package/src/llm/gemini.ts +0 -378
- package/src/llm/grok.ts +0 -29
- package/src/llm/openai-common.ts +0 -294
- package/src/llm/openai.ts +0 -292
- package/src/memory/shared.ts +0 -181
- package/src/memory/store.ts +0 -124
- package/src/orchestrator/orchestrator.ts +0 -1071
- package/src/orchestrator/scheduler.ts +0 -352
- package/src/task/queue.ts +0 -464
- package/src/task/task.ts +0 -239
- package/src/team/messaging.ts +0 -232
- package/src/team/team.ts +0 -334
- package/src/tool/built-in/bash.ts +0 -187
- package/src/tool/built-in/file-edit.ts +0 -154
- package/src/tool/built-in/file-read.ts +0 -105
- package/src/tool/built-in/file-write.ts +0 -81
- package/src/tool/built-in/grep.ts +0 -362
- package/src/tool/built-in/index.ts +0 -50
- package/src/tool/executor.ts +0 -178
- package/src/tool/framework.ts +0 -557
- package/src/tool/text-tool-extractor.ts +0 -219
- package/src/types.ts +0 -542
- package/src/utils/semaphore.ts +0 -89
- package/src/utils/trace.ts +0 -34
- package/tests/agent-hooks.test.ts +0 -473
- package/tests/agent-pool.test.ts +0 -212
- package/tests/approval.test.ts +0 -464
- package/tests/built-in-tools.test.ts +0 -393
- package/tests/gemini-adapter.test.ts +0 -97
- package/tests/grok-adapter.test.ts +0 -74
- package/tests/llm-adapters.test.ts +0 -357
- package/tests/loop-detection.test.ts +0 -456
- package/tests/openai-fallback.test.ts +0 -159
- package/tests/orchestrator.test.ts +0 -281
- package/tests/scheduler.test.ts +0 -221
- package/tests/semaphore.test.ts +0 -57
- package/tests/shared-memory.test.ts +0 -122
- package/tests/structured-output.test.ts +0 -331
- package/tests/task-queue.test.ts +0 -244
- package/tests/task-retry.test.ts +0 -368
- package/tests/task-utils.test.ts +0 -155
- package/tests/team-messaging.test.ts +0 -329
- package/tests/text-tool-extractor.test.ts +0 -170
- package/tests/tool-executor.test.ts +0 -193
- package/tests/trace.test.ts +0 -453
- package/tsconfig.json +0 -25
- package/vitest.config.ts +0 -9
package/package.json
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jackchen_me/open-multi-agent",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"description": "TypeScript multi-agent framework — one runTeam() call from goal to result. Auto task decomposition, parallel execution. 3 dependencies, deploys anywhere Node.js runs.",
|
|
5
|
+
"files": [
|
|
6
|
+
"dist",
|
|
7
|
+
"README.md",
|
|
8
|
+
"LICENSE"
|
|
9
|
+
],
|
|
5
10
|
"type": "module",
|
|
6
11
|
"main": "dist/index.js",
|
|
7
12
|
"types": "dist/index.d.ts",
|
|
@@ -17,6 +22,7 @@
|
|
|
17
22
|
"test": "vitest run",
|
|
18
23
|
"test:watch": "vitest",
|
|
19
24
|
"lint": "tsc --noEmit",
|
|
25
|
+
"test:e2e": "RUN_E2E=1 vitest run tests/e2e/",
|
|
20
26
|
"prepublishOnly": "npm run build"
|
|
21
27
|
},
|
|
22
28
|
"keywords": [
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: Bug Report
|
|
3
|
-
about: Report a bug to help us improve
|
|
4
|
-
title: "[Bug] "
|
|
5
|
-
labels: bug
|
|
6
|
-
assignees: ''
|
|
7
|
-
---
|
|
8
|
-
|
|
9
|
-
## Describe the bug
|
|
10
|
-
|
|
11
|
-
A clear and concise description of what the bug is.
|
|
12
|
-
|
|
13
|
-
## To Reproduce
|
|
14
|
-
|
|
15
|
-
Steps to reproduce the behavior:
|
|
16
|
-
|
|
17
|
-
1. Configure agent with '...'
|
|
18
|
-
2. Call `runTeam(...)` with '...'
|
|
19
|
-
3. See error
|
|
20
|
-
|
|
21
|
-
## Expected behavior
|
|
22
|
-
|
|
23
|
-
A clear description of what you expected to happen.
|
|
24
|
-
|
|
25
|
-
## Error output
|
|
26
|
-
|
|
27
|
-
```
|
|
28
|
-
Paste any error messages or logs here
|
|
29
|
-
```
|
|
30
|
-
|
|
31
|
-
## Environment
|
|
32
|
-
|
|
33
|
-
- OS: [e.g. macOS 14, Ubuntu 22.04]
|
|
34
|
-
- Node.js version: [e.g. 20.11]
|
|
35
|
-
- Package version: [e.g. 0.1.0]
|
|
36
|
-
- LLM provider: [e.g. Anthropic, OpenAI]
|
|
37
|
-
|
|
38
|
-
## Additional context
|
|
39
|
-
|
|
40
|
-
Add any other context about the problem here.
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: Feature Request
|
|
3
|
-
about: Suggest an idea for this project
|
|
4
|
-
title: "[Feature] "
|
|
5
|
-
labels: enhancement
|
|
6
|
-
assignees: ''
|
|
7
|
-
---
|
|
8
|
-
|
|
9
|
-
## Problem
|
|
10
|
-
|
|
11
|
-
A clear description of the problem or limitation you're experiencing.
|
|
12
|
-
|
|
13
|
-
## Proposed Solution
|
|
14
|
-
|
|
15
|
-
Describe what you'd like to happen.
|
|
16
|
-
|
|
17
|
-
## Alternatives Considered
|
|
18
|
-
|
|
19
|
-
Any alternative solutions or features you've considered.
|
|
20
|
-
|
|
21
|
-
## Additional context
|
|
22
|
-
|
|
23
|
-
Add any other context, code examples, or screenshots about the feature request here.
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
## What
|
|
2
|
-
|
|
3
|
-
<!-- What does this PR do? One or two sentences. -->
|
|
4
|
-
|
|
5
|
-
## Why
|
|
6
|
-
|
|
7
|
-
<!-- Why is this change needed? Link to an issue if applicable: Fixes #123 -->
|
|
8
|
-
|
|
9
|
-
## Checklist
|
|
10
|
-
|
|
11
|
-
- [ ] `npm run lint` passes
|
|
12
|
-
- [ ] `npm test` passes
|
|
13
|
-
- [ ] Added/updated tests for changed behavior
|
|
14
|
-
- [ ] No new runtime dependencies (or justified in the PR description)
|
package/.github/workflows/ci.yml
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
name: CI
|
|
2
|
-
|
|
3
|
-
on:
|
|
4
|
-
push:
|
|
5
|
-
branches: [main]
|
|
6
|
-
pull_request:
|
|
7
|
-
branches: [main]
|
|
8
|
-
|
|
9
|
-
jobs:
|
|
10
|
-
test:
|
|
11
|
-
runs-on: ubuntu-latest
|
|
12
|
-
strategy:
|
|
13
|
-
matrix:
|
|
14
|
-
node-version: [18, 20, 22]
|
|
15
|
-
steps:
|
|
16
|
-
- uses: actions/checkout@v4
|
|
17
|
-
- uses: actions/setup-node@v4
|
|
18
|
-
with:
|
|
19
|
-
node-version: ${{ matrix.node-version }}
|
|
20
|
-
cache: npm
|
|
21
|
-
- run: rm -f package-lock.json && npm install
|
|
22
|
-
- run: npm run lint
|
|
23
|
-
- run: npm test
|
package/CLAUDE.md
DELETED
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
# CLAUDE.md
|
|
2
|
-
|
|
3
|
-
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
|
|
4
|
-
|
|
5
|
-
## Commands
|
|
6
|
-
|
|
7
|
-
```bash
|
|
8
|
-
npm run build # Compile TypeScript (src/ → dist/)
|
|
9
|
-
npm run dev # Watch mode compilation
|
|
10
|
-
npm run lint # Type-check only (tsc --noEmit)
|
|
11
|
-
npm test # Run all tests (vitest run)
|
|
12
|
-
npm run test:watch # Vitest watch mode
|
|
13
|
-
```
|
|
14
|
-
|
|
15
|
-
Tests live in `tests/` (vitest). Examples in `examples/` are standalone scripts requiring API keys (`ANTHROPIC_API_KEY`, `OPENAI_API_KEY`).
|
|
16
|
-
|
|
17
|
-
## Architecture
|
|
18
|
-
|
|
19
|
-
ES module TypeScript framework for multi-agent orchestration. Three runtime dependencies: `@anthropic-ai/sdk`, `openai`, `zod`.
|
|
20
|
-
|
|
21
|
-
### Core Execution Flow
|
|
22
|
-
|
|
23
|
-
**`OpenMultiAgent`** (`src/orchestrator/orchestrator.ts`) is the top-level public API with three execution modes:
|
|
24
|
-
|
|
25
|
-
1. **`runAgent(config, prompt)`** — single agent, one-shot
|
|
26
|
-
2. **`runTeam(team, goal)`** — automatic orchestration: a temporary "coordinator" agent decomposes the goal into a task DAG via LLM call, then tasks execute in dependency order
|
|
27
|
-
3. **`runTasks(team, tasks)`** — explicit task pipeline with user-defined dependencies
|
|
28
|
-
|
|
29
|
-
### The Coordinator Pattern (runTeam)
|
|
30
|
-
|
|
31
|
-
This is the framework's key feature. When `runTeam()` is called:
|
|
32
|
-
1. A coordinator agent receives the goal + agent roster and produces a JSON task array (title, description, assignee, dependsOn)
|
|
33
|
-
2. `TaskQueue` resolves dependencies topologically — independent tasks run in parallel, dependent tasks wait
|
|
34
|
-
3. `Scheduler` auto-assigns any unassigned tasks (strategies: `dependency-first` default, `round-robin`, `least-busy`, `capability-match`)
|
|
35
|
-
4. Each task result is written to `SharedMemory` so subsequent agents see prior results
|
|
36
|
-
5. The coordinator synthesizes all task results into a final output
|
|
37
|
-
|
|
38
|
-
### Layer Map
|
|
39
|
-
|
|
40
|
-
| Layer | Files | Responsibility |
|
|
41
|
-
|-------|-------|----------------|
|
|
42
|
-
| Orchestrator | `orchestrator/orchestrator.ts`, `orchestrator/scheduler.ts` | Top-level API, task decomposition, coordinator pattern |
|
|
43
|
-
| Team | `team/team.ts`, `team/messaging.ts` | Agent roster, MessageBus (point-to-point + broadcast), SharedMemory binding |
|
|
44
|
-
| Agent | `agent/agent.ts`, `agent/runner.ts`, `agent/pool.ts`, `agent/structured-output.ts` | Agent lifecycle (idle→running→completed/error), conversation loop, concurrency pool with Semaphore, structured output validation |
|
|
45
|
-
| Task | `task/queue.ts`, `task/task.ts` | Dependency-aware queue, auto-unblock on completion, cascade failure to dependents |
|
|
46
|
-
| Tool | `tool/framework.ts`, `tool/executor.ts`, `tool/built-in/` | `defineTool()` with Zod schemas, ToolRegistry, parallel batch execution with concurrency semaphore |
|
|
47
|
-
| LLM | `llm/adapter.ts`, `llm/anthropic.ts`, `llm/openai.ts` | `LLMAdapter` interface (`chat` + `stream`), factory `createAdapter()` |
|
|
48
|
-
| Memory | `memory/shared.ts`, `memory/store.ts` | Namespaced key-value store (`agentName/key`), markdown summary injection into prompts |
|
|
49
|
-
| Types | `types.ts` | All interfaces in one file to avoid circular deps |
|
|
50
|
-
| Exports | `index.ts` | Public API surface |
|
|
51
|
-
|
|
52
|
-
### Agent Conversation Loop (AgentRunner)
|
|
53
|
-
|
|
54
|
-
`AgentRunner.run()`: send messages → extract tool-use blocks → execute tools in parallel batch → append results → loop until `end_turn` or `maxTurns` exhausted. Accumulates `TokenUsage` across all turns.
|
|
55
|
-
|
|
56
|
-
### Concurrency Control
|
|
57
|
-
|
|
58
|
-
Two independent semaphores: `AgentPool` (max concurrent agent runs, default 5) and `ToolExecutor` (max concurrent tool calls, default 4).
|
|
59
|
-
|
|
60
|
-
### Structured Output
|
|
61
|
-
|
|
62
|
-
Optional `outputSchema` (Zod) on `AgentConfig`. When set, the agent's final output is parsed as JSON and validated. On validation failure, one retry with error feedback is attempted. Validated data is available via `result.structured`. Logic lives in `agent/structured-output.ts`, wired into `Agent.executeRun()`.
|
|
63
|
-
|
|
64
|
-
### Task Retry
|
|
65
|
-
|
|
66
|
-
Optional `maxRetries`, `retryDelayMs`, `retryBackoff` on task config (used via `runTasks()`). `executeWithRetry()` in `orchestrator.ts` handles the retry loop with exponential backoff (capped at 30s). Token usage is accumulated across all attempts. Emits `task_retry` event via `onProgress`.
|
|
67
|
-
|
|
68
|
-
### Error Handling
|
|
69
|
-
|
|
70
|
-
- Tool errors → caught, returned as `ToolResult(isError: true)`, never thrown
|
|
71
|
-
- Task failures → retry if `maxRetries > 0`, then cascade to all dependents; independent tasks continue
|
|
72
|
-
- LLM API errors → propagate to caller
|
|
73
|
-
|
|
74
|
-
### Built-in Tools
|
|
75
|
-
|
|
76
|
-
`bash`, `file_read`, `file_write`, `file_edit`, `grep` — registered via `registerBuiltInTools(registry)`.
|
|
77
|
-
|
|
78
|
-
### Adding an LLM Adapter
|
|
79
|
-
|
|
80
|
-
Implement `LLMAdapter` interface with `chat(messages, options)` and `stream(messages, options)`, then register in `createAdapter()` factory in `src/llm/adapter.ts`.
|
package/CODE_OF_CONDUCT.md
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
# Contributor Covenant Code of Conduct
|
|
2
|
-
|
|
3
|
-
## Our Pledge
|
|
4
|
-
|
|
5
|
-
We as members, contributors, and leaders pledge to make participation in our
|
|
6
|
-
community a positive experience for everyone, regardless of background or
|
|
7
|
-
identity.
|
|
8
|
-
|
|
9
|
-
## Our Standards
|
|
10
|
-
|
|
11
|
-
Examples of behavior that contributes to a positive environment:
|
|
12
|
-
|
|
13
|
-
- Using welcoming and inclusive language
|
|
14
|
-
- Being respectful of differing viewpoints and experiences
|
|
15
|
-
- Gracefully accepting constructive feedback
|
|
16
|
-
- Focusing on what is best for the community
|
|
17
|
-
- Showing empathy towards other community members
|
|
18
|
-
|
|
19
|
-
Examples of unacceptable behavior:
|
|
20
|
-
|
|
21
|
-
- Trolling, insulting or derogatory comments, and personal attacks
|
|
22
|
-
- Public or private unwelcome conduct
|
|
23
|
-
- Publishing others' private information without explicit permission
|
|
24
|
-
- Other conduct which could reasonably be considered inappropriate in a
|
|
25
|
-
professional setting
|
|
26
|
-
|
|
27
|
-
## Enforcement Responsibilities
|
|
28
|
-
|
|
29
|
-
Community leaders are responsible for clarifying and enforcing our standards of
|
|
30
|
-
acceptable behavior and will take appropriate and fair corrective action in
|
|
31
|
-
response to any behavior that they deem inappropriate or harmful.
|
|
32
|
-
|
|
33
|
-
## Scope
|
|
34
|
-
|
|
35
|
-
This Code of Conduct applies within all community spaces, and also applies when
|
|
36
|
-
an individual is officially representing the community in public spaces.
|
|
37
|
-
|
|
38
|
-
## Enforcement
|
|
39
|
-
|
|
40
|
-
Instances of unacceptable behavior may be reported to the community leaders
|
|
41
|
-
responsible for enforcement at **jack@yuanasi.com**. All complaints will be
|
|
42
|
-
reviewed and investigated promptly and fairly.
|
|
43
|
-
|
|
44
|
-
## Attribution
|
|
45
|
-
|
|
46
|
-
This Code of Conduct is adapted from the [Contributor Covenant](https://www.contributor-covenant.org),
|
|
47
|
-
version 2.1, available at
|
|
48
|
-
[https://www.contributor-covenant.org/version/2/1/code_of_conduct.html](https://www.contributor-covenant.org/version/2/1/code_of_conduct.html).
|
package/CONTRIBUTING.md
DELETED
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
# Contributing
|
|
2
|
-
|
|
3
|
-
Thanks for your interest in contributing to Open Multi-Agent! This guide covers the basics to get you started.
|
|
4
|
-
|
|
5
|
-
## Setup
|
|
6
|
-
|
|
7
|
-
```bash
|
|
8
|
-
git clone https://github.com/JackChen-me/open-multi-agent.git
|
|
9
|
-
cd open-multi-agent
|
|
10
|
-
npm install
|
|
11
|
-
```
|
|
12
|
-
|
|
13
|
-
Requires Node.js >= 18.
|
|
14
|
-
|
|
15
|
-
## Development Commands
|
|
16
|
-
|
|
17
|
-
```bash
|
|
18
|
-
npm run build # Compile TypeScript (src/ → dist/)
|
|
19
|
-
npm run dev # Watch mode compilation
|
|
20
|
-
npm run lint # Type-check (tsc --noEmit)
|
|
21
|
-
npm test # Run all tests (vitest)
|
|
22
|
-
npm run test:watch # Vitest watch mode
|
|
23
|
-
```
|
|
24
|
-
|
|
25
|
-
## Running Tests
|
|
26
|
-
|
|
27
|
-
All tests live in `tests/`. They test core modules (TaskQueue, SharedMemory, ToolExecutor, Semaphore) without requiring API keys or network access.
|
|
28
|
-
|
|
29
|
-
```bash
|
|
30
|
-
npm test
|
|
31
|
-
```
|
|
32
|
-
|
|
33
|
-
Every PR must pass `npm run lint && npm test`. CI runs both automatically on Node 18, 20, and 22.
|
|
34
|
-
|
|
35
|
-
## Making a Pull Request
|
|
36
|
-
|
|
37
|
-
1. Fork the repo and create a branch from `main`
|
|
38
|
-
2. Make your changes
|
|
39
|
-
3. Add or update tests if you changed behavior
|
|
40
|
-
4. Run `npm run lint && npm test` locally
|
|
41
|
-
5. Open a PR against `main`
|
|
42
|
-
|
|
43
|
-
### PR Checklist
|
|
44
|
-
|
|
45
|
-
- [ ] `npm run lint` passes
|
|
46
|
-
- [ ] `npm test` passes
|
|
47
|
-
- [ ] New behavior has test coverage
|
|
48
|
-
- [ ] Linked to a relevant issue (if one exists)
|
|
49
|
-
|
|
50
|
-
## Code Style
|
|
51
|
-
|
|
52
|
-
- TypeScript strict mode, ES modules (`.js` extensions in imports)
|
|
53
|
-
- No additional linter/formatter configured — follow existing patterns
|
|
54
|
-
- Keep dependencies minimal (currently 3 runtime deps: `@anthropic-ai/sdk`, `openai`, `zod`)
|
|
55
|
-
|
|
56
|
-
## Architecture Overview
|
|
57
|
-
|
|
58
|
-
See the [README](./README.md#architecture) for an architecture diagram. Key entry points:
|
|
59
|
-
|
|
60
|
-
- **Orchestrator**: `src/orchestrator/orchestrator.ts` — top-level API
|
|
61
|
-
- **Task system**: `src/task/queue.ts`, `src/task/task.ts` — dependency DAG
|
|
62
|
-
- **Agent**: `src/agent/runner.ts` — conversation loop
|
|
63
|
-
- **Tools**: `src/tool/framework.ts`, `src/tool/executor.ts` — tool registry and execution
|
|
64
|
-
- **LLM adapters**: `src/llm/` — Anthropic, OpenAI, Copilot
|
|
65
|
-
|
|
66
|
-
## Where to Contribute
|
|
67
|
-
|
|
68
|
-
Check the [issues](https://github.com/JackChen-me/open-multi-agent/issues) page. Issues labeled `good first issue` are scoped and approachable. Issues labeled `help wanted` are larger but well-defined.
|
|
69
|
-
|
|
70
|
-
## License
|
|
71
|
-
|
|
72
|
-
By contributing, you agree that your contributions will be licensed under the MIT License.
|
package/DECISIONS.md
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
# Architecture Decisions
|
|
2
|
-
|
|
3
|
-
This document records deliberate "won't do" decisions for the project. These are features we evaluated and chose NOT to implement — not because they're bad ideas, but because they conflict with our positioning as the **simplest multi-agent framework**.
|
|
4
|
-
|
|
5
|
-
If you're considering a PR in any of these areas, please open a discussion first.
|
|
6
|
-
|
|
7
|
-
## Won't Do
|
|
8
|
-
|
|
9
|
-
### 1. Agent Handoffs
|
|
10
|
-
|
|
11
|
-
**What**: Agent A transfers an in-progress conversation to Agent B (like OpenAI Agents SDK `handoff()`).
|
|
12
|
-
|
|
13
|
-
**Why not**: Handoffs are a different paradigm from our task-based model. Our tasks have clear boundaries — one agent, one task, one result. Handoffs blur those boundaries and add state-transfer complexity. Users who need handoffs likely need a different framework (OpenAI Agents SDK is purpose-built for this).
|
|
14
|
-
|
|
15
|
-
### 2. State Persistence / Checkpointing
|
|
16
|
-
|
|
17
|
-
**What**: Save workflow state to a database so long-running workflows can resume after crashes (like LangGraph checkpointing).
|
|
18
|
-
|
|
19
|
-
**Why not**: Requires a storage backend (SQLite, Redis, Postgres), schema migrations, and serialization logic. This is enterprise infrastructure — it triples the complexity surface. Our target users run workflows that complete in seconds to minutes, not hours. If you need checkpointing, LangGraph is the right tool.
|
|
20
|
-
|
|
21
|
-
**Related**: Closing #20 with this rationale.
|
|
22
|
-
|
|
23
|
-
### 3. A2A Protocol (Agent-to-Agent)
|
|
24
|
-
|
|
25
|
-
**What**: Google's open protocol for agents on different servers to discover and communicate with each other.
|
|
26
|
-
|
|
27
|
-
**Why not**: Too early — the spec is still evolving and adoption is minimal. Our users run agents in a single process, not across distributed services. If A2A matures and there's real demand, we can revisit. Today it would add complexity for zero practical benefit.
|
|
28
|
-
|
|
29
|
-
### 4. MCP Integration (Model Context Protocol)
|
|
30
|
-
|
|
31
|
-
**What**: Anthropic's protocol for connecting LLMs to external tools and data sources.
|
|
32
|
-
|
|
33
|
-
**Why not**: MCP is valuable but targets a different layer. Our `defineTool()` API already lets users wrap any external service as a tool in ~10 lines of code. Adding MCP would mean maintaining protocol compatibility, transport layers, and tool discovery — complexity that serves tool platform builders, not our target users who just want to run agent teams.
|
|
34
|
-
|
|
35
|
-
### 5. Dashboard / Visualization
|
|
36
|
-
|
|
37
|
-
**What**: Built-in web UI to visualize task DAGs, agent activity, and token usage.
|
|
38
|
-
|
|
39
|
-
**Why not**: We expose data, we don't build UI. The `onProgress` callback and upcoming `onTrace` (#18) give users all the raw data. They can pipe it into Grafana, build a custom dashboard, or use console logs. Shipping a web UI means owning a frontend stack, which is outside our scope.
|
|
40
|
-
|
|
41
|
-
---
|
|
42
|
-
|
|
43
|
-
*Last updated: 2026-04-03*
|
package/README_zh.md
DELETED
|
@@ -1,277 +0,0 @@
|
|
|
1
|
-
# Open Multi-Agent
|
|
2
|
-
|
|
3
|
-
TypeScript 多智能体编排框架。一次 `runTeam()` 调用从目标到结果——框架自动拆解任务、解析依赖、并行执行。
|
|
4
|
-
|
|
5
|
-
3 个运行时依赖 · 33 个源文件 · Node.js 能跑的地方都能部署 · 被 [Latent Space](https://www.latent.space/p/ainews-a-quiet-april-fools) AI News 提及(AI 工程领域头部 Newsletter,17 万+订阅者)
|
|
6
|
-
|
|
7
|
-
[](https://github.com/JackChen-me/open-multi-agent/stargazers)
|
|
8
|
-
[](./LICENSE)
|
|
9
|
-
[](https://www.typescriptlang.org/)
|
|
10
|
-
[](https://github.com/JackChen-me/open-multi-agent/actions)
|
|
11
|
-
|
|
12
|
-
[English](./README.md) | **中文**
|
|
13
|
-
|
|
14
|
-
## 为什么选择 Open Multi-Agent?
|
|
15
|
-
|
|
16
|
-
- **目标进,结果出** — `runTeam(team, "构建一个 REST API")`。协调者智能体自动将目标拆解为带依赖关系的任务图,分配给对应智能体,独立任务并行执行,最终合成输出。无需手动定义任务或编排流程图。
|
|
17
|
-
- **TypeScript 原生** — 为 Node.js 生态而生。`npm install` 即用,无需 Python 运行时、无子进程桥接、无额外基础设施。可嵌入 Express、Next.js、Serverless 函数或 CI/CD 流水线。
|
|
18
|
-
- **可审计、极轻量** — 3 个运行时依赖(`@anthropic-ai/sdk`、`openai`、`zod`),33 个源文件。一个下午就能读完全部源码。
|
|
19
|
-
- **模型无关** — Claude、GPT、Gemma 4 和本地模型(Ollama、vLLM、LM Studio、llama.cpp server)可以在同一个团队中使用。通过 `baseURL` 即可接入任何 OpenAI 兼容服务。
|
|
20
|
-
- **多智能体协作** — 定义不同角色、工具和模型的智能体,通过消息总线和共享内存协作。
|
|
21
|
-
- **结构化输出** — 为任意智能体添加 `outputSchema`(Zod),输出自动解析为 JSON 并校验,校验失败自动重试一次。通过 `result.structured` 获取类型化结果。
|
|
22
|
-
- **任务重试** — 为任务设置 `maxRetries`,失败时自动指数退避重试。所有尝试的 token 用量累计,确保计费准确。
|
|
23
|
-
- **人机协同** — `runTasks()` 支持可选的 `onApproval` 回调。每批任务完成后,由你的回调决定是否继续执行后续任务。
|
|
24
|
-
- **生命周期钩子** — `AgentConfig` 上的 `beforeRun` / `afterRun`。在执行前拦截 prompt,或在执行后处理结果。从钩子中 throw 可中止运行。
|
|
25
|
-
- **循环检测** — `AgentConfig` 上的 `loopDetection` 可检测智能体重复相同工具调用或文本输出的卡死循环。可配置行为:警告(默认)、终止、或自定义回调。
|
|
26
|
-
- **可观测性** — 可选的 `onTrace` 回调为每次 LLM 调用、工具执行、任务和智能体运行发出结构化 span 事件——包含耗时、token 用量和共享的 `runId` 用于关联追踪。未订阅时零开销,零额外依赖。
|
|
27
|
-
|
|
28
|
-
## 快速开始
|
|
29
|
-
|
|
30
|
-
需要 Node.js >= 18。
|
|
31
|
-
|
|
32
|
-
```bash
|
|
33
|
-
npm install @jackchen_me/open-multi-agent
|
|
34
|
-
```
|
|
35
|
-
|
|
36
|
-
根据使用的 Provider 设置对应的 API key。通过 Ollama 使用本地模型无需 API key — 参见 [example 06](examples/06-local-model.ts)。
|
|
37
|
-
|
|
38
|
-
- `ANTHROPIC_API_KEY`
|
|
39
|
-
- `OPENAI_API_KEY`
|
|
40
|
-
- `GEMINI_API_KEY`
|
|
41
|
-
- `XAI_API_KEY`(Grok)
|
|
42
|
-
- `GITHUB_TOKEN`(Copilot)
|
|
43
|
-
|
|
44
|
-
三个智能体,一个目标——框架处理剩下的一切:
|
|
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
|
-
// 描述一个目标——框架将其拆解为任务并编排执行
|
|
83
|
-
const result = await orchestrator.runTeam(team, 'Create a REST API for a todo list in /tmp/todo-api/')
|
|
84
|
-
|
|
85
|
-
console.log(`成功: ${result.success}`)
|
|
86
|
-
console.log(`Token 用量: ${result.totalTokenUsage.output_tokens} output tokens`)
|
|
87
|
-
```
|
|
88
|
-
|
|
89
|
-
执行过程:
|
|
90
|
-
|
|
91
|
-
```
|
|
92
|
-
agent_start coordinator
|
|
93
|
-
task_start architect
|
|
94
|
-
task_complete architect
|
|
95
|
-
task_start developer
|
|
96
|
-
task_start developer // 无依赖的任务并行执行
|
|
97
|
-
task_complete developer
|
|
98
|
-
task_start reviewer // 实现完成后自动解锁
|
|
99
|
-
task_complete developer
|
|
100
|
-
task_complete reviewer
|
|
101
|
-
agent_complete coordinator // 综合所有结果
|
|
102
|
-
Success: true
|
|
103
|
-
Tokens: 12847 output tokens
|
|
104
|
-
```
|
|
105
|
-
|
|
106
|
-
## 三种运行模式
|
|
107
|
-
|
|
108
|
-
| 模式 | 方法 | 适用场景 |
|
|
109
|
-
|------|------|----------|
|
|
110
|
-
| 单智能体 | `runAgent()` | 一个智能体,一个提示词——最简入口 |
|
|
111
|
-
| 自动编排团队 | `runTeam()` | 给一个目标,框架自动规划和执行 |
|
|
112
|
-
| 显式任务管线 | `runTasks()` | 你自己定义任务图和分配 |
|
|
113
|
-
|
|
114
|
-
## 示例
|
|
115
|
-
|
|
116
|
-
所有示例都是可运行脚本,位于 [`examples/`](./examples/) 目录。使用 `npx tsx` 运行:
|
|
117
|
-
|
|
118
|
-
```bash
|
|
119
|
-
npx tsx examples/01-single-agent.ts
|
|
120
|
-
```
|
|
121
|
-
|
|
122
|
-
| 示例 | 展示内容 |
|
|
123
|
-
|------|----------|
|
|
124
|
-
| [01 — 单智能体](examples/01-single-agent.ts) | `runAgent()` 单次调用、`stream()` 流式输出、`prompt()` 多轮对话 |
|
|
125
|
-
| [02 — 团队协作](examples/02-team-collaboration.ts) | `runTeam()` 自动编排 + 协调者模式 |
|
|
126
|
-
| [03 — 任务流水线](examples/03-task-pipeline.ts) | `runTasks()` 显式依赖图(设计 → 实现 → 测试 + 评审) |
|
|
127
|
-
| [04 — 多模型团队](examples/04-multi-model-team.ts) | `defineTool()` 自定义工具、Anthropic + OpenAI 混合、`AgentPool` |
|
|
128
|
-
| [05 — Copilot](examples/05-copilot-test.ts) | GitHub Copilot 作为 LLM 提供者 |
|
|
129
|
-
| [06 — 本地模型](examples/06-local-model.ts) | Ollama + Claude 混合流水线,通过 `baseURL` 接入(兼容 vLLM、LM Studio 等) |
|
|
130
|
-
| [07 — 扇出聚合](examples/07-fan-out-aggregate.ts) | `runParallel()` MapReduce — 3 个分析师并行,然后综合 |
|
|
131
|
-
| [08 — Gemma 4 本地](examples/08-gemma4-local.ts) | `runTasks()` + `runTeam()` 本地 Gemma 4 via Ollama — 零 API 费用 |
|
|
132
|
-
| [09 — 结构化输出](examples/09-structured-output.ts) | `outputSchema`(Zod)— 校验 JSON 输出,通过 `result.structured` 获取 |
|
|
133
|
-
| [10 — 任务重试](examples/10-task-retry.ts) | `maxRetries` / `retryDelayMs` / `retryBackoff` + `task_retry` 进度事件 |
|
|
134
|
-
| [11 — 可观测性](examples/11-trace-observability.ts) | `onTrace` 回调 — LLM 调用、工具、任务、智能体的结构化 span 事件 |
|
|
135
|
-
| [12 — Grok](examples/12-grok.ts) | 同示例 02(`runTeam()` 团队协作),使用 Grok(`XAI_API_KEY`) |
|
|
136
|
-
| [13 — Gemini](examples/13-gemini.ts) | Gemini 适配器测试,使用 `gemini-2.5-flash`(`GEMINI_API_KEY`) |
|
|
137
|
-
|
|
138
|
-
## 架构
|
|
139
|
-
|
|
140
|
-
```
|
|
141
|
-
┌─────────────────────────────────────────────────────────────────┐
|
|
142
|
-
│ OpenMultiAgent (Orchestrator) │
|
|
143
|
-
│ │
|
|
144
|
-
│ createTeam() runTeam() runTasks() runAgent() getStatus() │
|
|
145
|
-
└──────────────────────┬──────────────────────────────────────────┘
|
|
146
|
-
│
|
|
147
|
-
┌──────────▼──────────┐
|
|
148
|
-
│ Team │
|
|
149
|
-
│ - AgentConfig[] │
|
|
150
|
-
│ - MessageBus │
|
|
151
|
-
│ - TaskQueue │
|
|
152
|
-
│ - SharedMemory │
|
|
153
|
-
└──────────┬──────────┘
|
|
154
|
-
│
|
|
155
|
-
┌─────────────┴─────────────┐
|
|
156
|
-
│ │
|
|
157
|
-
┌────────▼──────────┐ ┌───────────▼───────────┐
|
|
158
|
-
│ AgentPool │ │ TaskQueue │
|
|
159
|
-
│ - Semaphore │ │ - dependency graph │
|
|
160
|
-
│ - runParallel() │ │ - auto unblock │
|
|
161
|
-
└────────┬──────────┘ │ - cascade failure │
|
|
162
|
-
│ └───────────────────────┘
|
|
163
|
-
┌────────▼──────────┐
|
|
164
|
-
│ Agent │
|
|
165
|
-
│ - run() │ ┌──────────────────────┐
|
|
166
|
-
│ - prompt() │───►│ LLMAdapter │
|
|
167
|
-
│ - stream() │ │ - AnthropicAdapter │
|
|
168
|
-
└────────┬──────────┘ │ - OpenAIAdapter │
|
|
169
|
-
│ │ - CopilotAdapter │
|
|
170
|
-
│ │ - GeminiAdapter │
|
|
171
|
-
│ │ - GrokAdapter │
|
|
172
|
-
│ └──────────────────────┘
|
|
173
|
-
┌────────▼──────────┐
|
|
174
|
-
│ AgentRunner │ ┌──────────────────────┐
|
|
175
|
-
│ - conversation │───►│ ToolRegistry │
|
|
176
|
-
│ loop │ │ - defineTool() │
|
|
177
|
-
│ - tool dispatch │ │ - 5 built-in tools │
|
|
178
|
-
└───────────────────┘ └──────────────────────┘
|
|
179
|
-
```
|
|
180
|
-
|
|
181
|
-
## 内置工具
|
|
182
|
-
|
|
183
|
-
| 工具 | 说明 |
|
|
184
|
-
|------|------|
|
|
185
|
-
| `bash` | 执行 Shell 命令。返回 stdout + stderr。支持超时和工作目录设置。 |
|
|
186
|
-
| `file_read` | 读取指定绝对路径的文件内容。支持偏移量和行数限制以处理大文件。 |
|
|
187
|
-
| `file_write` | 写入或创建文件。自动创建父目录。 |
|
|
188
|
-
| `file_edit` | 通过精确字符串匹配编辑文件。 |
|
|
189
|
-
| `grep` | 使用正则表达式搜索文件内容。优先使用 ripgrep,回退到 Node.js 实现。 |
|
|
190
|
-
|
|
191
|
-
## 支持的 Provider
|
|
192
|
-
|
|
193
|
-
| Provider | 配置 | 环境变量 | 状态 |
|
|
194
|
-
|----------|------|----------|------|
|
|
195
|
-
| Anthropic (Claude) | `provider: 'anthropic'` | `ANTHROPIC_API_KEY` | 已验证 |
|
|
196
|
-
| OpenAI (GPT) | `provider: 'openai'` | `OPENAI_API_KEY` | 已验证 |
|
|
197
|
-
| Grok (xAI) | `provider: 'grok'` | `XAI_API_KEY` | 已验证 |
|
|
198
|
-
| GitHub Copilot | `provider: 'copilot'` | `GITHUB_TOKEN` | 已验证 |
|
|
199
|
-
| Gemini | `provider: 'gemini'` | `GEMINI_API_KEY` | 已验证 |
|
|
200
|
-
| Ollama / vLLM / LM Studio | `provider: 'openai'` + `baseURL` | — | 已验证 |
|
|
201
|
-
| llama.cpp server | `provider: 'openai'` + `baseURL` | — | 已验证 |
|
|
202
|
-
|
|
203
|
-
已验证支持 tool-calling 的本地模型:**Gemma 4**(见[示例 08](examples/08-gemma4-local.ts))。
|
|
204
|
-
|
|
205
|
-
任何 OpenAI 兼容 API 均可通过 `provider: 'openai'` + `baseURL` 接入(DeepSeek、Groq、Mistral、Qwen、MiniMax 等)。**Grok 现已原生支持**,使用 `provider: 'grok'`。
|
|
206
|
-
|
|
207
|
-
### 本地模型 Tool-Calling
|
|
208
|
-
|
|
209
|
-
框架支持通过 Ollama、vLLM、LM Studio 或 llama.cpp 运行的本地模型进行 tool-calling。Tool-calling 由这些服务通过 OpenAI 兼容 API 原生处理。
|
|
210
|
-
|
|
211
|
-
**已验证模型:** Gemma 4、Llama 3.1、Qwen 3、Mistral、Phi-4。完整列表见 [ollama.com/search?c=tools](https://ollama.com/search?c=tools)。
|
|
212
|
-
|
|
213
|
-
**兜底提取:** 如果本地模型以文本形式返回工具调用,而非使用 `tool_calls` 协议格式(常见于 thinking 模型或配置不当的服务),框架会自动从文本输出中提取。
|
|
214
|
-
|
|
215
|
-
**超时设置:** 本地推理可能较慢。使用 `AgentConfig` 上的 `timeoutMs` 防止无限等待:
|
|
216
|
-
|
|
217
|
-
```typescript
|
|
218
|
-
const localAgent: AgentConfig = {
|
|
219
|
-
name: 'local',
|
|
220
|
-
model: 'llama3.1',
|
|
221
|
-
provider: 'openai',
|
|
222
|
-
baseURL: 'http://localhost:11434/v1',
|
|
223
|
-
apiKey: 'ollama',
|
|
224
|
-
tools: ['bash', 'file_read'],
|
|
225
|
-
timeoutMs: 120_000, // 2 分钟后中止
|
|
226
|
-
}
|
|
227
|
-
```
|
|
228
|
-
|
|
229
|
-
**常见问题:**
|
|
230
|
-
- 模型不调用工具?确保该模型出现在 Ollama 的 [Tools 分类](https://ollama.com/search?c=tools)中。并非所有模型都支持 tool-calling。
|
|
231
|
-
- 使用 Ollama?更新到最新版(`ollama update`)——旧版本有已知的 tool-calling bug。
|
|
232
|
-
- 代理干扰?本地服务使用 `no_proxy=localhost`。
|
|
233
|
-
|
|
234
|
-
### LLM 配置示例
|
|
235
|
-
|
|
236
|
-
```typescript
|
|
237
|
-
const grokAgent: AgentConfig = {
|
|
238
|
-
name: 'grok-agent',
|
|
239
|
-
provider: 'grok',
|
|
240
|
-
model: 'grok-4',
|
|
241
|
-
systemPrompt: 'You are a helpful assistant.',
|
|
242
|
-
}
|
|
243
|
-
```
|
|
244
|
-
|
|
245
|
-
(设置 `XAI_API_KEY` 环境变量即可,无需 `baseURL`。)
|
|
246
|
-
|
|
247
|
-
## 参与贡献
|
|
248
|
-
|
|
249
|
-
欢迎提 Issue、功能需求和 PR。以下方向的贡献尤其有价值:
|
|
250
|
-
|
|
251
|
-
- **Provider 集成** — 验证并文档化 OpenAI 兼容 Provider(DeepSeek、Groq、Qwen、MiniMax 等)通过 `baseURL` 接入。详见 [#25](https://github.com/JackChen-me/open-multi-agent/issues/25)。对于非 OpenAI 兼容的 Provider,欢迎贡献新的 `LLMAdapter` 实现——接口只需两个方法:`chat()` 和 `stream()`。
|
|
252
|
-
- **示例** — 真实场景的工作流和用例。
|
|
253
|
-
- **文档** — 指南、教程和 API 文档。
|
|
254
|
-
|
|
255
|
-
## 作者
|
|
256
|
-
|
|
257
|
-
> JackChen — 前 WPS 产品经理,现独立创业者。关注小红书[「杰克西|硅基杠杆」](https://www.xiaohongshu.com/user/profile/5a1bdc1e4eacab4aa39ea6d6),持续获取我的 AI Agent 观点和思考。
|
|
258
|
-
|
|
259
|
-
## 贡献者
|
|
260
|
-
|
|
261
|
-
<a href="https://github.com/JackChen-me/open-multi-agent/graphs/contributors">
|
|
262
|
-
<img src="https://contrib.rocks/image?repo=JackChen-me/open-multi-agent&v=20260405" />
|
|
263
|
-
</a>
|
|
264
|
-
|
|
265
|
-
## Star 趋势
|
|
266
|
-
|
|
267
|
-
<a href="https://star-history.com/#JackChen-me/open-multi-agent&Date">
|
|
268
|
-
<picture>
|
|
269
|
-
<source media="(prefers-color-scheme: dark)" srcset="https://api.star-history.com/svg?repos=JackChen-me/open-multi-agent&type=Date&theme=dark&v=20260405" />
|
|
270
|
-
<source media="(prefers-color-scheme: light)" srcset="https://api.star-history.com/svg?repos=JackChen-me/open-multi-agent&type=Date&v=20260405" />
|
|
271
|
-
<img alt="Star History Chart" src="https://api.star-history.com/svg?repos=JackChen-me/open-multi-agent&type=Date&v=20260405" />
|
|
272
|
-
</picture>
|
|
273
|
-
</a>
|
|
274
|
-
|
|
275
|
-
## 许可证
|
|
276
|
-
|
|
277
|
-
MIT
|
package/SECURITY.md
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
# Security Policy
|
|
2
|
-
|
|
3
|
-
## Supported Versions
|
|
4
|
-
|
|
5
|
-
| Version | Supported |
|
|
6
|
-
|---------|-----------|
|
|
7
|
-
| latest | Yes |
|
|
8
|
-
|
|
9
|
-
## Reporting a Vulnerability
|
|
10
|
-
|
|
11
|
-
If you discover a security vulnerability, please report it responsibly via email:
|
|
12
|
-
|
|
13
|
-
**jack@yuanasi.com**
|
|
14
|
-
|
|
15
|
-
Please do **not** open a public GitHub issue for security vulnerabilities.
|
|
16
|
-
|
|
17
|
-
We will acknowledge receipt within 48 hours and aim to provide a fix or mitigation plan within 7 days.
|