@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.
Files changed (80) hide show
  1. package/package.json +8 -2
  2. package/.github/ISSUE_TEMPLATE/bug_report.md +0 -40
  3. package/.github/ISSUE_TEMPLATE/feature_request.md +0 -23
  4. package/.github/pull_request_template.md +0 -14
  5. package/.github/workflows/ci.yml +0 -23
  6. package/CLAUDE.md +0 -80
  7. package/CODE_OF_CONDUCT.md +0 -48
  8. package/CONTRIBUTING.md +0 -72
  9. package/DECISIONS.md +0 -43
  10. package/README_zh.md +0 -277
  11. package/SECURITY.md +0 -17
  12. package/examples/01-single-agent.ts +0 -131
  13. package/examples/02-team-collaboration.ts +0 -167
  14. package/examples/03-task-pipeline.ts +0 -201
  15. package/examples/04-multi-model-team.ts +0 -261
  16. package/examples/05-copilot-test.ts +0 -49
  17. package/examples/06-local-model.ts +0 -200
  18. package/examples/07-fan-out-aggregate.ts +0 -209
  19. package/examples/08-gemma4-local.ts +0 -192
  20. package/examples/09-structured-output.ts +0 -73
  21. package/examples/10-task-retry.ts +0 -132
  22. package/examples/11-trace-observability.ts +0 -133
  23. package/examples/12-grok.ts +0 -154
  24. package/examples/13-gemini.ts +0 -48
  25. package/src/agent/agent.ts +0 -622
  26. package/src/agent/loop-detector.ts +0 -137
  27. package/src/agent/pool.ts +0 -285
  28. package/src/agent/runner.ts +0 -542
  29. package/src/agent/structured-output.ts +0 -126
  30. package/src/index.ts +0 -182
  31. package/src/llm/adapter.ts +0 -98
  32. package/src/llm/anthropic.ts +0 -389
  33. package/src/llm/copilot.ts +0 -552
  34. package/src/llm/gemini.ts +0 -378
  35. package/src/llm/grok.ts +0 -29
  36. package/src/llm/openai-common.ts +0 -294
  37. package/src/llm/openai.ts +0 -292
  38. package/src/memory/shared.ts +0 -181
  39. package/src/memory/store.ts +0 -124
  40. package/src/orchestrator/orchestrator.ts +0 -1071
  41. package/src/orchestrator/scheduler.ts +0 -352
  42. package/src/task/queue.ts +0 -464
  43. package/src/task/task.ts +0 -239
  44. package/src/team/messaging.ts +0 -232
  45. package/src/team/team.ts +0 -334
  46. package/src/tool/built-in/bash.ts +0 -187
  47. package/src/tool/built-in/file-edit.ts +0 -154
  48. package/src/tool/built-in/file-read.ts +0 -105
  49. package/src/tool/built-in/file-write.ts +0 -81
  50. package/src/tool/built-in/grep.ts +0 -362
  51. package/src/tool/built-in/index.ts +0 -50
  52. package/src/tool/executor.ts +0 -178
  53. package/src/tool/framework.ts +0 -557
  54. package/src/tool/text-tool-extractor.ts +0 -219
  55. package/src/types.ts +0 -542
  56. package/src/utils/semaphore.ts +0 -89
  57. package/src/utils/trace.ts +0 -34
  58. package/tests/agent-hooks.test.ts +0 -473
  59. package/tests/agent-pool.test.ts +0 -212
  60. package/tests/approval.test.ts +0 -464
  61. package/tests/built-in-tools.test.ts +0 -393
  62. package/tests/gemini-adapter.test.ts +0 -97
  63. package/tests/grok-adapter.test.ts +0 -74
  64. package/tests/llm-adapters.test.ts +0 -357
  65. package/tests/loop-detection.test.ts +0 -456
  66. package/tests/openai-fallback.test.ts +0 -159
  67. package/tests/orchestrator.test.ts +0 -281
  68. package/tests/scheduler.test.ts +0 -221
  69. package/tests/semaphore.test.ts +0 -57
  70. package/tests/shared-memory.test.ts +0 -122
  71. package/tests/structured-output.test.ts +0 -331
  72. package/tests/task-queue.test.ts +0 -244
  73. package/tests/task-retry.test.ts +0 -368
  74. package/tests/task-utils.test.ts +0 -155
  75. package/tests/team-messaging.test.ts +0 -329
  76. package/tests/text-tool-extractor.test.ts +0 -170
  77. package/tests/tool-executor.test.ts +0 -193
  78. package/tests/trace.test.ts +0 -453
  79. package/tsconfig.json +0 -25
  80. package/vitest.config.ts +0 -9
