@jackchen_me/open-multi-agent 0.1.0 → 1.0.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.
Files changed (140) hide show
  1. package/.github/ISSUE_TEMPLATE/bug_report.md +40 -0
  2. package/.github/ISSUE_TEMPLATE/feature_request.md +23 -0
  3. package/.github/pull_request_template.md +14 -0
  4. package/.github/workflows/ci.yml +23 -0
  5. package/CLAUDE.md +80 -0
  6. package/CODE_OF_CONDUCT.md +48 -0
  7. package/CONTRIBUTING.md +72 -0
  8. package/DECISIONS.md +43 -0
  9. package/README.md +144 -144
  10. package/README_zh.md +277 -0
  11. package/SECURITY.md +17 -0
  12. package/dist/agent/agent.d.ts +20 -1
  13. package/dist/agent/agent.d.ts.map +1 -1
  14. package/dist/agent/agent.js +233 -12
  15. package/dist/agent/agent.js.map +1 -1
  16. package/dist/agent/loop-detector.d.ts +39 -0
  17. package/dist/agent/loop-detector.d.ts.map +1 -0
  18. package/dist/agent/loop-detector.js +122 -0
  19. package/dist/agent/loop-detector.js.map +1 -0
  20. package/dist/agent/pool.d.ts +2 -1
  21. package/dist/agent/pool.d.ts.map +1 -1
  22. package/dist/agent/pool.js +4 -2
  23. package/dist/agent/pool.js.map +1 -1
  24. package/dist/agent/runner.d.ts +23 -1
  25. package/dist/agent/runner.d.ts.map +1 -1
  26. package/dist/agent/runner.js +113 -12
  27. package/dist/agent/runner.js.map +1 -1
  28. package/dist/agent/structured-output.d.ts +33 -0
  29. package/dist/agent/structured-output.d.ts.map +1 -0
  30. package/dist/agent/structured-output.js +116 -0
  31. package/dist/agent/structured-output.js.map +1 -0
  32. package/dist/index.d.ts +5 -2
  33. package/dist/index.d.ts.map +1 -1
  34. package/dist/index.js +4 -1
  35. package/dist/index.js.map +1 -1
  36. package/dist/llm/adapter.d.ts +12 -4
  37. package/dist/llm/adapter.d.ts.map +1 -1
  38. package/dist/llm/adapter.js +28 -5
  39. package/dist/llm/adapter.js.map +1 -1
  40. package/dist/llm/anthropic.d.ts +1 -1
  41. package/dist/llm/anthropic.d.ts.map +1 -1
  42. package/dist/llm/anthropic.js +2 -1
  43. package/dist/llm/anthropic.js.map +1 -1
  44. package/dist/llm/copilot.d.ts +92 -0
  45. package/dist/llm/copilot.d.ts.map +1 -0
  46. package/dist/llm/copilot.js +427 -0
  47. package/dist/llm/copilot.js.map +1 -0
  48. package/dist/llm/gemini.d.ts +65 -0
  49. package/dist/llm/gemini.d.ts.map +1 -0
  50. package/dist/llm/gemini.js +317 -0
  51. package/dist/llm/gemini.js.map +1 -0
  52. package/dist/llm/grok.d.ts +21 -0
  53. package/dist/llm/grok.d.ts.map +1 -0
  54. package/dist/llm/grok.js +24 -0
  55. package/dist/llm/grok.js.map +1 -0
  56. package/dist/llm/openai-common.d.ts +54 -0
  57. package/dist/llm/openai-common.d.ts.map +1 -0
  58. package/dist/llm/openai-common.js +242 -0
  59. package/dist/llm/openai-common.js.map +1 -0
  60. package/dist/llm/openai.d.ts +2 -2
  61. package/dist/llm/openai.d.ts.map +1 -1
  62. package/dist/llm/openai.js +23 -226
  63. package/dist/llm/openai.js.map +1 -1
  64. package/dist/orchestrator/orchestrator.d.ts +25 -1
  65. package/dist/orchestrator/orchestrator.d.ts.map +1 -1
  66. package/dist/orchestrator/orchestrator.js +214 -41
  67. package/dist/orchestrator/orchestrator.js.map +1 -1
  68. package/dist/task/queue.d.ts +31 -2
  69. package/dist/task/queue.d.ts.map +1 -1
  70. package/dist/task/queue.js +70 -3
  71. package/dist/task/queue.js.map +1 -1
  72. package/dist/task/task.d.ts +3 -0
  73. package/dist/task/task.d.ts.map +1 -1
  74. package/dist/task/task.js +5 -1
  75. package/dist/task/task.js.map +1 -1
  76. package/dist/team/messaging.d.ts.map +1 -1
  77. package/dist/team/messaging.js +2 -1
  78. package/dist/team/messaging.js.map +1 -1
  79. package/dist/tool/text-tool-extractor.d.ts +32 -0
  80. package/dist/tool/text-tool-extractor.d.ts.map +1 -0
  81. package/dist/tool/text-tool-extractor.js +187 -0
  82. package/dist/tool/text-tool-extractor.js.map +1 -0
  83. package/dist/types.d.ts +167 -7
  84. package/dist/types.d.ts.map +1 -1
  85. package/dist/utils/trace.d.ts +12 -0
  86. package/dist/utils/trace.d.ts.map +1 -0
  87. package/dist/utils/trace.js +30 -0
  88. package/dist/utils/trace.js.map +1 -0
  89. package/examples/05-copilot-test.ts +49 -0
  90. package/examples/06-local-model.ts +200 -0
  91. package/examples/07-fan-out-aggregate.ts +209 -0
  92. package/examples/08-gemma4-local.ts +192 -0
  93. package/examples/09-structured-output.ts +73 -0
  94. package/examples/10-task-retry.ts +132 -0
  95. package/examples/11-trace-observability.ts +133 -0
  96. package/examples/12-grok.ts +154 -0
  97. package/examples/13-gemini.ts +48 -0
  98. package/package.json +14 -3
  99. package/src/agent/agent.ts +273 -15
  100. package/src/agent/loop-detector.ts +137 -0
  101. package/src/agent/pool.ts +9 -2
  102. package/src/agent/runner.ts +148 -19
  103. package/src/agent/structured-output.ts +126 -0
  104. package/src/index.ts +17 -1
  105. package/src/llm/adapter.ts +29 -5
  106. package/src/llm/anthropic.ts +2 -1
  107. package/src/llm/copilot.ts +552 -0
  108. package/src/llm/gemini.ts +378 -0
  109. package/src/llm/grok.ts +29 -0
  110. package/src/llm/openai-common.ts +294 -0
  111. package/src/llm/openai.ts +31 -261
  112. package/src/orchestrator/orchestrator.ts +260 -40
  113. package/src/task/queue.ts +74 -4
  114. package/src/task/task.ts +8 -1
  115. package/src/team/messaging.ts +3 -1
  116. package/src/tool/text-tool-extractor.ts +219 -0
  117. package/src/types.ts +186 -6
  118. package/src/utils/trace.ts +34 -0
  119. package/tests/agent-hooks.test.ts +473 -0
  120. package/tests/agent-pool.test.ts +212 -0
  121. package/tests/approval.test.ts +464 -0
  122. package/tests/built-in-tools.test.ts +393 -0
  123. package/tests/gemini-adapter.test.ts +97 -0
  124. package/tests/grok-adapter.test.ts +74 -0
  125. package/tests/llm-adapters.test.ts +357 -0
  126. package/tests/loop-detection.test.ts +456 -0
  127. package/tests/openai-fallback.test.ts +159 -0
  128. package/tests/orchestrator.test.ts +281 -0
  129. package/tests/scheduler.test.ts +221 -0
  130. package/tests/semaphore.test.ts +57 -0
  131. package/tests/shared-memory.test.ts +122 -0
  132. package/tests/structured-output.test.ts +331 -0
  133. package/tests/task-queue.test.ts +244 -0
  134. package/tests/task-retry.test.ts +368 -0
  135. package/tests/task-utils.test.ts +155 -0
  136. package/tests/team-messaging.test.ts +329 -0
  137. package/tests/text-tool-extractor.test.ts +170 -0
  138. package/tests/tool-executor.test.ts +193 -0
  139. package/tests/trace.test.ts +453 -0
  140. package/vitest.config.ts +9 -0
@@ -0,0 +1,40 @@
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.
@@ -0,0 +1,23 @@
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.
@@ -0,0 +1,14 @@
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)
@@ -0,0 +1,23 @@
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 ADDED
@@ -0,0 +1,80 @@
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`.
@@ -0,0 +1,48 @@
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).
@@ -0,0 +1,72 @@
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 ADDED
@@ -0,0 +1,43 @@
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*