societyai 0.1.1 → 0.1.3
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/README.md +65 -53
- package/bin/societyai.js +813 -13
- package/dist/__tests__/execution/graph-visualizer.test.js +12 -12
- package/dist/__tests__/execution/graph-visualizer.test.js.map +1 -1
- package/dist/adapters/index.d.ts +1 -0
- package/dist/adapters/index.d.ts.map +1 -1
- package/dist/adapters/index.js +5 -1
- package/dist/adapters/index.js.map +1 -1
- package/dist/adapters/model-adapters.d.ts +51 -0
- package/dist/adapters/model-adapters.d.ts.map +1 -0
- package/dist/adapters/model-adapters.js +110 -0
- package/dist/adapters/model-adapters.js.map +1 -0
- package/dist/advanced.d.ts +9 -0
- package/dist/advanced.d.ts.map +1 -0
- package/dist/advanced.js +20 -0
- package/dist/advanced.js.map +1 -0
- package/dist/capabilities/memory.d.ts +23 -1
- package/dist/capabilities/memory.d.ts.map +1 -1
- package/dist/capabilities/memory.js +88 -2
- package/dist/capabilities/memory.js.map +1 -1
- package/dist/context.d.ts +8 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/context.js +23 -0
- package/dist/context.js.map +1 -0
- package/dist/core/errors.d.ts +18 -0
- package/dist/core/errors.d.ts.map +1 -1
- package/dist/core/errors.js +48 -1
- package/dist/core/errors.js.map +1 -1
- package/dist/core/middleware.d.ts +31 -0
- package/dist/core/middleware.d.ts.map +1 -1
- package/dist/core/middleware.js +126 -4
- package/dist/core/middleware.js.map +1 -1
- package/dist/events.d.ts +6 -0
- package/dist/events.d.ts.map +1 -0
- package/dist/events.js +16 -0
- package/dist/events.js.map +1 -0
- package/dist/execution/engine/execution-engine.d.ts +7 -1
- package/dist/execution/engine/execution-engine.d.ts.map +1 -1
- package/dist/execution/engine/execution-engine.js +38 -4
- package/dist/execution/engine/execution-engine.js.map +1 -1
- package/dist/execution/graph-visualizer.d.ts +47 -2
- package/dist/execution/graph-visualizer.d.ts.map +1 -1
- package/dist/execution/graph-visualizer.js +335 -48
- package/dist/execution/graph-visualizer.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10 -5
- package/dist/index.js.map +1 -1
- package/dist/memory.d.ts +5 -0
- package/dist/memory.d.ts.map +1 -0
- package/dist/memory.js +13 -0
- package/dist/memory.js.map +1 -0
- package/dist/public-api.d.ts +23 -0
- package/dist/public-api.d.ts.map +1 -0
- package/dist/public-api.js +61 -0
- package/dist/public-api.js.map +1 -0
- package/package.json +27 -3
package/README.md
CHANGED
|
@@ -89,43 +89,57 @@ npm run test -- --coverage
|
|
|
89
89
|
npm install societyai
|
|
90
90
|
```
|
|
91
91
|
|
|
92
|
-
### 1.
|
|
92
|
+
### 1. Quick Start with Built-in Adapters
|
|
93
93
|
|
|
94
|
-
SocietyAI
|
|
95
|
-
your model to the `AIModel` interface. Here is a minimal example for OpenAI:
|
|
94
|
+
SocietyAI provides built-in adapters for popular LLM providers:
|
|
96
95
|
|
|
97
96
|
```typescript
|
|
98
|
-
import {
|
|
99
|
-
import
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
97
|
+
import { Society } from 'societyai';
|
|
98
|
+
import { ModelAdapters } from 'societyai/adapters';
|
|
99
|
+
|
|
100
|
+
// Use built-in OpenAI adapter
|
|
101
|
+
const model = ModelAdapters.openai({
|
|
102
|
+
apiKey: process.env.OPENAI_API_KEY!,
|
|
103
|
+
model: 'gpt-4'
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
const result = await Society.create()
|
|
107
|
+
.addAgent(agent => agent
|
|
108
|
+
.withId('writer')
|
|
109
|
+
.withRole(r => r.withSystemPrompt('You are a technical writer'))
|
|
110
|
+
.withModel(model)
|
|
111
|
+
)
|
|
112
|
+
.addTask(t => t
|
|
113
|
+
.withId('write')
|
|
114
|
+
.withAgents(['writer'])
|
|
115
|
+
.sequential()
|
|
116
|
+
)
|
|
117
|
+
.execute('Write about TypeScript');
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
### Available Adapters
|
|
121
|
+
|
|
122
|
+
```typescript
|
|
123
|
+
import { ModelAdapters } from 'societyai/adapters';
|
|
124
|
+
|
|
125
|
+
// OpenAI
|
|
126
|
+
const openai = ModelAdapters.openai({ apiKey, model: 'gpt-4' });
|
|
127
|
+
|
|
128
|
+
// Anthropic
|
|
129
|
+
const anthropic = ModelAdapters.anthropic({ apiKey, model: 'claude-3-opus' });
|
|
130
|
+
|
|
131
|
+
// Google Gemini
|
|
132
|
+
const gemini = ModelAdapters.gemini({ apiKey, model: 'gemini-pro' });
|
|
133
|
+
|
|
134
|
+
// Azure OpenAI
|
|
135
|
+
const azure = ModelAdapters.azureOpenAI({ apiKey, endpoint, deployment });
|
|
136
|
+
|
|
137
|
+
// Ollama (local)
|
|
138
|
+
const ollama = ModelAdapters.ollama({ model: 'llama2', baseURL });
|
|
139
|
+
|
|
140
|
+
// Mock (for testing)
|
|
141
|
+
import { MockModel } from 'societyai/adapters';
|
|
142
|
+
const mock = new MockModel();
|
|
129
143
|
```
|
|
130
144
|
|
|
131
145
|
### 2. Create Your First Society
|
|
@@ -134,9 +148,12 @@ This example creates a small team to write and review an article.
|
|
|
134
148
|
|
|
135
149
|
```typescript
|
|
136
150
|
import { Society } from 'societyai';
|
|
137
|
-
import {
|
|
151
|
+
import { ModelAdapters } from 'societyai/adapters';
|
|
138
152
|
|
|
139
|
-
const model =
|
|
153
|
+
const model = ModelAdapters.openai({
|
|
154
|
+
apiKey: process.env.OPENAI_API_KEY!,
|
|
155
|
+
model: 'gpt-4'
|
|
156
|
+
});
|
|
140
157
|
|
|
141
158
|
// Create the Society
|
|
142
159
|
const result = await Society.create()
|
|
@@ -199,20 +216,16 @@ console.log('History:', result.taskResults);
|
|
|
199
216
|
For CPU-intensive agents, use worker threads to prevent blocking:
|
|
200
217
|
|
|
201
218
|
```typescript
|
|
202
|
-
import { Society, Middlewares, MiddlewareChain
|
|
203
|
-
import {
|
|
219
|
+
import { Society, Middlewares, MiddlewareChain } from 'societyai';
|
|
220
|
+
import { ModelAdapters } from 'societyai/adapters';
|
|
204
221
|
|
|
205
|
-
const model =
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
const observer = createOpenTelemetryObserver({
|
|
209
|
-
serviceName: 'my-app',
|
|
210
|
-
exporterType: 'console',
|
|
222
|
+
const model = ModelAdapters.openai({
|
|
223
|
+
apiKey: process.env.OPENAI_API_KEY!,
|
|
224
|
+
model: 'gpt-4'
|
|
211
225
|
});
|
|
212
226
|
|
|
213
227
|
const result = await Society.create()
|
|
214
228
|
.withId('advanced-team')
|
|
215
|
-
.withObserver(observer) // ← OpenTelemetry tracing
|
|
216
229
|
.addMiddleware(
|
|
217
230
|
MiddlewareChain.create()
|
|
218
231
|
.use(Middlewares.logging())
|
|
@@ -227,7 +240,7 @@ const result = await Society.create()
|
|
|
227
240
|
role.withSystemPrompt('You coordinate tasks and handle I/O operations.')
|
|
228
241
|
)
|
|
229
242
|
.withModel(model)
|
|
230
|
-
// executionMode defaults to '
|
|
243
|
+
// executionMode defaults to 'inline' (main thread)
|
|
231
244
|
)
|
|
232
245
|
|
|
233
246
|
// CPU-intensive agent — runs in an isolated Worker Thread
|
|
@@ -257,19 +270,15 @@ const result = await Society.create()
|
|
|
257
270
|
.execute('Start workflow');
|
|
258
271
|
|
|
259
272
|
console.log('Result:', result.output);
|
|
260
|
-
|
|
261
|
-
// Always shut down the observer to flush pending spans
|
|
262
|
-
await observer.shutdown();
|
|
263
273
|
```
|
|
264
274
|
|
|
265
275
|
**Key Points:**
|
|
266
276
|
|
|
267
277
|
- **`executionMode: 'isolated'`**: Runs the agent in a Worker Thread, preventing
|
|
268
278
|
main-event-loop blocking for CPU-heavy work.
|
|
269
|
-
- **`withObserver(observer)`**: Accepts any `SocietyObserver` implementation —
|
|
270
|
-
`OpenTelemetryObserver` provides distributed tracing for production.
|
|
271
279
|
- **Middlewares**: Applied to every agent call via `.addMiddleware()`. Accepts a
|
|
272
280
|
single `Middleware`, a raw `MiddlewareFn`, or a `MiddlewareChain`.
|
|
281
|
+
- **ModelAdapters**: Built-in adapters for OpenAI, Anthropic, Gemini, Azure, Ollama.
|
|
273
282
|
- **MCP Tools**: Add external tools via
|
|
274
283
|
`withTools(await MCPServers.filesystem('/path'))` on any agent.
|
|
275
284
|
|
|
@@ -289,14 +298,17 @@ Explore detailed documentation in the `/docs` folder:
|
|
|
289
298
|
|
|
290
299
|
Recent Highlights:
|
|
291
300
|
|
|
301
|
+
- [Getting Started](./docs/1-basics/getting-started.md) with CLI and ModelAdapters.
|
|
292
302
|
- [Context Management](./docs/2-building-societies/context.md) for dependency
|
|
293
303
|
injection.
|
|
294
|
-
- [
|
|
295
|
-
|
|
304
|
+
- [Visualization](./docs/4-advanced/visualization.md) — Mermaid, DOT, HTML export.
|
|
305
|
+
- [Benchmarks](./docs/4-advanced/benchmarks.md) — Performance testing.
|
|
306
|
+
- [Middleware](./docs/4-advanced/middleware.md) — Including streaming middleware.
|
|
296
307
|
- [Memory & RAG](./docs/3-capabilities/memory.md) for long-term state.
|
|
297
308
|
- [Structured Validation](./docs/3-capabilities/validation.md) for reliable JSON
|
|
298
309
|
outputs.
|
|
299
310
|
- [Execution Engine](./docs/5-architecture/execution-engine.md) deep dive.
|
|
311
|
+
- [CLI Reference](./docs/reference/cli.md) — Complete CLI documentation.
|
|
300
312
|
|
|
301
313
|
## 🤝 Contribution
|
|
302
314
|
|