@@ -1,133 +0,0 @@
1
- /**
2
- * Example 11 — Trace Observability
3
- *
4
- * Demonstrates the `onTrace` callback for lightweight observability. Every LLM
5
- * call, tool execution, task lifecycle, and agent run emits a structured trace
6
- * event with timing data and token usage — giving you full visibility into
7
- * what's happening inside a multi-agent run.
8
- *
9
- * Trace events share a `runId` for correlation, so you can reconstruct the
10
- * full execution timeline. Pipe them into your own logging, OpenTelemetry, or
11
- * dashboard.
12
- *
13
- * Run:
14
- * npx tsx examples/11-trace-observability.ts
15
- *
16
- * Prerequisites:
17
- * ANTHROPIC_API_KEY env var must be set.
18
- */
19
-
20
- import { OpenMultiAgent } from '../src/index.js'
21
- import type { AgentConfig, TraceEvent } from '../src/types.js'
22
-
23
- // ---------------------------------------------------------------------------
24
- // Agents
25
- // ---------------------------------------------------------------------------
26
-
27
- const researcher: AgentConfig = {
28
- name: 'researcher',
29
- model: 'claude-sonnet-4-6',
30
- systemPrompt: 'You are a research assistant. Provide concise, factual answers.',
31
- maxTurns: 2,
32
- }
33
-
34
- const writer: AgentConfig = {
35
- name: 'writer',
36
- model: 'claude-sonnet-4-6',
37
- systemPrompt: 'You are a technical writer. Summarize research into clear prose.',
38
- maxTurns: 2,
39
- }
40
-
41
- // ---------------------------------------------------------------------------
42
- // Trace handler — log every span with timing
43
- // ---------------------------------------------------------------------------
44
-
45
- function handleTrace(event: TraceEvent): void {
46
- const dur = `${event.durationMs}ms`.padStart(7)
47
-
48
- switch (event.type) {
49
- case 'llm_call':
50
- console.log(
51
- ` [LLM] ${dur} agent=${event.agent} model=${event.model} turn=${event.turn}` +
52
- ` tokens=${event.tokens.input_tokens}in/${event.tokens.output_tokens}out`,
53
- )
54
- break
55
- case 'tool_call':
56
- console.log(
57
- ` [TOOL] ${dur} agent=${event.agent} tool=${event.tool}` +
58
- ` error=${event.isError}`,
59
- )
60
- break
61
- case 'task':
62
- console.log(
63
- ` [TASK] ${dur} task="${event.taskTitle}" agent=${event.agent}` +
64
- ` success=${event.success} retries=${event.retries}`,
65
- )
66
- break
67
- case 'agent':
68
- console.log(
69
- ` [AGENT] ${dur} agent=${event.agent} turns=${event.turns}` +
70
- ` tools=${event.toolCalls} tokens=${event.tokens.input_tokens}in/${event.tokens.output_tokens}out`,
71
- )
72
- break
73
- }
74
- }
75
-
76
- // ---------------------------------------------------------------------------
77
- // Orchestrator + team
78
- // ---------------------------------------------------------------------------
79
-
80
- const orchestrator = new OpenMultiAgent({
81
- defaultModel: 'claude-sonnet-4-6',
82
- onTrace: handleTrace,
83
- })
84
-
85
- const team = orchestrator.createTeam('trace-demo', {
86
- name: 'trace-demo',
87
- agents: [researcher, writer],
88
- sharedMemory: true,
89
- })
90
-
91
- // ---------------------------------------------------------------------------
92
- // Tasks — researcher first, then writer summarizes
93
- // ---------------------------------------------------------------------------
94
-
95
- const tasks = [
96
- {
97
- title: 'Research topic',
98
- description: 'List 5 key benefits of TypeScript for large codebases. Be concise.',
99
- assignee: 'researcher',
100
- },
101
- {
102
- title: 'Write summary',
103
- description: 'Read the research from shared memory and write a 3-sentence summary.',
104
- assignee: 'writer',
105
- dependsOn: ['Research topic'],
106
- },
107
- ]
108
-
109
- // ---------------------------------------------------------------------------
110
- // Run
111
- // ---------------------------------------------------------------------------
112
-
113
- console.log('Trace Observability Example')
114
- console.log('='.repeat(60))
115
- console.log('Pipeline: research → write (with full trace output)')
116
- console.log('='.repeat(60))
117
- console.log()
118
-
119
- const result = await orchestrator.runTasks(team, tasks)
120
-
121
- // ---------------------------------------------------------------------------
122
- // Summary
123
- // ---------------------------------------------------------------------------
124
-
125
- console.log('\n' + '='.repeat(60))
126
- console.log(`Overall success: ${result.success}`)
127
- console.log(`Tokens — input: ${result.totalTokenUsage.input_tokens}, output: ${result.totalTokenUsage.output_tokens}`)
128
-
129
- for (const [name, r] of result.agentResults) {
130
- const icon = r.success ? 'OK ' : 'FAIL'
131
- console.log(` [${icon}] ${name}`)
132
- console.log(` ${r.output.slice(0, 200)}`)
133
- }
@@ -1,154 +0,0 @@
1
- /**
2
- * Example 12 — Multi-Agent Team Collaboration with Grok (xAI)
3
- *
4
- * Three specialized agents (architect, developer, reviewer) collaborate via `runTeam()`
5
- * to build a minimal Express.js REST API. Every agent uses Grok's coding-optimized model.
6
- *
7
- * Run:
8
- * npx tsx examples/12-grok.ts
9
- *
10
- * Prerequisites:
11
- * XAI_API_KEY environment variable must be set.
12
- */
13
-
14
- import { OpenMultiAgent } from '../src/index.js'
15
- import type { AgentConfig, OrchestratorEvent } from '../src/types.js'
16
-
17
- // ---------------------------------------------------------------------------
18
- // Agent definitions (all using grok-code-fast-1)
19
- // ---------------------------------------------------------------------------
20
- const architect: AgentConfig = {
21
- name: 'architect',
22
- model: 'grok-code-fast-1',
23
- provider: 'grok',
24
- systemPrompt: `You are a software architect with deep experience in Node.js and REST API design.
25
- Your job is to design clear, production-quality API contracts and file/directory structures.
26
- Output concise plans in markdown — no unnecessary prose.`,
27
- tools: ['bash', 'file_write'],
28
- maxTurns: 5,
29
- temperature: 0.2,
30
- }
31
-
32
- const developer: AgentConfig = {
33
- name: 'developer',
34
- model: 'grok-code-fast-1',
35
- provider: 'grok',
36
- systemPrompt: `You are a TypeScript/Node.js developer. You implement what the architect specifies.
37
- Write clean, runnable code with proper error handling. Use the tools to write files and run tests.`,
38
- tools: ['bash', 'file_read', 'file_write', 'file_edit'],
39
- maxTurns: 12,
40
- temperature: 0.1,
41
- }
42
-
43
- const reviewer: AgentConfig = {
44
- name: 'reviewer',
45
- model: 'grok-code-fast-1',
46
- provider: 'grok',
47
- systemPrompt: `You are a senior code reviewer. Review code for correctness, security, and clarity.
48
- Provide a structured review with: LGTM items, suggestions, and any blocking issues.
49
- Read files using the tools before reviewing.`,
50
- tools: ['bash', 'file_read', 'grep'],
51
- maxTurns: 5,
52
- temperature: 0.3,
53
- }
54
-
55
- // ---------------------------------------------------------------------------
56
- // Progress tracking
57
- // ---------------------------------------------------------------------------
58
- const startTimes = new Map<string, number>()
59
-
60
- function handleProgress(event: OrchestratorEvent): void {
61
- const ts = new Date().toISOString().slice(11, 23) // HH:MM:SS.mmm
62
- switch (event.type) {
63
- case 'agent_start':
64
- startTimes.set(event.agent ?? '', Date.now())
65
- console.log(`[${ts}] AGENT START → ${event.agent}`)
66
- break
67
- case 'agent_complete': {
68
- const elapsed = Date.now() - (startTimes.get(event.agent ?? '') ?? Date.now())
69
- console.log(`[${ts}] AGENT DONE ← ${event.agent} (${elapsed}ms)`)
70
- break
71
- }
72
- case 'task_start':
73
- console.log(`[${ts}] TASK START ↓ ${event.task}`)
74
- break
75
- case 'task_complete':
76
- console.log(`[${ts}] TASK DONE ↑ ${event.task}`)
77
- break
78
- case 'message':
79
- console.log(`[${ts}] MESSAGE • ${event.agent} → (team)`)
80
- break
81
- case 'error':
82
- console.error(`[${ts}] ERROR ✗ agent=${event.agent} task=${event.task}`)
83
- if (event.data instanceof Error) console.error(` ${event.data.message}`)
84
- break
85
- }
86
- }
87
-
88
- // ---------------------------------------------------------------------------
89
- // Orchestrate
90
- // ---------------------------------------------------------------------------
91
- const orchestrator = new OpenMultiAgent({
92
- defaultModel: 'grok-code-fast-1',
93
- defaultProvider: 'grok',
94
- maxConcurrency: 1, // sequential for readable output
95
- onProgress: handleProgress,
96
- })
97
-
98
- const team = orchestrator.createTeam('api-team', {
99
- name: 'api-team',
100
- agents: [architect, developer, reviewer],
101
- sharedMemory: true,
102
- maxConcurrency: 1,
103
- })
104
-
105
- console.log(`Team "${team.name}" created with agents: ${team.getAgents().map(a => a.name).join(', ')}`)
106
- console.log('\nStarting team run...\n')
107
- console.log('='.repeat(60))
108
-
109
- const goal = `Create a minimal Express.js REST API in /tmp/express-api/ with:
110
- - GET /health → { status: "ok" }
111
- - GET /users → returns a hardcoded array of 2 user objects
112
- - POST /users → accepts { name, email } body, logs it, returns 201
113
- - Proper error handling middleware
114
- - The server should listen on port 3001
115
- - Include a package.json with the required dependencies`
116
-
117
- const result = await orchestrator.runTeam(team, goal)
118
-
119
- console.log('\n' + '='.repeat(60))
120
-
121
- // ---------------------------------------------------------------------------
122
- // Results
123
- // ---------------------------------------------------------------------------
124
- console.log('\nTeam run complete.')
125
- console.log(`Success: ${result.success}`)
126
- console.log(`Total tokens — input: ${result.totalTokenUsage.input_tokens}, output: ${result.totalTokenUsage.output_tokens}`)
127
-
128
- console.log('\nPer-agent results:')
129
- for (const [agentName, agentResult] of result.agentResults) {
130
- const status = agentResult.success ? 'OK' : 'FAILED'
131
- const tools = agentResult.toolCalls.length
132
- console.log(` ${agentName.padEnd(12)} [${status}] tool_calls=${tools}`)
133
- if (!agentResult.success) {
134
- console.log(` Error: ${agentResult.output.slice(0, 120)}`)
135
- }
136
- }
137
-
138
- // Sample outputs
139
- const developerResult = result.agentResults.get('developer')
140
- if (developerResult?.success) {
141
- console.log('\nDeveloper output (last 600 chars):')
142
- console.log('─'.repeat(60))
143
- const out = developerResult.output
144
- console.log(out.length > 600 ? '...' + out.slice(-600) : out)
145
- console.log('─'.repeat(60))
146
- }
147
-
148
- const reviewerResult = result.agentResults.get('reviewer')
149
- if (reviewerResult?.success) {
150
- console.log('\nReviewer output:')
151
- console.log('─'.repeat(60))
152
- console.log(reviewerResult.output)
153
- console.log('─'.repeat(60))
154
- }
@@ -1,48 +0,0 @@
1
- /**
2
- * Quick smoke test for the Gemini adapter.
3
- *
4
- * Run:
5
- * npx tsx examples/13-gemini.ts
6
- *
7
- * If GEMINI_API_KEY is not set, the adapter will not work.
8
- */
9
-
10
- import { OpenMultiAgent } from '../src/index.js'
11
- import type { OrchestratorEvent } from '../src/types.js'
12
-
13
- const orchestrator = new OpenMultiAgent({
14
- defaultModel: 'gemini-2.5-flash',
15
- defaultProvider: 'gemini',
16
- onProgress: (event: OrchestratorEvent) => {
17
- if (event.type === 'agent_start') {
18
- console.log(`[start] agent=${event.agent}`)
19
- } else if (event.type === 'agent_complete') {
20
- console.log(`[complete] agent=${event.agent}`)
21
- }
22
- },
23
- })
24
-
25
- console.log('Testing Gemini adapter with gemini-2.5-flash...\n')
26
-
27
- const result = await orchestrator.runAgent(
28
- {
29
- name: 'assistant',
30
- model: 'gemini-2.5-flash',
31
- provider: 'gemini',
32
- systemPrompt: 'You are a helpful assistant. Keep answers brief.',
33
- maxTurns: 1,
34
- maxTokens: 256,
35
- },
36
- 'What is 2 + 2? Reply in one sentence.',
37
- )
38
-
39
- if (result.success) {
40
- console.log('\nAgent output:')
41
- console.log('─'.repeat(60))
42
- console.log(result.output)
43
- console.log('─'.repeat(60))
44
- console.log(`\nTokens: input=${result.tokenUsage.input_tokens}, output=${result.tokenUsage.output_tokens}`)
45
- } else {
46
- console.error('Agent failed:', result.output)
47
- process.exit(1)
48
- }