dank-ai 1.0.5 → 1.0.6
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 +1331 -66
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,107 +1,1372 @@
|
|
|
1
|
-
#
|
|
1
|
+
# 🚀 Dank Agent Service
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
**Docker-based AI Agent Orchestration Platform**
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
Dank is a powerful Node.js service that allows you to define, deploy, and manage AI agents using Docker containers. Each agent runs in its own isolated environment with configurable resources, LLM providers, and custom handlers.
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
- 🐳 **Docker Integration**: Containerized agents with automatic management
|
|
9
|
-
- 📡 **Event System**: Real-time event handling for prompts, responses, and tools
|
|
10
|
-
- 🔧 **Auto-Detection**: Automatically enables features based on usage
|
|
11
|
-
- 📊 **Monitoring**: Built-in logging and status monitoring
|
|
7
|
+
## ✨ Features
|
|
12
8
|
|
|
13
|
-
|
|
9
|
+
- **🤖 Multi-LLM Support**: OpenAI, Anthropic, Cohere, Ollama, and custom providers
|
|
10
|
+
- **🐳 Docker Orchestration**: Isolated agent containers with resource management
|
|
11
|
+
- **⚡ Easy Configuration**: Define agents with simple JavaScript configuration
|
|
12
|
+
- **📊 Real-time Monitoring**: Built-in health checks and status monitoring
|
|
13
|
+
- **🔧 Flexible Handlers**: Custom event handlers for agent outputs and errors
|
|
14
|
+
- **🎯 CLI Interface**: Powerful command-line tools for agent management
|
|
14
15
|
|
|
15
|
-
|
|
16
|
-
```bash
|
|
17
|
-
npm install
|
|
18
|
-
```
|
|
16
|
+
## 🚀 Quick Start
|
|
19
17
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
18
|
+
### Prerequisites
|
|
19
|
+
Before you begin, make sure you have:
|
|
20
|
+
- **Node.js 16+** installed
|
|
21
|
+
- **Docker Desktop** or **Docker Engine** (will be installed automatically if missing)
|
|
22
|
+
- **API keys** for your chosen LLM provider(s)
|
|
25
23
|
|
|
26
|
-
|
|
27
|
-
Edit `dank.config.js` to define your agents and their capabilities.
|
|
24
|
+
> **🆕 Auto-Docker Installation**: Dank will automatically detect, install, and start Docker if it's not available on your system. No manual setup required!
|
|
28
25
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
26
|
+
### 1. Install Dank globally
|
|
27
|
+
```bash
|
|
28
|
+
npm install -g dank-ai
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
### 2. Initialize a new project
|
|
32
|
+
```bash
|
|
33
|
+
# Create and navigate to your project directory
|
|
34
|
+
mkdir my-agent-project
|
|
35
|
+
cd my-agent-project
|
|
36
|
+
|
|
37
|
+
# Initialize Dank project
|
|
38
|
+
dank init my-agent-project
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
This creates:
|
|
42
|
+
```
|
|
43
|
+
my-agent-project/
|
|
44
|
+
├── dank.config.js # Your agent configuration
|
|
45
|
+
├── agents/ # Custom agent code (optional)
|
|
46
|
+
│ └── example-agent.js
|
|
47
|
+
└── .dank/ # Generated files
|
|
48
|
+
└── project.yaml
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
### 3. Set up environment variables
|
|
52
|
+
Create a `.env` file or export environment variables:
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
# For OpenAI
|
|
56
|
+
export OPENAI_API_KEY="your-openai-api-key"
|
|
57
|
+
|
|
58
|
+
# For Anthropic
|
|
59
|
+
export ANTHROPIC_API_KEY="your-anthropic-api-key"
|
|
60
|
+
|
|
61
|
+
# For Cohere
|
|
62
|
+
export COHERE_API_KEY="your-cohere-api-key"
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
### 4. Configure your agents
|
|
66
|
+
Edit `dank.config.js` to define your agents:
|
|
67
|
+
|
|
68
|
+
```javascript
|
|
69
|
+
const { createAgent } = require('dank');
|
|
70
|
+
|
|
71
|
+
module.exports = {
|
|
72
|
+
name: 'my-agent-project',
|
|
73
|
+
|
|
74
|
+
agents: [
|
|
75
|
+
createAgent('assistant')
|
|
76
|
+
.setLLM('openai', {
|
|
77
|
+
apiKey: process.env.OPENAI_API_KEY,
|
|
78
|
+
model: 'gpt-3.5-turbo',
|
|
79
|
+
temperature: 0.7
|
|
80
|
+
})
|
|
81
|
+
.setPrompt('You are a helpful assistant that responds with enthusiasm!')
|
|
82
|
+
.setResources({
|
|
83
|
+
memory: '512m',
|
|
84
|
+
cpu: 1
|
|
85
|
+
})
|
|
86
|
+
.addHandler('output', (data) => {
|
|
87
|
+
console.log('Assistant says:', data);
|
|
88
|
+
})
|
|
89
|
+
]
|
|
90
|
+
};
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
### 5. Build Docker images (optional)
|
|
94
|
+
```bash
|
|
95
|
+
# Build agent images (base image is pulled automatically)
|
|
96
|
+
dank build
|
|
97
|
+
|
|
98
|
+
# Or build only the base image
|
|
99
|
+
dank build --base
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
### 6. Start your agents
|
|
103
|
+
```bash
|
|
104
|
+
# Start all agents
|
|
105
|
+
dank run
|
|
106
|
+
|
|
107
|
+
# Or run in detached mode (background)
|
|
108
|
+
dank run --detached
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
### 7. Monitor your agents
|
|
112
|
+
```bash
|
|
113
|
+
# Check agent status
|
|
114
|
+
dank status
|
|
115
|
+
|
|
116
|
+
# Watch status in real-time
|
|
117
|
+
dank status --watch
|
|
118
|
+
|
|
119
|
+
# View agent logs
|
|
120
|
+
dank logs assistant
|
|
121
|
+
|
|
122
|
+
# Follow logs in real-time
|
|
123
|
+
dank logs assistant --follow
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
## 📋 CLI Commands
|
|
127
|
+
|
|
128
|
+
### Core Commands
|
|
129
|
+
```bash
|
|
130
|
+
dank run # Start all defined agents
|
|
131
|
+
dank status # Show agent status
|
|
132
|
+
dank stop [agents...] # Stop specific agents
|
|
133
|
+
dank stop --all # Stop all agents
|
|
134
|
+
dank logs [agent] # View agent logs
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
### Management Commands
|
|
138
|
+
```bash
|
|
139
|
+
dank init [name] # Initialize new project
|
|
140
|
+
dank build # Build Docker images
|
|
141
|
+
dank clean # Clean up Docker resources
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
### Advanced Options
|
|
145
|
+
```bash
|
|
146
|
+
dank run --detached # Run in background
|
|
147
|
+
dank run --no-build # Skip rebuilding images (default is to rebuild)
|
|
148
|
+
dank run --pull # Pull latest base image before building
|
|
149
|
+
dank status --watch # Live status monitoring
|
|
150
|
+
dank logs --follow # Follow log output
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
## 🤖 Agent Configuration
|
|
154
|
+
|
|
155
|
+
### Basic Agent Setup
|
|
156
|
+
```javascript
|
|
157
|
+
const agent = createAgent('my-agent')
|
|
158
|
+
.setLLM('openai', {
|
|
159
|
+
apiKey: process.env.OPENAI_API_KEY,
|
|
160
|
+
model: 'gpt-4',
|
|
161
|
+
temperature: 0.8
|
|
162
|
+
})
|
|
163
|
+
.setPrompt('Your system prompt here')
|
|
164
|
+
.setPromptingServer({
|
|
165
|
+
protocol: 'http',
|
|
166
|
+
port: 3000,
|
|
167
|
+
authentication: false,
|
|
168
|
+
maxConnections: 50
|
|
169
|
+
})
|
|
170
|
+
.setResources({
|
|
171
|
+
memory: '1g',
|
|
172
|
+
cpu: 2,
|
|
173
|
+
timeout: 60000
|
|
174
|
+
});
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
### Supported LLM Providers
|
|
178
|
+
|
|
179
|
+
#### OpenAI
|
|
180
|
+
```javascript
|
|
181
|
+
.setLLM('openai', {
|
|
182
|
+
apiKey: 'your-api-key',
|
|
183
|
+
model: 'gpt-4',
|
|
184
|
+
temperature: 0.7,
|
|
185
|
+
maxTokens: 1000
|
|
186
|
+
})
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
#### Anthropic
|
|
190
|
+
```javascript
|
|
191
|
+
.setLLM('anthropic', {
|
|
192
|
+
apiKey: 'your-api-key',
|
|
193
|
+
model: 'claude-3-sonnet-20240229',
|
|
194
|
+
maxTokens: 1000
|
|
195
|
+
})
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
#### Ollama (Local)
|
|
199
|
+
```javascript
|
|
200
|
+
.setLLM('ollama', {
|
|
201
|
+
baseURL: 'http://localhost:11434',
|
|
202
|
+
model: 'llama2'
|
|
203
|
+
})
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
#### Cohere
|
|
207
|
+
```javascript
|
|
208
|
+
.setLLM('cohere', {
|
|
209
|
+
apiKey: 'your-api-key',
|
|
210
|
+
model: 'command',
|
|
211
|
+
temperature: 0.7
|
|
212
|
+
})
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
#### Hugging Face
|
|
216
|
+
```javascript
|
|
217
|
+
.setLLM('huggingface', {
|
|
218
|
+
apiKey: 'your-api-key',
|
|
219
|
+
model: 'microsoft/DialoGPT-medium'
|
|
220
|
+
})
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
#### Custom Provider
|
|
224
|
+
```javascript
|
|
225
|
+
.setLLM('custom', {
|
|
226
|
+
baseURL: 'https://api.your-provider.com',
|
|
227
|
+
apiKey: 'your-key',
|
|
228
|
+
model: 'your-model'
|
|
229
|
+
})
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
### Event Handlers
|
|
233
|
+
|
|
234
|
+
Dank provides a comprehensive event system with three main sources of events. Each event handler follows specific naming patterns for maximum flexibility and control.
|
|
235
|
+
|
|
236
|
+
> **🆕 Auto-Detection**: Dank automatically enables communication features based on your usage:
|
|
237
|
+
> - **Event Handlers**: Auto-enabled when you add `.addHandler()` calls
|
|
238
|
+
> - **Direct Prompting**: Auto-enabled when you use `.setPrompt()` + `.setLLM()`
|
|
239
|
+
> - **HTTP API**: Auto-enabled when you add routes with `.get()`, `.post()`, etc.
|
|
240
|
+
|
|
241
|
+
#### 🎯 **Event Handler Patterns**
|
|
242
|
+
|
|
243
|
+
##### **1. Direct Prompting Events** (`request_output`)
|
|
244
|
+
Events triggered when agents receive and respond to direct prompts via WebSocket or HTTP:
|
|
35
245
|
|
|
36
|
-
|
|
246
|
+
```javascript
|
|
247
|
+
agent
|
|
248
|
+
// Main LLM response event
|
|
249
|
+
.addHandler('request_output', (data) => {
|
|
250
|
+
console.log('LLM Response:', {
|
|
251
|
+
prompt: data.prompt, // Original prompt
|
|
252
|
+
finalPrompt: data.finalPrompt, // Modified prompt (if changed)
|
|
253
|
+
response: data.response, // LLM response
|
|
254
|
+
conversationId: data.conversationId,
|
|
255
|
+
processingTime: data.processingTime,
|
|
256
|
+
promptModified: data.promptModified, // Boolean: was prompt modified?
|
|
257
|
+
usage: data.usage,
|
|
258
|
+
model: data.model
|
|
259
|
+
});
|
|
260
|
+
})
|
|
261
|
+
|
|
262
|
+
// Lifecycle events with modification capabilities
|
|
263
|
+
.addHandler('request_output:start', (data) => {
|
|
264
|
+
console.log('Processing prompt:', data.conversationId);
|
|
265
|
+
console.log('Original prompt:', data.prompt);
|
|
266
|
+
|
|
267
|
+
// ✨ MODIFY PROMPT: Return modified data to change the prompt sent to LLM
|
|
268
|
+
const enhancedPrompt = `Context: You are a helpful assistant. Please be concise and friendly.\n\nUser Question: ${data.prompt}`;
|
|
269
|
+
|
|
270
|
+
return {
|
|
271
|
+
prompt: enhancedPrompt // This will replace the original prompt
|
|
272
|
+
};
|
|
273
|
+
})
|
|
274
|
+
|
|
275
|
+
.addHandler('request_output:end', (data) => {
|
|
276
|
+
console.log('Completed in:', data.processingTime + 'ms');
|
|
277
|
+
console.log('Original response:', data.response.substring(0, 50) + '...');
|
|
278
|
+
|
|
279
|
+
// ✨ MODIFY RESPONSE: Return modified data to change the response sent to caller
|
|
280
|
+
const enhancedResponse = `${data.response}\n\n---\n💡 This response was generated by Dank Framework`;
|
|
281
|
+
|
|
282
|
+
return {
|
|
283
|
+
response: enhancedResponse // This will replace the original response
|
|
284
|
+
};
|
|
285
|
+
})
|
|
286
|
+
|
|
287
|
+
.addHandler('request_output:error', (data) => {
|
|
288
|
+
console.error('Prompt processing failed:', data.error);
|
|
289
|
+
});
|
|
290
|
+
```
|
|
291
|
+
|
|
292
|
+
**🔄 Event Modification Capabilities:**
|
|
293
|
+
|
|
294
|
+
- **`request_output:start`**: Can modify the prompt before it's sent to the LLM by returning an object with a `prompt` property
|
|
295
|
+
- **`request_output:end`**: Can modify the response before it's sent back to the caller by returning an object with a `response` property
|
|
296
|
+
- **Event Data**: All events include both original and final values, plus modification flags for tracking changes
|
|
297
|
+
|
|
298
|
+
**⏱️ Event Flow Timeline:**
|
|
37
299
|
|
|
38
|
-
|
|
39
|
-
-
|
|
40
|
-
- `
|
|
41
|
-
- `npm run status` - Check agent status
|
|
42
|
-
- `npm run logs` - View agent logs
|
|
43
|
-
- `npm run build` - Build agent images
|
|
44
|
-
- `npm run clean` - Clean up containers and images
|
|
300
|
+
1. **`request_output:start`** → Fires when prompt is received
|
|
301
|
+
- Can modify prompt before LLM processing
|
|
302
|
+
- Contains: `{ prompt, conversationId, context, timestamp }`
|
|
45
303
|
|
|
46
|
-
|
|
304
|
+
2. **LLM Processing** → The (potentially modified) prompt is sent to the LLM
|
|
47
305
|
|
|
48
|
-
|
|
306
|
+
3. **`request_output`** → Fires after LLM responds successfully
|
|
307
|
+
- Contains: `{ prompt, finalPrompt, response, conversationId, promptModified, ... }`
|
|
49
308
|
|
|
50
|
-
|
|
51
|
-
|
|
309
|
+
4. **`request_output:end`** → Fires after `request_output`, before sending to caller
|
|
310
|
+
- Can modify response before returning to client
|
|
311
|
+
- Contains: `{ prompt, finalPrompt, response, conversationId, promptModified, success, ... }`
|
|
312
|
+
|
|
313
|
+
5. **Response Sent** → The (potentially modified) response is sent back to the caller
|
|
314
|
+
|
|
315
|
+
**💡 Practical Examples:**
|
|
52
316
|
|
|
53
317
|
```javascript
|
|
318
|
+
// Example 1: Add context and formatting to prompts
|
|
54
319
|
.addHandler('request_output:start', (data) => {
|
|
55
|
-
//
|
|
56
|
-
|
|
320
|
+
// Add system context and format the user's question
|
|
321
|
+
const enhancedPrompt = `System: You are a helpful AI assistant. Be concise and professional.
|
|
322
|
+
|
|
323
|
+
User Question: ${data.prompt}
|
|
324
|
+
|
|
325
|
+
Please provide a clear, helpful response.`;
|
|
326
|
+
|
|
327
|
+
return { prompt: enhancedPrompt };
|
|
57
328
|
})
|
|
58
329
|
|
|
330
|
+
// Example 2: Add metadata and branding to responses
|
|
59
331
|
.addHandler('request_output:end', (data) => {
|
|
60
|
-
//
|
|
61
|
-
|
|
332
|
+
// Add footer with metadata and branding
|
|
333
|
+
const brandedResponse = `${data.response}
|
|
334
|
+
|
|
335
|
+
---
|
|
336
|
+
🤖 Generated by Dank Framework Agent
|
|
337
|
+
⏱️ Processing time: ${data.processingTime}ms
|
|
338
|
+
🆔 Conversation: ${data.conversationId}`;
|
|
339
|
+
|
|
340
|
+
return { response: brandedResponse };
|
|
341
|
+
})
|
|
342
|
+
|
|
343
|
+
// Example 3: Log and analyze all interactions
|
|
344
|
+
.addHandler('request_output', (data) => {
|
|
345
|
+
// Log for analytics
|
|
346
|
+
console.log('Interaction logged:', {
|
|
347
|
+
originalPrompt: data.prompt,
|
|
348
|
+
modifiedPrompt: data.finalPrompt,
|
|
349
|
+
wasModified: data.promptModified,
|
|
350
|
+
responseLength: data.response.length,
|
|
351
|
+
model: data.model,
|
|
352
|
+
usage: data.usage
|
|
353
|
+
});
|
|
62
354
|
})
|
|
63
355
|
```
|
|
64
356
|
|
|
65
|
-
|
|
66
|
-
|
|
357
|
+
##### **2. Tool Events** (`tool:*`)
|
|
358
|
+
Events triggered by tool usage, following the pattern `tool:<tool-name>:<action>:<specifics>`:
|
|
67
359
|
|
|
68
360
|
```javascript
|
|
69
|
-
|
|
70
|
-
|
|
361
|
+
agent
|
|
362
|
+
// HTTP Server Tool Events
|
|
363
|
+
.addHandler('tool:http-server:*', (data) => {
|
|
364
|
+
// Listen to ALL HTTP server events
|
|
365
|
+
console.log('HTTP Activity:', data.type, data.method, data.path);
|
|
366
|
+
})
|
|
367
|
+
|
|
368
|
+
.addHandler('tool:http-server:call', (data) => {
|
|
369
|
+
// All incoming HTTP requests
|
|
370
|
+
console.log('Request:', data.method, data.path, data.body);
|
|
371
|
+
})
|
|
372
|
+
|
|
373
|
+
.addHandler('tool:http-server:response', (data) => {
|
|
374
|
+
// All HTTP responses
|
|
375
|
+
console.log('Response:', data.statusCode, data.processingTime);
|
|
376
|
+
})
|
|
377
|
+
|
|
378
|
+
.addHandler('tool:http-server:call:post', (data) => {
|
|
379
|
+
// Only POST requests
|
|
380
|
+
console.log('POST Request:', data.path, data.body);
|
|
381
|
+
})
|
|
382
|
+
|
|
383
|
+
.addHandler('tool:http-server:response:get', (data) => {
|
|
384
|
+
// Only GET responses
|
|
385
|
+
console.log('GET Response:', data.path, data.responseData);
|
|
386
|
+
})
|
|
387
|
+
|
|
388
|
+
.addHandler('tool:http-server:error', (data) => {
|
|
389
|
+
// HTTP server errors
|
|
390
|
+
console.error('HTTP Error:', data.error);
|
|
391
|
+
});
|
|
392
|
+
```
|
|
393
|
+
|
|
394
|
+
**Tool Event Pattern Structure:**
|
|
395
|
+
- `tool:<tool-name>:*` - All events for a specific tool
|
|
396
|
+
- `tool:<tool-name>:call` - Tool invocation/input events
|
|
397
|
+
- `tool:<tool-name>:response` - Tool output/result events
|
|
398
|
+
- `tool:<tool-name>:call:<method>` - Specific method calls (e.g., POST, GET)
|
|
399
|
+
- `tool:<tool-name>:response:<method>` - Specific method responses
|
|
400
|
+
- `tool:<tool-name>:error` - Tool-specific errors
|
|
401
|
+
|
|
402
|
+
##### **3. System Events** (Legacy/System)
|
|
403
|
+
Traditional system-level events:
|
|
404
|
+
|
|
405
|
+
```javascript
|
|
406
|
+
agent
|
|
407
|
+
.addHandler('output', (data) => {
|
|
408
|
+
console.log('General output:', data);
|
|
409
|
+
})
|
|
410
|
+
|
|
411
|
+
.addHandler('error', (error) => {
|
|
412
|
+
console.error('System error:', error);
|
|
413
|
+
})
|
|
414
|
+
|
|
415
|
+
.addHandler('heartbeat', () => {
|
|
416
|
+
console.log('Agent heartbeat');
|
|
417
|
+
})
|
|
418
|
+
|
|
419
|
+
.addHandler('start', () => {
|
|
420
|
+
console.log('Agent started');
|
|
421
|
+
})
|
|
422
|
+
|
|
423
|
+
.addHandler('stop', () => {
|
|
424
|
+
console.log('Agent stopped');
|
|
425
|
+
});
|
|
426
|
+
```
|
|
427
|
+
|
|
428
|
+
#### 🔥 **Advanced Event Patterns**
|
|
429
|
+
|
|
430
|
+
**Wildcard Matching:**
|
|
431
|
+
```javascript
|
|
432
|
+
// Listen to all tool events
|
|
433
|
+
.addHandler('tool:*', (data) => {
|
|
434
|
+
console.log('Any tool activity:', data);
|
|
435
|
+
})
|
|
436
|
+
|
|
437
|
+
// Listen to all HTTP responses
|
|
438
|
+
.addHandler('tool:http-server:response:*', (data) => {
|
|
439
|
+
console.log('Any HTTP response:', data);
|
|
71
440
|
})
|
|
72
441
|
|
|
73
|
-
|
|
74
|
-
|
|
442
|
+
// Listen to all request outputs
|
|
443
|
+
.addHandler('request_output:*', (data) => {
|
|
444
|
+
console.log('Any request event:', data);
|
|
75
445
|
})
|
|
76
446
|
```
|
|
77
447
|
|
|
78
|
-
|
|
79
|
-
|
|
448
|
+
**Multiple Handlers:**
|
|
449
|
+
```javascript
|
|
450
|
+
// Multiple handlers for the same event
|
|
451
|
+
agent
|
|
452
|
+
.addHandler('request_output', (data) => {
|
|
453
|
+
// Log to console
|
|
454
|
+
console.log('Response:', data.response);
|
|
455
|
+
})
|
|
456
|
+
.addHandler('request_output', (data) => {
|
|
457
|
+
// Save to database
|
|
458
|
+
saveToDatabase(data);
|
|
459
|
+
})
|
|
460
|
+
.addHandler('request_output', (data) => {
|
|
461
|
+
// Send to analytics
|
|
462
|
+
trackAnalytics(data);
|
|
463
|
+
});
|
|
464
|
+
```
|
|
80
465
|
|
|
466
|
+
#### 📊 **Event Data Structures**
|
|
467
|
+
|
|
468
|
+
**Request Output Event Data:**
|
|
81
469
|
```javascript
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
470
|
+
{
|
|
471
|
+
prompt: "User's input prompt",
|
|
472
|
+
response: "LLM's response",
|
|
473
|
+
conversationId: "unique-conversation-id",
|
|
474
|
+
context: { protocol: "websocket", clientId: "..." },
|
|
475
|
+
usage: { total_tokens: 150, prompt_tokens: 50, completion_tokens: 100 },
|
|
476
|
+
model: "gpt-3.5-turbo",
|
|
477
|
+
processingTime: 1250,
|
|
478
|
+
timestamp: "2024-01-15T10:30:00.000Z"
|
|
479
|
+
}
|
|
480
|
+
```
|
|
481
|
+
|
|
482
|
+
**Tool HTTP Event Data:**
|
|
483
|
+
```javascript
|
|
484
|
+
{
|
|
485
|
+
requestId: "unique-request-id",
|
|
486
|
+
method: "POST",
|
|
487
|
+
path: "/api/chat",
|
|
488
|
+
headers: { "content-type": "application/json" },
|
|
489
|
+
body: { message: "Hello" },
|
|
490
|
+
query: {},
|
|
491
|
+
params: {},
|
|
492
|
+
statusCode: 200,
|
|
493
|
+
responseData: { response: "Hi there!" },
|
|
494
|
+
processingTime: 45,
|
|
495
|
+
timestamp: "2024-01-15T10:30:00.000Z"
|
|
496
|
+
}
|
|
497
|
+
```
|
|
85
498
|
|
|
86
|
-
|
|
87
|
-
|
|
499
|
+
#### 🎛️ **Communication Method Control**
|
|
500
|
+
|
|
501
|
+
Each communication method can be enabled/disabled independently:
|
|
502
|
+
|
|
503
|
+
```javascript
|
|
504
|
+
createAgent('flexible-agent')
|
|
505
|
+
// Configure direct prompting with specific settings
|
|
506
|
+
.setPromptingServer({
|
|
507
|
+
protocol: 'websocket',
|
|
508
|
+
port: 3000,
|
|
509
|
+
authentication: false,
|
|
510
|
+
maxConnections: 50
|
|
511
|
+
})
|
|
512
|
+
.disableDirectPrompting() // Disable if needed
|
|
513
|
+
|
|
514
|
+
// Enable HTTP API
|
|
515
|
+
.enableHttp({ port: 3001 })
|
|
516
|
+
|
|
517
|
+
// Listen to direct prompting events only
|
|
518
|
+
.addHandler('request_output', (data) => {
|
|
519
|
+
console.log('WebSocket response:', data.response);
|
|
520
|
+
})
|
|
521
|
+
|
|
522
|
+
// HTTP events will fire when routes are added
|
|
523
|
+
.get('/api/status', (req, res) => {
|
|
524
|
+
res.json({ status: 'ok' });
|
|
525
|
+
})
|
|
526
|
+
.addHandler('tool:http-server:*', (data) => {
|
|
527
|
+
console.log('HTTP activity:', data);
|
|
528
|
+
});
|
|
529
|
+
```
|
|
530
|
+
|
|
531
|
+
### Resource Management
|
|
532
|
+
|
|
533
|
+
Configure container resources:
|
|
534
|
+
|
|
535
|
+
```javascript
|
|
536
|
+
.setResources({
|
|
537
|
+
memory: '512m', // Memory limit (512m, 1g, etc.)
|
|
538
|
+
cpu: 1, // CPU allocation (0.5, 1, 2, etc.)
|
|
539
|
+
timeout: 30000, // Request timeout in ms
|
|
540
|
+
maxRestarts: 3 // Max container restarts
|
|
88
541
|
})
|
|
89
542
|
```
|
|
90
543
|
|
|
91
|
-
##
|
|
544
|
+
## 🏗️ Project Structure
|
|
545
|
+
|
|
546
|
+
```
|
|
547
|
+
my-project/
|
|
548
|
+
├── dank.config.js # Agent configuration
|
|
549
|
+
├── agents/ # Custom agent code (optional)
|
|
550
|
+
│ └── example-agent.js
|
|
551
|
+
└── .dank/ # Generated files
|
|
552
|
+
├── project.yaml # Project state
|
|
553
|
+
└── logs/ # Agent logs
|
|
554
|
+
```
|
|
555
|
+
|
|
556
|
+
## 📦 Package Exports
|
|
557
|
+
|
|
558
|
+
When you install Dank via npm, you can import the following:
|
|
559
|
+
|
|
560
|
+
```javascript
|
|
561
|
+
const {
|
|
562
|
+
createAgent, // Convenience function to create agents
|
|
563
|
+
DankAgent, // Main agent class
|
|
564
|
+
DankProject, // Project management class
|
|
565
|
+
SUPPORTED_LLMS, // List of supported LLM providers
|
|
566
|
+
DEFAULT_CONFIG // Default configuration values
|
|
567
|
+
} = require("dank");
|
|
568
|
+
```
|
|
569
|
+
|
|
570
|
+
## 📋 Example Files
|
|
571
|
+
|
|
572
|
+
The `examples/` directory contains two configuration files:
|
|
573
|
+
|
|
574
|
+
- **`dank.config.js`** - Local development example (uses `../lib/index.js`)
|
|
575
|
+
- **`dank.config.template.js`** - Production template (uses `require("dank")`)
|
|
576
|
+
|
|
577
|
+
### For Local Development
|
|
578
|
+
```bash
|
|
579
|
+
# Use the example file directly
|
|
580
|
+
dank run --config example/dank.config.js
|
|
581
|
+
```
|
|
582
|
+
|
|
583
|
+
### For Production Use
|
|
584
|
+
```bash
|
|
585
|
+
# 1. Copy the template to your project
|
|
586
|
+
cp example/dank.config.template.js ./dank.config.js
|
|
587
|
+
|
|
588
|
+
# 2. Install dank as a dependency
|
|
589
|
+
npm install dank-ai
|
|
590
|
+
|
|
591
|
+
# 3. The template already uses the correct import
|
|
592
|
+
# const { createAgent } = require("dank");
|
|
593
|
+
|
|
594
|
+
# 4. Run your agents
|
|
595
|
+
dank run
|
|
596
|
+
```
|
|
597
|
+
|
|
598
|
+
## 🐳 Docker Architecture
|
|
599
|
+
|
|
600
|
+
Dank uses a layered Docker approach:
|
|
601
|
+
|
|
602
|
+
1. **Base Image** (`deltadarkly/dank-agent-base`): Common runtime with Node.js, LLM clients
|
|
603
|
+
2. **Agent Images**: Extend base image with agent-specific code and custom tags
|
|
604
|
+
3. **Containers**: Running instances with resource limits and networking
|
|
605
|
+
|
|
606
|
+
### Container Features
|
|
607
|
+
- **Isolated Environments**: Each agent runs in its own container
|
|
608
|
+
- **Resource Limits**: Memory and CPU constraints per agent
|
|
609
|
+
- **Health Monitoring**: Built-in health checks and status reporting
|
|
610
|
+
- **Automatic Restarts**: Container restart policies for reliability
|
|
611
|
+
- **Logging**: Centralized log collection and viewing
|
|
612
|
+
|
|
613
|
+
### 🚀 Automatic Docker Management
|
|
614
|
+
|
|
615
|
+
Dank automatically handles Docker installation and startup for you:
|
|
616
|
+
|
|
617
|
+
#### **Auto-Detection & Installation**
|
|
618
|
+
When you run any Dank command, it will:
|
|
619
|
+
1. **Check if Docker is installed** - Runs `docker --version` to detect installation
|
|
620
|
+
2. **Install Docker if missing** - Automatically installs Docker for your platform:
|
|
621
|
+
- **macOS**: Uses Homebrew to install Docker Desktop
|
|
622
|
+
- **Linux**: Installs Docker CE via apt package manager
|
|
623
|
+
- **Windows**: Uses Chocolatey to install Docker Desktop
|
|
624
|
+
3. **Start Docker if stopped** - Automatically starts Docker service
|
|
625
|
+
4. **Wait for availability** - Ensures Docker is ready before proceeding
|
|
626
|
+
|
|
627
|
+
#### **Platform-Specific Installation**
|
|
628
|
+
|
|
629
|
+
**macOS:**
|
|
630
|
+
```bash
|
|
631
|
+
# Dank will automatically run:
|
|
632
|
+
brew install --cask docker
|
|
633
|
+
open -a Docker
|
|
634
|
+
```
|
|
635
|
+
|
|
636
|
+
**Linux (Ubuntu/Debian):**
|
|
637
|
+
```bash
|
|
638
|
+
# Dank will automatically run:
|
|
639
|
+
sudo apt-get update
|
|
640
|
+
sudo apt-get install -y docker-ce docker-ce-cli containerd.io
|
|
641
|
+
sudo systemctl start docker
|
|
642
|
+
sudo systemctl enable docker
|
|
643
|
+
sudo usermod -aG docker $USER
|
|
644
|
+
```
|
|
645
|
+
|
|
646
|
+
**Windows:**
|
|
647
|
+
```bash
|
|
648
|
+
# Dank will automatically run:
|
|
649
|
+
choco install docker-desktop -y
|
|
650
|
+
start "" "C:\Program Files\Docker\Docker\Docker Desktop.exe"
|
|
651
|
+
```
|
|
652
|
+
|
|
653
|
+
#### **Manual Fallback**
|
|
654
|
+
If automatic installation fails, Dank will provide clear instructions:
|
|
655
|
+
```bash
|
|
656
|
+
# Example output when manual installation is needed
|
|
657
|
+
❌ Docker installation failed: Homebrew not found
|
|
658
|
+
💡 Please install Docker Desktop manually from:
|
|
659
|
+
https://www.docker.com/products/docker-desktop/
|
|
660
|
+
```
|
|
661
|
+
|
|
662
|
+
#### **Status Messages**
|
|
663
|
+
Dank provides clear feedback during the process:
|
|
664
|
+
```bash
|
|
665
|
+
🔍 Checking Docker availability...
|
|
666
|
+
📦 Docker is not installed. Installing Docker...
|
|
667
|
+
🖥️ Installing Docker Desktop for macOS...
|
|
668
|
+
⏳ Installing Docker Desktop via Homebrew...
|
|
669
|
+
✅ Docker installation completed
|
|
670
|
+
🚀 Starting Docker Desktop...
|
|
671
|
+
⏳ Waiting for Docker to become available...
|
|
672
|
+
✅ Docker is now available
|
|
673
|
+
🐳 Docker connection established
|
|
674
|
+
```
|
|
675
|
+
|
|
676
|
+
## 💼 Using Dank in Your Project
|
|
677
|
+
|
|
678
|
+
### Step-by-Step Integration Guide
|
|
679
|
+
|
|
680
|
+
#### 1. Project Setup
|
|
681
|
+
```bash
|
|
682
|
+
# In your existing project directory
|
|
683
|
+
npm install -g dank-ai
|
|
684
|
+
|
|
685
|
+
# Initialize Dank configuration
|
|
686
|
+
dank init
|
|
687
|
+
|
|
688
|
+
# This creates dank.config.js in your current directory
|
|
689
|
+
```
|
|
690
|
+
|
|
691
|
+
#### 2. Basic Agent Configuration
|
|
692
|
+
Start with a simple agent configuration in `dank.config.js`:
|
|
693
|
+
|
|
694
|
+
```javascript
|
|
695
|
+
const { createAgent } = require('dank');
|
|
696
|
+
|
|
697
|
+
module.exports = {
|
|
698
|
+
name: 'my-project',
|
|
699
|
+
|
|
700
|
+
agents: [
|
|
701
|
+
// Simple assistant agent
|
|
702
|
+
createAgent('helper')
|
|
703
|
+
.setLLM('openai', {
|
|
704
|
+
apiKey: process.env.OPENAI_API_KEY,
|
|
705
|
+
model: 'gpt-3.5-turbo'
|
|
706
|
+
})
|
|
707
|
+
.setPrompt('You are a helpful assistant.')
|
|
708
|
+
.addHandler('output', console.log)
|
|
709
|
+
]
|
|
710
|
+
};
|
|
711
|
+
```
|
|
712
|
+
|
|
713
|
+
#### 3. Multi-Agent Setup
|
|
714
|
+
Configure multiple specialized agents:
|
|
715
|
+
|
|
716
|
+
```javascript
|
|
717
|
+
const { createAgent } = require('dank');
|
|
718
|
+
|
|
719
|
+
module.exports = {
|
|
720
|
+
name: 'multi-agent-system',
|
|
721
|
+
|
|
722
|
+
agents: [
|
|
723
|
+
// Customer service agent
|
|
724
|
+
createAgent('customer-service')
|
|
725
|
+
.setLLM('openai', {
|
|
726
|
+
apiKey: process.env.OPENAI_API_KEY,
|
|
727
|
+
model: 'gpt-3.5-turbo',
|
|
728
|
+
temperature: 0.7
|
|
729
|
+
})
|
|
730
|
+
.setPrompt(`
|
|
731
|
+
You are a friendly customer service representative.
|
|
732
|
+
- Be helpful and professional
|
|
733
|
+
- Resolve customer issues quickly
|
|
734
|
+
- Escalate complex problems appropriately
|
|
735
|
+
`)
|
|
736
|
+
.setResources({ memory: '512m', cpu: 1 })
|
|
737
|
+
.addHandler('output', (data) => {
|
|
738
|
+
console.log('[Customer Service]:', data);
|
|
739
|
+
// Add your business logic here
|
|
740
|
+
}),
|
|
741
|
+
|
|
742
|
+
// Data analyst agent
|
|
743
|
+
createAgent('analyst')
|
|
744
|
+
.setLLM('openai', {
|
|
745
|
+
apiKey: process.env.OPENAI_API_KEY,
|
|
746
|
+
model: 'gpt-4',
|
|
747
|
+
temperature: 0.3
|
|
748
|
+
})
|
|
749
|
+
.setPrompt(`
|
|
750
|
+
You are a data analyst expert.
|
|
751
|
+
- Analyze trends and patterns
|
|
752
|
+
- Provide statistical insights
|
|
753
|
+
- Create actionable recommendations
|
|
754
|
+
`)
|
|
755
|
+
.setResources({ memory: '1g', cpu: 2 })
|
|
756
|
+
.addHandler('output', (data) => {
|
|
757
|
+
console.log('[Analyst]:', data);
|
|
758
|
+
// Save analysis results to database
|
|
759
|
+
}),
|
|
760
|
+
|
|
761
|
+
// Content creator agent
|
|
762
|
+
createAgent('content-creator')
|
|
763
|
+
.setLLM('anthropic', {
|
|
764
|
+
apiKey: process.env.ANTHROPIC_API_KEY,
|
|
765
|
+
model: 'claude-3-sonnet-20240229'
|
|
766
|
+
})
|
|
767
|
+
.setPrompt(`
|
|
768
|
+
You are a creative content writer.
|
|
769
|
+
- Write engaging, original content
|
|
770
|
+
- Adapt tone to target audience
|
|
771
|
+
- Follow brand guidelines
|
|
772
|
+
`)
|
|
773
|
+
.setResources({ memory: '512m', cpu: 1 })
|
|
774
|
+
.addHandler('output', (data) => {
|
|
775
|
+
console.log('[Content Creator]:', data);
|
|
776
|
+
// Process and publish content
|
|
777
|
+
})
|
|
778
|
+
]
|
|
779
|
+
};
|
|
780
|
+
```
|
|
781
|
+
|
|
782
|
+
### 🎯 Common Use Cases
|
|
783
|
+
|
|
784
|
+
#### Use Case 1: Customer Support Automation
|
|
785
|
+
```javascript
|
|
786
|
+
createAgent('support-bot')
|
|
787
|
+
.setLLM('openai', {
|
|
788
|
+
apiKey: process.env.OPENAI_API_KEY,
|
|
789
|
+
model: 'gpt-3.5-turbo'
|
|
790
|
+
})
|
|
791
|
+
.setPrompt(`
|
|
792
|
+
You are a customer support specialist for [Your Company].
|
|
793
|
+
|
|
794
|
+
Guidelines:
|
|
795
|
+
- Always be polite and helpful
|
|
796
|
+
- For technical issues, provide step-by-step solutions
|
|
797
|
+
- If you cannot resolve an issue, escalate to human support
|
|
798
|
+
- Use the customer's name when available
|
|
799
|
+
|
|
800
|
+
Knowledge Base:
|
|
801
|
+
- Product features: [list your features]
|
|
802
|
+
- Common issues: [list common problems and solutions]
|
|
803
|
+
- Contact info: support@yourcompany.com
|
|
804
|
+
`)
|
|
805
|
+
.addHandler('output', (response) => {
|
|
806
|
+
// Send response back to customer via your chat system
|
|
807
|
+
sendToCustomer(response);
|
|
808
|
+
})
|
|
809
|
+
.addHandler('error', (error) => {
|
|
810
|
+
// Fallback to human support
|
|
811
|
+
escalateToHuman(error);
|
|
812
|
+
});
|
|
813
|
+
```
|
|
814
|
+
|
|
815
|
+
#### Use Case 2: Content Generation Pipeline
|
|
816
|
+
```javascript
|
|
817
|
+
const contentAgents = [
|
|
818
|
+
// Research agent
|
|
819
|
+
createAgent('researcher')
|
|
820
|
+
.setLLM('openai', { model: 'gpt-4' })
|
|
821
|
+
.setPrompt('Research and gather information on given topics')
|
|
822
|
+
.addHandler('output', (research) => {
|
|
823
|
+
// Pass research to writer agent
|
|
824
|
+
triggerContentCreation(research);
|
|
825
|
+
}),
|
|
826
|
+
|
|
827
|
+
// Writer agent
|
|
828
|
+
createAgent('writer')
|
|
829
|
+
.setLLM('anthropic', { model: 'claude-3-sonnet' })
|
|
830
|
+
.setPrompt('Write engaging blog posts based on research data')
|
|
831
|
+
.addHandler('output', (article) => {
|
|
832
|
+
// Save draft and notify editor
|
|
833
|
+
saveDraft(article);
|
|
834
|
+
notifyEditor(article);
|
|
835
|
+
}),
|
|
836
|
+
|
|
837
|
+
// SEO optimizer agent
|
|
838
|
+
createAgent('seo-optimizer')
|
|
839
|
+
.setLLM('openai', { model: 'gpt-3.5-turbo' })
|
|
840
|
+
.setPrompt('Optimize content for SEO and readability')
|
|
841
|
+
.addHandler('output', (optimizedContent) => {
|
|
842
|
+
// Publish optimized content
|
|
843
|
+
publishContent(optimizedContent);
|
|
844
|
+
})
|
|
845
|
+
];
|
|
846
|
+
```
|
|
847
|
+
|
|
848
|
+
#### Use Case 3: Data Analysis Workflow
|
|
849
|
+
```javascript
|
|
850
|
+
createAgent('data-processor')
|
|
851
|
+
.setLLM('openai', {
|
|
852
|
+
apiKey: process.env.OPENAI_API_KEY,
|
|
853
|
+
model: 'gpt-4',
|
|
854
|
+
temperature: 0.1 // Low temperature for consistent analysis
|
|
855
|
+
})
|
|
856
|
+
.setPrompt(`
|
|
857
|
+
You are a data analyst. Analyze the provided data and:
|
|
858
|
+
1. Identify key trends and patterns
|
|
859
|
+
2. Calculate important metrics
|
|
860
|
+
3. Provide actionable insights
|
|
861
|
+
4. Format results as JSON
|
|
862
|
+
`)
|
|
863
|
+
.setResources({
|
|
864
|
+
memory: '2g', // More memory for data processing
|
|
865
|
+
cpu: 2, // More CPU for complex calculations
|
|
866
|
+
timeout: 120000 // Longer timeout for large datasets
|
|
867
|
+
})
|
|
868
|
+
.addHandler('output', (analysis) => {
|
|
869
|
+
try {
|
|
870
|
+
const results = JSON.parse(analysis);
|
|
871
|
+
// Store results in database
|
|
872
|
+
saveAnalysisResults(results);
|
|
873
|
+
// Generate reports
|
|
874
|
+
generateReport(results);
|
|
875
|
+
// Send alerts if thresholds are met
|
|
876
|
+
checkAlerts(results);
|
|
877
|
+
} catch (error) {
|
|
878
|
+
console.error('Failed to parse analysis:', error);
|
|
879
|
+
}
|
|
880
|
+
});
|
|
881
|
+
```
|
|
882
|
+
|
|
883
|
+
### 🔧 Advanced Configuration
|
|
884
|
+
|
|
885
|
+
#### Custom Agent Code
|
|
886
|
+
For complex logic, create custom agent files in the `agents/` directory:
|
|
887
|
+
|
|
888
|
+
```javascript
|
|
889
|
+
// agents/custom-agent.js
|
|
890
|
+
module.exports = {
|
|
891
|
+
async main(llmClient, handlers) {
|
|
892
|
+
console.log('Custom agent starting...');
|
|
893
|
+
|
|
894
|
+
// Your custom agent logic
|
|
895
|
+
setInterval(async () => {
|
|
896
|
+
try {
|
|
897
|
+
// Make LLM request
|
|
898
|
+
const response = await llmClient.chat.completions.create({
|
|
899
|
+
model: 'gpt-3.5-turbo',
|
|
900
|
+
messages: [
|
|
901
|
+
{ role: 'system', content: 'You are a helpful assistant' },
|
|
902
|
+
{ role: 'user', content: 'Generate a daily report' }
|
|
903
|
+
]
|
|
904
|
+
});
|
|
905
|
+
|
|
906
|
+
// Trigger output handlers
|
|
907
|
+
const outputHandlers = handlers.get('output') || [];
|
|
908
|
+
outputHandlers.forEach(handler =>
|
|
909
|
+
handler(response.choices[0].message.content)
|
|
910
|
+
);
|
|
911
|
+
|
|
912
|
+
} catch (error) {
|
|
913
|
+
// Trigger error handlers
|
|
914
|
+
const errorHandlers = handlers.get('error') || [];
|
|
915
|
+
errorHandlers.forEach(handler => handler(error));
|
|
916
|
+
}
|
|
917
|
+
}, 60000); // Run every minute
|
|
918
|
+
},
|
|
919
|
+
|
|
920
|
+
// Define custom handlers
|
|
921
|
+
handlers: {
|
|
922
|
+
output: [
|
|
923
|
+
(data) => console.log('Custom output:', data)
|
|
924
|
+
],
|
|
925
|
+
error: [
|
|
926
|
+
(error) => console.error('Custom error:', error)
|
|
927
|
+
]
|
|
928
|
+
}
|
|
929
|
+
};
|
|
930
|
+
```
|
|
931
|
+
|
|
932
|
+
#### Environment-Specific Configuration
|
|
933
|
+
```javascript
|
|
934
|
+
// dank.config.js
|
|
935
|
+
const { createAgent } = require('dank');
|
|
936
|
+
|
|
937
|
+
const isDevelopment = process.env.NODE_ENV === 'development';
|
|
938
|
+
const isProduction = process.env.NODE_ENV === 'production';
|
|
939
|
+
|
|
940
|
+
module.exports = {
|
|
941
|
+
name: 'my-project',
|
|
942
|
+
|
|
943
|
+
agents: [
|
|
944
|
+
createAgent('main-agent')
|
|
945
|
+
.setLLM('openai', {
|
|
946
|
+
apiKey: process.env.OPENAI_API_KEY,
|
|
947
|
+
model: isDevelopment ? 'gpt-3.5-turbo' : 'gpt-4',
|
|
948
|
+
temperature: isDevelopment ? 0.9 : 0.7
|
|
949
|
+
})
|
|
950
|
+
.setResources({
|
|
951
|
+
memory: isDevelopment ? '256m' : '1g',
|
|
952
|
+
cpu: isDevelopment ? 0.5 : 2
|
|
953
|
+
})
|
|
954
|
+
.addHandler('output', (data) => {
|
|
955
|
+
if (isDevelopment) {
|
|
956
|
+
console.log('DEV:', data);
|
|
957
|
+
} else {
|
|
958
|
+
// Production logging
|
|
959
|
+
logger.info('Agent output', { data });
|
|
960
|
+
}
|
|
961
|
+
})
|
|
962
|
+
]
|
|
963
|
+
};
|
|
964
|
+
```
|
|
965
|
+
|
|
966
|
+
### 🔧 Advanced Usage
|
|
967
|
+
|
|
968
|
+
#### Environment Variables
|
|
969
|
+
```bash
|
|
970
|
+
export OPENAI_API_KEY="your-key"
|
|
971
|
+
export ANTHROPIC_API_KEY="your-key"
|
|
972
|
+
export LOG_LEVEL="debug"
|
|
973
|
+
export DOCKER_HOST="unix:///var/run/docker.sock"
|
|
974
|
+
export NODE_ENV="production"
|
|
975
|
+
```
|
|
976
|
+
|
|
977
|
+
#### Integration with Existing Applications
|
|
978
|
+
```javascript
|
|
979
|
+
// In your existing Node.js application
|
|
980
|
+
const { spawn } = require('child_process');
|
|
981
|
+
|
|
982
|
+
// Start Dank agents programmatically
|
|
983
|
+
function startAgents() {
|
|
984
|
+
const dankProcess = spawn('dank', ['run', '--detached'], {
|
|
985
|
+
stdio: 'inherit',
|
|
986
|
+
env: { ...process.env, NODE_ENV: 'production' }
|
|
987
|
+
});
|
|
988
|
+
|
|
989
|
+
dankProcess.on('close', (code) => {
|
|
990
|
+
console.log(`Dank agents exited with code ${code}`);
|
|
991
|
+
});
|
|
992
|
+
|
|
993
|
+
return dankProcess;
|
|
994
|
+
}
|
|
995
|
+
|
|
996
|
+
// Stop agents gracefully
|
|
997
|
+
function stopAgents() {
|
|
998
|
+
spawn('dank', ['stop', '--all'], { stdio: 'inherit' });
|
|
999
|
+
}
|
|
1000
|
+
|
|
1001
|
+
// Check agent status
|
|
1002
|
+
async function getAgentStatus() {
|
|
1003
|
+
return new Promise((resolve) => {
|
|
1004
|
+
const statusProcess = spawn('dank', ['status', '--json'], {
|
|
1005
|
+
stdio: ['pipe', 'pipe', 'pipe']
|
|
1006
|
+
});
|
|
1007
|
+
|
|
1008
|
+
let output = '';
|
|
1009
|
+
statusProcess.stdout.on('data', (data) => {
|
|
1010
|
+
output += data.toString();
|
|
1011
|
+
});
|
|
1012
|
+
|
|
1013
|
+
statusProcess.on('close', () => {
|
|
1014
|
+
try {
|
|
1015
|
+
resolve(JSON.parse(output));
|
|
1016
|
+
} catch {
|
|
1017
|
+
resolve(null);
|
|
1018
|
+
}
|
|
1019
|
+
});
|
|
1020
|
+
});
|
|
1021
|
+
}
|
|
1022
|
+
```
|
|
1023
|
+
|
|
1024
|
+
### 🚨 Troubleshooting
|
|
1025
|
+
|
|
1026
|
+
#### Common Issues and Solutions
|
|
1027
|
+
|
|
1028
|
+
**1. Docker Connection Issues**
|
|
1029
|
+
```bash
|
|
1030
|
+
# Error: Cannot connect to Docker daemon
|
|
1031
|
+
# Solution: Dank will automatically handle this!
|
|
1032
|
+
|
|
1033
|
+
# If automatic installation fails, manual steps:
|
|
1034
|
+
docker --version
|
|
1035
|
+
docker ps
|
|
1036
|
+
|
|
1037
|
+
# On macOS/Windows: Start Docker Desktop manually
|
|
1038
|
+
# On Linux: Start Docker service
|
|
1039
|
+
sudo systemctl start docker
|
|
1040
|
+
```
|
|
1041
|
+
|
|
1042
|
+
**1a. Docker Installation Issues**
|
|
1043
|
+
```bash
|
|
1044
|
+
# If automatic installation fails, try manual installation:
|
|
1045
|
+
|
|
1046
|
+
# macOS (with Homebrew):
|
|
1047
|
+
brew install --cask docker
|
|
1048
|
+
open -a Docker
|
|
1049
|
+
|
|
1050
|
+
# Linux (Ubuntu/Debian):
|
|
1051
|
+
sudo apt-get update
|
|
1052
|
+
sudo apt-get install -y docker-ce docker-ce-cli containerd.io
|
|
1053
|
+
sudo systemctl start docker
|
|
1054
|
+
sudo usermod -aG docker $USER
|
|
1055
|
+
|
|
1056
|
+
# Windows (with Chocolatey):
|
|
1057
|
+
choco install docker-desktop -y
|
|
1058
|
+
# Then start Docker Desktop from Start Menu
|
|
1059
|
+
```
|
|
1060
|
+
|
|
1061
|
+
**2. API Key Issues**
|
|
1062
|
+
```bash
|
|
1063
|
+
# Error: Invalid API key
|
|
1064
|
+
# Solution: Check your environment variables
|
|
1065
|
+
echo $OPENAI_API_KEY
|
|
1066
|
+
|
|
1067
|
+
# Set the key properly
|
|
1068
|
+
export OPENAI_API_KEY="sk-your-actual-key-here"
|
|
1069
|
+
|
|
1070
|
+
# Or create a .env file in your project
|
|
1071
|
+
echo "OPENAI_API_KEY=sk-your-actual-key-here" > .env
|
|
1072
|
+
```
|
|
1073
|
+
|
|
1074
|
+
**3. Base Image Not Found**
|
|
1075
|
+
```bash
|
|
1076
|
+
# Error: Base image 'deltadarkly/dank-agent-base' not found
|
|
1077
|
+
# Solution: The base image is pulled automatically, but you can build it manually
|
|
1078
|
+
dank build --base
|
|
1079
|
+
```
|
|
1080
|
+
|
|
1081
|
+
**4. Container Resource Issues**
|
|
1082
|
+
```bash
|
|
1083
|
+
# Error: Container exits with code 137 (out of memory)
|
|
1084
|
+
# Solution: Increase memory allocation
|
|
1085
|
+
createAgent('my-agent')
|
|
1086
|
+
.setResources({
|
|
1087
|
+
memory: '1g', // Increase from 512m to 1g
|
|
1088
|
+
cpu: 2
|
|
1089
|
+
})
|
|
1090
|
+
```
|
|
1091
|
+
|
|
1092
|
+
**5. Agent Not Starting**
|
|
1093
|
+
```bash
|
|
1094
|
+
# Check agent logs for detailed error information
|
|
1095
|
+
dank logs agent-name
|
|
1096
|
+
|
|
1097
|
+
# Check container status
|
|
1098
|
+
docker ps -f name=dank-
|
|
1099
|
+
|
|
1100
|
+
# View Docker logs directly
|
|
1101
|
+
docker logs container-id
|
|
1102
|
+
```
|
|
1103
|
+
|
|
1104
|
+
### 💡 Best Practices
|
|
1105
|
+
|
|
1106
|
+
#### 1. Resource Management
|
|
1107
|
+
```javascript
|
|
1108
|
+
// Good: Appropriate resource allocation
|
|
1109
|
+
createAgent('light-agent')
|
|
1110
|
+
.setResources({
|
|
1111
|
+
memory: '256m', // Light tasks
|
|
1112
|
+
cpu: 0.5
|
|
1113
|
+
});
|
|
1114
|
+
|
|
1115
|
+
createAgent('heavy-agent')
|
|
1116
|
+
.setResources({
|
|
1117
|
+
memory: '2g', // Heavy processing
|
|
1118
|
+
cpu: 2,
|
|
1119
|
+
timeout: 120000 // Longer timeout
|
|
1120
|
+
});
|
|
1121
|
+
```
|
|
1122
|
+
|
|
1123
|
+
#### 2. Error Handling
|
|
1124
|
+
```javascript
|
|
1125
|
+
// Good: Comprehensive error handling
|
|
1126
|
+
createAgent('robust-agent')
|
|
1127
|
+
.addHandler('error', (error) => {
|
|
1128
|
+
console.error('Agent error:', error.message);
|
|
1129
|
+
|
|
1130
|
+
// Log to monitoring system
|
|
1131
|
+
logError(error);
|
|
1132
|
+
|
|
1133
|
+
// Send alert if critical
|
|
1134
|
+
if (error.type === 'CRITICAL') {
|
|
1135
|
+
sendAlert(error);
|
|
1136
|
+
}
|
|
1137
|
+
|
|
1138
|
+
// Implement retry logic
|
|
1139
|
+
scheduleRetry(error.context);
|
|
1140
|
+
})
|
|
1141
|
+
.addHandler('output', (data) => {
|
|
1142
|
+
try {
|
|
1143
|
+
processOutput(data);
|
|
1144
|
+
} catch (error) {
|
|
1145
|
+
console.error('Output processing failed:', error);
|
|
1146
|
+
}
|
|
1147
|
+
});
|
|
1148
|
+
```
|
|
1149
|
+
|
|
1150
|
+
#### 3. Environment Configuration
|
|
1151
|
+
```javascript
|
|
1152
|
+
// Good: Environment-specific settings
|
|
1153
|
+
const config = {
|
|
1154
|
+
development: {
|
|
1155
|
+
model: 'gpt-3.5-turbo',
|
|
1156
|
+
memory: '256m',
|
|
1157
|
+
logLevel: 'debug'
|
|
1158
|
+
},
|
|
1159
|
+
production: {
|
|
1160
|
+
model: 'gpt-4',
|
|
1161
|
+
memory: '1g',
|
|
1162
|
+
logLevel: 'info'
|
|
1163
|
+
}
|
|
1164
|
+
};
|
|
1165
|
+
|
|
1166
|
+
const env = process.env.NODE_ENV || 'development';
|
|
1167
|
+
const settings = config[env];
|
|
1168
|
+
|
|
1169
|
+
createAgent('environment-aware')
|
|
1170
|
+
.setLLM('openai', {
|
|
1171
|
+
model: settings.model,
|
|
1172
|
+
temperature: 0.7
|
|
1173
|
+
})
|
|
1174
|
+
.setResources({
|
|
1175
|
+
memory: settings.memory
|
|
1176
|
+
});
|
|
1177
|
+
```
|
|
1178
|
+
|
|
1179
|
+
#### 4. Monitoring and Logging
|
|
1180
|
+
```javascript
|
|
1181
|
+
// Good: Structured logging
|
|
1182
|
+
createAgent('monitored-agent')
|
|
1183
|
+
.addHandler('output', (data) => {
|
|
1184
|
+
logger.info('Agent output', {
|
|
1185
|
+
agent: 'monitored-agent',
|
|
1186
|
+
timestamp: new Date().toISOString(),
|
|
1187
|
+
data: data.substring(0, 100) // Truncate for logs
|
|
1188
|
+
});
|
|
1189
|
+
})
|
|
1190
|
+
.addHandler('error', (error) => {
|
|
1191
|
+
logger.error('Agent error', {
|
|
1192
|
+
agent: 'monitored-agent',
|
|
1193
|
+
error: error.message,
|
|
1194
|
+
stack: error.stack
|
|
1195
|
+
});
|
|
1196
|
+
})
|
|
1197
|
+
.addHandler('start', () => {
|
|
1198
|
+
logger.info('Agent started', { agent: 'monitored-agent' });
|
|
1199
|
+
});
|
|
1200
|
+
```
|
|
1201
|
+
|
|
1202
|
+
#### 5. Security Considerations
|
|
1203
|
+
```javascript
|
|
1204
|
+
// Good: Secure configuration
|
|
1205
|
+
createAgent('secure-agent')
|
|
1206
|
+
.setLLM('openai', {
|
|
1207
|
+
apiKey: process.env.OPENAI_API_KEY, // Never hardcode keys
|
|
1208
|
+
model: 'gpt-3.5-turbo'
|
|
1209
|
+
})
|
|
1210
|
+
.setPrompt(`
|
|
1211
|
+
You are a helpful assistant.
|
|
1212
|
+
|
|
1213
|
+
IMPORTANT SECURITY RULES:
|
|
1214
|
+
- Never reveal API keys or sensitive information
|
|
1215
|
+
- Don't execute system commands
|
|
1216
|
+
- Validate all inputs before processing
|
|
1217
|
+
- Don't access external URLs unless explicitly allowed
|
|
1218
|
+
`)
|
|
1219
|
+
.addHandler('output', (data) => {
|
|
1220
|
+
// Sanitize output before logging
|
|
1221
|
+
const sanitized = sanitizeOutput(data);
|
|
1222
|
+
console.log(sanitized);
|
|
1223
|
+
});
|
|
1224
|
+
```
|
|
1225
|
+
|
|
1226
|
+
### 📊 Performance Optimization
|
|
1227
|
+
|
|
1228
|
+
#### 1. Resource Tuning
|
|
1229
|
+
```bash
|
|
1230
|
+
# Monitor resource usage
|
|
1231
|
+
dank status --watch
|
|
1232
|
+
|
|
1233
|
+
# Check container stats
|
|
1234
|
+
docker stats $(docker ps -f name=dank- -q)
|
|
1235
|
+
|
|
1236
|
+
# Optimize based on usage patterns
|
|
1237
|
+
```
|
|
1238
|
+
|
|
1239
|
+
#### 2. Parallel Agent Management
|
|
1240
|
+
```javascript
|
|
1241
|
+
// Good: Balanced agent distribution
|
|
1242
|
+
module.exports = {
|
|
1243
|
+
agents: [
|
|
1244
|
+
// CPU-intensive agents
|
|
1245
|
+
createAgent('analyzer').setResources({ cpu: 2, memory: '1g' }),
|
|
1246
|
+
|
|
1247
|
+
// Memory-intensive agents
|
|
1248
|
+
createAgent('processor').setResources({ cpu: 1, memory: '2g' }),
|
|
1249
|
+
|
|
1250
|
+
// Light agents
|
|
1251
|
+
createAgent('notifier').setResources({ cpu: 0.5, memory: '256m' })
|
|
1252
|
+
]
|
|
1253
|
+
};
|
|
1254
|
+
```
|
|
1255
|
+
|
|
1256
|
+
#### 3. Efficient Prompt Design
|
|
1257
|
+
```javascript
|
|
1258
|
+
// Good: Clear, specific prompts
|
|
1259
|
+
.setPrompt(`
|
|
1260
|
+
You are a customer service agent. Follow these steps:
|
|
1261
|
+
|
|
1262
|
+
1. Greet the customer politely
|
|
1263
|
+
2. Understand their issue by asking clarifying questions
|
|
1264
|
+
3. Provide a solution or escalate if needed
|
|
1265
|
+
4. Confirm resolution
|
|
1266
|
+
|
|
1267
|
+
Response format: JSON with fields: greeting, questions, solution, status
|
|
1268
|
+
`);
|
|
1269
|
+
```
|
|
1270
|
+
|
|
1271
|
+
### 🔄 Development Workflow
|
|
1272
|
+
|
|
1273
|
+
#### 1. Local Development
|
|
1274
|
+
```bash
|
|
1275
|
+
# 1. Start with development configuration
|
|
1276
|
+
NODE_ENV=development dank run
|
|
1277
|
+
|
|
1278
|
+
# 2. Make changes to dank.config.js
|
|
1279
|
+
|
|
1280
|
+
# 3. Restart agents to apply changes
|
|
1281
|
+
dank stop --all
|
|
1282
|
+
dank run --build # Rebuild if needed
|
|
1283
|
+
|
|
1284
|
+
# 4. Test with reduced resources
|
|
1285
|
+
createAgent('dev-agent').setResources({ memory: '128m', cpu: 0.25 })
|
|
1286
|
+
```
|
|
1287
|
+
|
|
1288
|
+
#### 2. Testing Agents
|
|
1289
|
+
```bash
|
|
1290
|
+
# Test individual agents
|
|
1291
|
+
dank run --detached
|
|
1292
|
+
dank logs test-agent --follow
|
|
1293
|
+
|
|
1294
|
+
# Check health endpoints
|
|
1295
|
+
curl http://localhost:3001/health
|
|
1296
|
+
|
|
1297
|
+
# Monitor resource usage
|
|
1298
|
+
docker stats dank-test-agent
|
|
1299
|
+
```
|
|
1300
|
+
|
|
1301
|
+
#### 3. Production Deployment
|
|
1302
|
+
```bash
|
|
1303
|
+
# 1. Set production environment
|
|
1304
|
+
export NODE_ENV=production
|
|
1305
|
+
|
|
1306
|
+
# 2. Build optimized images
|
|
1307
|
+
dank build --force
|
|
1308
|
+
|
|
1309
|
+
# 3. Start with production config
|
|
1310
|
+
dank run --detached
|
|
1311
|
+
|
|
1312
|
+
# 4. Monitor and scale as needed
|
|
1313
|
+
dank status --watch
|
|
1314
|
+
```
|
|
1315
|
+
|
|
1316
|
+
### Monitoring and Debugging
|
|
1317
|
+
|
|
1318
|
+
```bash
|
|
1319
|
+
# Watch all agents in real-time
|
|
1320
|
+
dank status --watch
|
|
1321
|
+
|
|
1322
|
+
# Follow logs from specific agent
|
|
1323
|
+
dank logs my-agent --follow
|
|
1324
|
+
|
|
1325
|
+
# View container details
|
|
1326
|
+
docker ps -f name=dank-
|
|
1327
|
+
|
|
1328
|
+
# Check agent health
|
|
1329
|
+
curl http://localhost:3001/health
|
|
1330
|
+
```
|
|
1331
|
+
|
|
1332
|
+
## 📦 Installation
|
|
1333
|
+
|
|
1334
|
+
### Prerequisites
|
|
1335
|
+
- Node.js 16+
|
|
1336
|
+
- Docker Desktop or Docker Engine
|
|
1337
|
+
- npm or yarn
|
|
1338
|
+
|
|
1339
|
+
### Global Installation
|
|
1340
|
+
```bash
|
|
1341
|
+
npm install -g dank-ai
|
|
1342
|
+
```
|
|
1343
|
+
|
|
1344
|
+
### Local Development
|
|
1345
|
+
```bash
|
|
1346
|
+
git clone https://github.com/your-org/dank
|
|
1347
|
+
cd dank
|
|
1348
|
+
npm install
|
|
1349
|
+
npm link # Creates global symlink
|
|
1350
|
+
```
|
|
1351
|
+
|
|
1352
|
+
## 🤝 Contributing
|
|
1353
|
+
|
|
1354
|
+
1. Fork the repository
|
|
1355
|
+
2. Create a feature branch: `git checkout -b feature/amazing-feature`
|
|
1356
|
+
3. Commit changes: `git commit -m 'Add amazing feature'`
|
|
1357
|
+
4. Push to branch: `git push origin feature/amazing-feature`
|
|
1358
|
+
5. Open a Pull Request
|
|
92
1359
|
|
|
93
|
-
|
|
1360
|
+
## 📄 License
|
|
94
1361
|
|
|
95
|
-
-
|
|
96
|
-
- Set up LLM providers and models
|
|
97
|
-
- Configure event handlers
|
|
98
|
-
- Set Docker and resource limits
|
|
99
|
-
- Enable/disable communication features
|
|
1362
|
+
ISC License - see LICENSE file for details.
|
|
100
1363
|
|
|
101
|
-
##
|
|
1364
|
+
## 🆘 Support
|
|
102
1365
|
|
|
103
|
-
|
|
1366
|
+
- **Documentation**: [Wiki](https://github.com/your-org/dank/wiki)
|
|
1367
|
+
- **Issues**: [GitHub Issues](https://github.com/your-org/dank/issues)
|
|
1368
|
+
- **Discussions**: [GitHub Discussions](https://github.com/your-org/dank/discussions)
|
|
104
1369
|
|
|
105
|
-
|
|
1370
|
+
---
|
|
106
1371
|
|
|
107
|
-
|
|
1372
|
+
**Built with 💯 energy for the AI agent revolution!** 🚀
|