dank-ai 1.0.0 ā 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -4
- package/lib/cli/init.js +289 -7
- package/lib/project.js +246 -19
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -25,7 +25,7 @@ Before you begin, make sure you have:
|
|
|
25
25
|
|
|
26
26
|
### 1. Install Dank globally
|
|
27
27
|
```bash
|
|
28
|
-
npm install -g dank
|
|
28
|
+
npm install -g dank-ai
|
|
29
29
|
```
|
|
30
30
|
|
|
31
31
|
### 2. Initialize a new project
|
|
@@ -545,7 +545,7 @@ dank run --config example/dank.config.js
|
|
|
545
545
|
cp example/dank.config.template.js ./dank.config.js
|
|
546
546
|
|
|
547
547
|
# 2. Install dank as a dependency
|
|
548
|
-
npm install dank
|
|
548
|
+
npm install dank-ai
|
|
549
549
|
|
|
550
550
|
# 3. The template already uses the correct import
|
|
551
551
|
# const { createAgent } = require("dank");
|
|
@@ -639,7 +639,7 @@ Dank provides clear feedback during the process:
|
|
|
639
639
|
#### 1. Project Setup
|
|
640
640
|
```bash
|
|
641
641
|
# In your existing project directory
|
|
642
|
-
npm install -g dank
|
|
642
|
+
npm install -g dank-ai
|
|
643
643
|
|
|
644
644
|
# Initialize Dank configuration
|
|
645
645
|
dank init
|
|
@@ -1297,7 +1297,7 @@ curl http://localhost:3001/health
|
|
|
1297
1297
|
|
|
1298
1298
|
### Global Installation
|
|
1299
1299
|
```bash
|
|
1300
|
-
npm install -g dank
|
|
1300
|
+
npm install -g dank-ai
|
|
1301
1301
|
```
|
|
1302
1302
|
|
|
1303
1303
|
### Local Development
|
package/lib/cli/init.js
CHANGED
|
@@ -10,7 +10,7 @@ const { DankProject } = require('../project');
|
|
|
10
10
|
async function initCommand(projectName, options) {
|
|
11
11
|
const name = projectName || path.basename(process.cwd());
|
|
12
12
|
|
|
13
|
-
console.log(chalk.yellow(`š Initializing Dank project: ${name}
|
|
13
|
+
console.log(chalk.yellow(`š Initializing Dank project: ${name}\n`));
|
|
14
14
|
|
|
15
15
|
try {
|
|
16
16
|
// Create project instance
|
|
@@ -22,12 +22,25 @@ async function initCommand(projectName, options) {
|
|
|
22
22
|
// Initialize project structure
|
|
23
23
|
await project.init();
|
|
24
24
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
25
|
+
// Create package.json
|
|
26
|
+
await createPackageJson(name, project.projectPath);
|
|
27
|
+
|
|
28
|
+
// Create .env.example file
|
|
29
|
+
await createEnvExample(project.projectPath);
|
|
30
|
+
|
|
31
|
+
// Create .gitignore
|
|
32
|
+
await createGitignore(project.projectPath);
|
|
33
|
+
|
|
34
|
+
// Create README.md
|
|
35
|
+
await createReadme(name, project.projectPath);
|
|
36
|
+
|
|
37
|
+
console.log(chalk.green('\nā
Project initialized successfully!'));
|
|
38
|
+
console.log(chalk.cyan('\nNext steps:'));
|
|
39
|
+
console.log(chalk.gray(' 1. Copy .env.example to .env and set your API keys'));
|
|
40
|
+
console.log(chalk.gray(' 2. Run "npm install" to install dependencies'));
|
|
41
|
+
console.log(chalk.gray(' 3. Edit dank.config.js to configure your agents'));
|
|
42
|
+
console.log(chalk.gray(' 4. Run "dank run" to start your agents'));
|
|
43
|
+
console.log(chalk.gray('\nFor more information, visit: https://github.com/your-org/dank'));
|
|
31
44
|
|
|
32
45
|
} catch (error) {
|
|
33
46
|
console.error(chalk.red('ā Initialization failed:'), error.message);
|
|
@@ -35,4 +48,273 @@ async function initCommand(projectName, options) {
|
|
|
35
48
|
}
|
|
36
49
|
}
|
|
37
50
|
|
|
51
|
+
/**
|
|
52
|
+
* Create package.json for the new project
|
|
53
|
+
*/
|
|
54
|
+
async function createPackageJson(projectName, projectPath) {
|
|
55
|
+
const packageJson = {
|
|
56
|
+
name: projectName.toLowerCase().replace(/[^a-z0-9-]/g, '-'),
|
|
57
|
+
version: '1.0.0',
|
|
58
|
+
description: `Dank AI agents for ${projectName}`,
|
|
59
|
+
main: 'dank.config.js',
|
|
60
|
+
scripts: {
|
|
61
|
+
start: 'dank run',
|
|
62
|
+
dev: 'dank run --config dank.config.js',
|
|
63
|
+
stop: 'dank stop',
|
|
64
|
+
status: 'dank status',
|
|
65
|
+
logs: 'dank logs',
|
|
66
|
+
build: 'dank build',
|
|
67
|
+
clean: 'dank clean'
|
|
68
|
+
},
|
|
69
|
+
dependencies: {
|
|
70
|
+
'dank': '^1.0.0'
|
|
71
|
+
},
|
|
72
|
+
keywords: ['dank', 'ai', 'agents', 'automation', 'llm'],
|
|
73
|
+
author: '',
|
|
74
|
+
license: 'ISC',
|
|
75
|
+
engines: {
|
|
76
|
+
node: '>=16.0.0',
|
|
77
|
+
npm: '>=8.0.0'
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
const packagePath = path.join(projectPath, 'package.json');
|
|
82
|
+
await fs.writeFile(packagePath, JSON.stringify(packageJson, null, 2), 'utf8');
|
|
83
|
+
console.log(chalk.green(`Created package.json: ${packagePath}`));
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Create .env.example file
|
|
88
|
+
*/
|
|
89
|
+
async function createEnvExample(projectPath) {
|
|
90
|
+
const envExample = `# Dank AI Agent Environment Variables
|
|
91
|
+
# Copy this file to .env and fill in your API keys
|
|
92
|
+
|
|
93
|
+
# OpenAI Configuration
|
|
94
|
+
OPENAI_API_KEY=your_openai_api_key_here
|
|
95
|
+
OPENAI_MODEL=gpt-3.5-turbo
|
|
96
|
+
|
|
97
|
+
# Anthropic Configuration (optional)
|
|
98
|
+
ANTHROPIC_API_KEY=your_anthropic_api_key_here
|
|
99
|
+
ANTHROPIC_MODEL=claude-3-sonnet-20240229
|
|
100
|
+
|
|
101
|
+
# Google AI Configuration (optional)
|
|
102
|
+
GOOGLE_AI_API_KEY=your_google_ai_api_key_here
|
|
103
|
+
GOOGLE_AI_MODEL=gemini-pro
|
|
104
|
+
|
|
105
|
+
# Agent Configuration
|
|
106
|
+
DANK_LOG_LEVEL=info
|
|
107
|
+
DANK_MAX_CONCURRENT_AGENTS=3
|
|
108
|
+
|
|
109
|
+
# Docker Configuration (optional)
|
|
110
|
+
DOCKER_REGISTRY=your_registry_here
|
|
111
|
+
DOCKER_NAMESPACE=your_namespace_here
|
|
112
|
+
`;
|
|
113
|
+
|
|
114
|
+
const envPath = path.join(projectPath, '.env.example');
|
|
115
|
+
await fs.writeFile(envPath, envExample, 'utf8');
|
|
116
|
+
console.log(chalk.green(`Created .env.example: ${envPath}`));
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Create .gitignore file
|
|
121
|
+
*/
|
|
122
|
+
async function createGitignore(projectPath) {
|
|
123
|
+
const gitignore = `# Dependencies
|
|
124
|
+
node_modules/
|
|
125
|
+
npm-debug.log*
|
|
126
|
+
yarn-debug.log*
|
|
127
|
+
yarn-error.log*
|
|
128
|
+
|
|
129
|
+
# Environment variables
|
|
130
|
+
.env
|
|
131
|
+
.env.local
|
|
132
|
+
.env.development.local
|
|
133
|
+
.env.test.local
|
|
134
|
+
.env.production.local
|
|
135
|
+
|
|
136
|
+
# Dank Framework specific
|
|
137
|
+
.dank/
|
|
138
|
+
agent-code/
|
|
139
|
+
build-contexts/
|
|
140
|
+
dank-agent-*
|
|
141
|
+
container-logs/
|
|
142
|
+
agent-logs/
|
|
143
|
+
conversation-data/
|
|
144
|
+
*.agent.js
|
|
145
|
+
|
|
146
|
+
# Docker
|
|
147
|
+
.dockerignore
|
|
148
|
+
*.dockerignore
|
|
149
|
+
|
|
150
|
+
# macOS
|
|
151
|
+
.DS_Store
|
|
152
|
+
|
|
153
|
+
# Windows
|
|
154
|
+
Thumbs.db
|
|
155
|
+
ehthumbs.db
|
|
156
|
+
*.stackdump
|
|
157
|
+
|
|
158
|
+
# IDEs
|
|
159
|
+
.vscode/
|
|
160
|
+
.idea/
|
|
161
|
+
*.sublime-project
|
|
162
|
+
*.sublime-workspace
|
|
163
|
+
|
|
164
|
+
# Logs
|
|
165
|
+
logs/
|
|
166
|
+
*.log
|
|
167
|
+
|
|
168
|
+
# Runtime data
|
|
169
|
+
pids
|
|
170
|
+
*.pid
|
|
171
|
+
*.seed
|
|
172
|
+
*.pid.lock
|
|
173
|
+
|
|
174
|
+
# Coverage directory
|
|
175
|
+
coverage/
|
|
176
|
+
*.lcov
|
|
177
|
+
|
|
178
|
+
# nyc test coverage
|
|
179
|
+
.nyc_output
|
|
180
|
+
|
|
181
|
+
# Dependency directories
|
|
182
|
+
jspm_packages/
|
|
183
|
+
|
|
184
|
+
# Optional npm cache directory
|
|
185
|
+
.npm
|
|
186
|
+
|
|
187
|
+
# Optional eslint cache
|
|
188
|
+
.eslintcache
|
|
189
|
+
|
|
190
|
+
# Output of 'npm pack'
|
|
191
|
+
*.tgz
|
|
192
|
+
|
|
193
|
+
# Yarn Integrity file
|
|
194
|
+
.yarn-integrity
|
|
195
|
+
`;
|
|
196
|
+
|
|
197
|
+
const gitignorePath = path.join(projectPath, '.gitignore');
|
|
198
|
+
await fs.writeFile(gitignorePath, gitignore, 'utf8');
|
|
199
|
+
console.log(chalk.green(`Created .gitignore: ${gitignorePath}`));
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* Create README.md for the project
|
|
204
|
+
*/
|
|
205
|
+
async function createReadme(projectName, projectPath) {
|
|
206
|
+
const readme = `# ${projectName}
|
|
207
|
+
|
|
208
|
+
A Dank AI agent project with modern event handling and Docker orchestration.
|
|
209
|
+
|
|
210
|
+
## Features
|
|
211
|
+
|
|
212
|
+
- š¤ **AI Agents**: Powered by multiple LLM providers (OpenAI, Anthropic, Google AI)
|
|
213
|
+
- š³ **Docker Integration**: Containerized agents with automatic management
|
|
214
|
+
- š” **Event System**: Real-time event handling for prompts, responses, and tools
|
|
215
|
+
- š§ **Auto-Detection**: Automatically enables features based on usage
|
|
216
|
+
- š **Monitoring**: Built-in logging and status monitoring
|
|
217
|
+
|
|
218
|
+
## Quick Start
|
|
219
|
+
|
|
220
|
+
1. **Install dependencies:**
|
|
221
|
+
\`\`\`bash
|
|
222
|
+
npm install
|
|
223
|
+
\`\`\`
|
|
224
|
+
|
|
225
|
+
2. **Set up environment:**
|
|
226
|
+
\`\`\`bash
|
|
227
|
+
cp .env.example .env
|
|
228
|
+
# Edit .env with your API keys
|
|
229
|
+
\`\`\`
|
|
230
|
+
|
|
231
|
+
3. **Configure your agents:**
|
|
232
|
+
Edit \`dank.config.js\` to define your agents and their capabilities.
|
|
233
|
+
|
|
234
|
+
4. **Start your agents:**
|
|
235
|
+
\`\`\`bash
|
|
236
|
+
npm start
|
|
237
|
+
# or
|
|
238
|
+
dank run
|
|
239
|
+
\`\`\`
|
|
240
|
+
|
|
241
|
+
## Available Commands
|
|
242
|
+
|
|
243
|
+
- \`npm start\` - Start all agents
|
|
244
|
+
- \`npm run dev\` - Start in development mode
|
|
245
|
+
- \`npm run stop\` - Stop all agents
|
|
246
|
+
- \`npm run status\` - Check agent status
|
|
247
|
+
- \`npm run logs\` - View agent logs
|
|
248
|
+
- \`npm run build\` - Build agent images
|
|
249
|
+
- \`npm run clean\` - Clean up containers and images
|
|
250
|
+
|
|
251
|
+
## Event Handlers
|
|
252
|
+
|
|
253
|
+
This project includes examples of the three main event types:
|
|
254
|
+
|
|
255
|
+
### 1. Direct Prompting Events (\`request_output\`)
|
|
256
|
+
Handle LLM interactions and modify prompts/responses:
|
|
257
|
+
|
|
258
|
+
\`\`\`javascript
|
|
259
|
+
.addHandler('request_output:start', (data) => {
|
|
260
|
+
// Modify the prompt before sending to LLM
|
|
261
|
+
return { prompt: \`Enhanced: \${data.prompt}\` };
|
|
262
|
+
})
|
|
263
|
+
|
|
264
|
+
.addHandler('request_output:end', (data) => {
|
|
265
|
+
// Modify the response before sending back
|
|
266
|
+
return { response: \`\${data.response} [Enhanced by Dank]\` };
|
|
267
|
+
})
|
|
268
|
+
\`\`\`
|
|
269
|
+
|
|
270
|
+
### 2. HTTP API Events (\`tool:http-server\`)
|
|
271
|
+
Handle HTTP requests and responses:
|
|
272
|
+
|
|
273
|
+
\`\`\`javascript
|
|
274
|
+
.addHandler('tool:http-server:call', (data) => {
|
|
275
|
+
console.log('HTTP request received:', data.method, data.path);
|
|
276
|
+
})
|
|
277
|
+
|
|
278
|
+
.addHandler('tool:http-server:response', (data) => {
|
|
279
|
+
console.log('HTTP response sent:', data.statusCode);
|
|
280
|
+
})
|
|
281
|
+
\`\`\`
|
|
282
|
+
|
|
283
|
+
### 3. System Events
|
|
284
|
+
Handle agent lifecycle and errors:
|
|
285
|
+
|
|
286
|
+
\`\`\`javascript
|
|
287
|
+
.addHandler('output', (data) => {
|
|
288
|
+
console.log('Agent output:', data);
|
|
289
|
+
})
|
|
290
|
+
|
|
291
|
+
.addHandler('error', (error) => {
|
|
292
|
+
console.error('Agent error:', error);
|
|
293
|
+
})
|
|
294
|
+
\`\`\`
|
|
295
|
+
|
|
296
|
+
## Configuration
|
|
297
|
+
|
|
298
|
+
Edit \`dank.config.js\` to:
|
|
299
|
+
|
|
300
|
+
- Define your agents and their capabilities
|
|
301
|
+
- Set up LLM providers and models
|
|
302
|
+
- Configure event handlers
|
|
303
|
+
- Set Docker and resource limits
|
|
304
|
+
- Enable/disable communication features
|
|
305
|
+
|
|
306
|
+
## Documentation
|
|
307
|
+
|
|
308
|
+
For more information, visit the [Dank Framework Documentation](https://github.com/your-org/dank).
|
|
309
|
+
|
|
310
|
+
## License
|
|
311
|
+
|
|
312
|
+
ISC
|
|
313
|
+
`;
|
|
314
|
+
|
|
315
|
+
const readmePath = path.join(projectPath, 'README.md');
|
|
316
|
+
await fs.writeFile(readmePath, readme, 'utf8');
|
|
317
|
+
console.log(chalk.green(`Created README.md: ${readmePath}`));
|
|
318
|
+
}
|
|
319
|
+
|
|
38
320
|
module.exports = { initCommand };
|
package/lib/project.js
CHANGED
|
@@ -206,22 +206,189 @@ module.exports = {
|
|
|
206
206
|
|
|
207
207
|
// Define your agents
|
|
208
208
|
agents: [
|
|
209
|
-
|
|
209
|
+
// Example 1: Direct Prompting Agent with Event Handlers
|
|
210
|
+
createAgent('prompt-agent')
|
|
210
211
|
.setLLM('openai', {
|
|
211
212
|
apiKey: process.env.OPENAI_API_KEY,
|
|
212
213
|
model: 'gpt-3.5-turbo',
|
|
213
214
|
temperature: 0.7
|
|
214
215
|
})
|
|
215
|
-
.setPrompt('You are a helpful assistant
|
|
216
|
+
.setPrompt('You are a helpful AI assistant. Be concise and friendly in your responses.')
|
|
217
|
+
.setBaseImage('nodejs-20')
|
|
218
|
+
.setPort(3000)
|
|
216
219
|
.setResources({
|
|
217
220
|
memory: '512m',
|
|
218
221
|
cpu: 1
|
|
219
222
|
})
|
|
223
|
+
// Event handlers for prompt modification and response enhancement
|
|
224
|
+
.addHandler('request_output:start', (data) => {
|
|
225
|
+
console.log('[Prompt Agent] Processing prompt:', data.conversationId);
|
|
226
|
+
console.log('[Prompt Agent] Original prompt:', data.prompt);
|
|
227
|
+
|
|
228
|
+
// Enhance the prompt with context
|
|
229
|
+
const enhancedPrompt = \`Context: You are a helpful AI assistant. Please be concise and friendly.\\n\\nUser Question: \${data.prompt}\\n\\nPlease provide a clear, helpful response.\`;
|
|
230
|
+
|
|
231
|
+
console.log('[Prompt Agent] Enhanced prompt:', enhancedPrompt);
|
|
232
|
+
|
|
233
|
+
return {
|
|
234
|
+
prompt: enhancedPrompt
|
|
235
|
+
};
|
|
236
|
+
})
|
|
237
|
+
.addHandler('request_output', (data) => {
|
|
238
|
+
console.log('[Prompt Agent] LLM Response:', {
|
|
239
|
+
prompt: data.prompt,
|
|
240
|
+
finalPrompt: data.finalPrompt,
|
|
241
|
+
promptModified: data.promptModified,
|
|
242
|
+
response: data.response,
|
|
243
|
+
conversationId: data.conversationId,
|
|
244
|
+
processingTime: data.processingTime,
|
|
245
|
+
usage: data.usage,
|
|
246
|
+
model: data.model
|
|
247
|
+
});
|
|
248
|
+
})
|
|
249
|
+
.addHandler('request_output:end', (data) => {
|
|
250
|
+
console.log('[Prompt Agent] Completed in:', data.processingTime + 'ms');
|
|
251
|
+
console.log('[Prompt Agent] Original response:', data.response ? data.response.substring(0, 50) + '...' : 'N/A');
|
|
252
|
+
|
|
253
|
+
// Enhance the response with metadata
|
|
254
|
+
const enhancedResponse = \`\${data.response}\\n\\n---\\nš¤ Generated by Dank Framework Agent\\nā±ļø Processing time: \${data.processingTime}ms\\n\`;
|
|
255
|
+
|
|
256
|
+
console.log('[Prompt Agent] Enhanced response:', enhancedResponse.substring(0, 100) + '...');
|
|
257
|
+
|
|
258
|
+
return {
|
|
259
|
+
response: enhancedResponse
|
|
260
|
+
};
|
|
261
|
+
})
|
|
262
|
+
.addHandler('request_output:error', (data) => {
|
|
263
|
+
console.error('[Prompt Agent] Error processing prompt:', data.error);
|
|
264
|
+
})
|
|
265
|
+
.addHandler('output', (data) => {
|
|
266
|
+
console.log('[Prompt Agent] System output:', data);
|
|
267
|
+
})
|
|
268
|
+
.addHandler('error', (error) => {
|
|
269
|
+
console.error('[Prompt Agent] System error:', error);
|
|
270
|
+
}),
|
|
271
|
+
|
|
272
|
+
// Example 2: HTTP API Agent with Tool Events
|
|
273
|
+
createAgent('api-agent')
|
|
274
|
+
.setLLM('openai', {
|
|
275
|
+
apiKey: process.env.OPENAI_API_KEY,
|
|
276
|
+
model: 'gpt-4',
|
|
277
|
+
temperature: 0.3
|
|
278
|
+
})
|
|
279
|
+
.setPrompt('You are a specialized API assistant that helps with data processing and analysis.')
|
|
280
|
+
.setBaseImage('nodejs-20')
|
|
281
|
+
.setPort(3001)
|
|
282
|
+
.setResources({
|
|
283
|
+
memory: '1g',
|
|
284
|
+
cpu: 2
|
|
285
|
+
})
|
|
286
|
+
// HTTP API routes
|
|
287
|
+
.get('/health', (req, res) => {
|
|
288
|
+
res.json({ status: 'healthy', timestamp: new Date().toISOString() });
|
|
289
|
+
})
|
|
290
|
+
.post('/analyze', (req, res) => {
|
|
291
|
+
res.json({
|
|
292
|
+
message: 'Data analysis endpoint',
|
|
293
|
+
data: req.body,
|
|
294
|
+
timestamp: new Date().toISOString()
|
|
295
|
+
});
|
|
296
|
+
})
|
|
297
|
+
.get('/status', (req, res) => {
|
|
298
|
+
res.json({
|
|
299
|
+
agent: 'api-agent',
|
|
300
|
+
status: 'running',
|
|
301
|
+
uptime: process.uptime()
|
|
302
|
+
});
|
|
303
|
+
})
|
|
304
|
+
// Tool event handlers for HTTP requests
|
|
305
|
+
.addHandler('tool:http-server:call', (data) => {
|
|
306
|
+
console.log('[API Agent] HTTP Request:', {
|
|
307
|
+
method: data.method,
|
|
308
|
+
path: data.path,
|
|
309
|
+
headers: data.headers,
|
|
310
|
+
body: data.body,
|
|
311
|
+
timestamp: data.timestamp
|
|
312
|
+
});
|
|
313
|
+
})
|
|
314
|
+
.addHandler('tool:http-server:response', (data) => {
|
|
315
|
+
console.log('[API Agent] HTTP Response:', {
|
|
316
|
+
statusCode: data.statusCode,
|
|
317
|
+
headers: data.headers,
|
|
318
|
+
body: data.body,
|
|
319
|
+
processingTime: data.processingTime,
|
|
320
|
+
timestamp: data.timestamp
|
|
321
|
+
});
|
|
322
|
+
})
|
|
323
|
+
.addHandler('tool:http-server:error', (data) => {
|
|
324
|
+
console.error('[API Agent] HTTP Error:', {
|
|
325
|
+
error: data.error,
|
|
326
|
+
method: data.method,
|
|
327
|
+
path: data.path,
|
|
328
|
+
timestamp: data.timestamp
|
|
329
|
+
});
|
|
330
|
+
})
|
|
331
|
+
.addHandler('output', (data) => {
|
|
332
|
+
console.log('[API Agent] System output:', data);
|
|
333
|
+
})
|
|
334
|
+
.addHandler('error', (error) => {
|
|
335
|
+
console.error('[API Agent] System error:', error);
|
|
336
|
+
}),
|
|
337
|
+
|
|
338
|
+
// Example 3: Multi-Modal Agent with All Features
|
|
339
|
+
createAgent('multi-agent')
|
|
340
|
+
.setLLM('openai', {
|
|
341
|
+
apiKey: process.env.OPENAI_API_KEY,
|
|
342
|
+
model: 'gpt-4',
|
|
343
|
+
temperature: 0.5
|
|
344
|
+
})
|
|
345
|
+
.setPrompt('You are a versatile AI assistant that can handle both direct prompts and API requests. You excel at creative tasks and problem-solving.')
|
|
346
|
+
.setBaseImage('nodejs-20')
|
|
347
|
+
.setPort(3002)
|
|
348
|
+
.setResources({
|
|
349
|
+
memory: '2g',
|
|
350
|
+
cpu: 2
|
|
351
|
+
})
|
|
352
|
+
// HTTP API routes
|
|
353
|
+
.get('/creative', (req, res) => {
|
|
354
|
+
res.json({
|
|
355
|
+
message: 'Creative writing endpoint',
|
|
356
|
+
timestamp: new Date().toISOString()
|
|
357
|
+
});
|
|
358
|
+
})
|
|
359
|
+
.post('/solve', (req, res) => {
|
|
360
|
+
res.json({
|
|
361
|
+
message: 'Problem solving endpoint',
|
|
362
|
+
data: req.body,
|
|
363
|
+
timestamp: new Date().toISOString()
|
|
364
|
+
});
|
|
365
|
+
})
|
|
366
|
+
// Comprehensive event handling
|
|
367
|
+
.addHandler('request_output:start', (data) => {
|
|
368
|
+
console.log('[Multi Agent] Processing request:', data.conversationId);
|
|
369
|
+
return {
|
|
370
|
+
prompt: \`[Multi-Modal Assistant] \${data.prompt}\\n\\nPlease provide a comprehensive and creative response.\`
|
|
371
|
+
};
|
|
372
|
+
})
|
|
373
|
+
.addHandler('request_output:end', (data) => {
|
|
374
|
+
console.log('[Multi Agent] Response completed in:', data.processingTime + 'ms');
|
|
375
|
+
return {
|
|
376
|
+
response: \`\${data.response}\\n\\n⨠Enhanced by Multi-Modal Dank Agent\`
|
|
377
|
+
};
|
|
378
|
+
})
|
|
379
|
+
.addHandler('tool:http-server:*', (data) => {
|
|
380
|
+
console.log('[Multi Agent] HTTP Activity:', {
|
|
381
|
+
type: data.type,
|
|
382
|
+
method: data.method,
|
|
383
|
+
path: data.path,
|
|
384
|
+
timestamp: data.timestamp
|
|
385
|
+
});
|
|
386
|
+
})
|
|
220
387
|
.addHandler('output', (data) => {
|
|
221
|
-
console.log('Agent output:', data);
|
|
388
|
+
console.log('[Multi Agent] System output:', data);
|
|
222
389
|
})
|
|
223
390
|
.addHandler('error', (error) => {
|
|
224
|
-
console.error('Agent error:', error);
|
|
391
|
+
console.error('[Multi Agent] System error:', error);
|
|
225
392
|
})
|
|
226
393
|
]
|
|
227
394
|
};
|
|
@@ -235,7 +402,7 @@ module.exports = {
|
|
|
235
402
|
return `/**
|
|
236
403
|
* Example Dank Agent
|
|
237
404
|
*
|
|
238
|
-
* This is an example of how to define a Dank agent.
|
|
405
|
+
* This is an example of how to define a Dank agent with modern event handling.
|
|
239
406
|
* You can create multiple agent files and import them in your config.
|
|
240
407
|
*/
|
|
241
408
|
|
|
@@ -244,32 +411,92 @@ const { createAgent } = require('dank');
|
|
|
244
411
|
const exampleAgent = createAgent('example-agent')
|
|
245
412
|
.setLLM('openai', {
|
|
246
413
|
apiKey: process.env.OPENAI_API_KEY,
|
|
247
|
-
model: 'gpt-3.5-turbo'
|
|
414
|
+
model: 'gpt-3.5-turbo',
|
|
415
|
+
temperature: 0.7
|
|
248
416
|
})
|
|
249
417
|
.setPrompt(\`
|
|
250
418
|
You are a helpful AI assistant with the following capabilities:
|
|
251
419
|
- Answer questions clearly and concisely
|
|
252
420
|
- Provide code examples when appropriate
|
|
253
421
|
- Be friendly and professional
|
|
422
|
+
- Help with problem-solving and creative tasks
|
|
254
423
|
\`)
|
|
424
|
+
.setBaseImage('nodejs-20')
|
|
425
|
+
.setPort(3000)
|
|
255
426
|
.setResources({
|
|
256
427
|
memory: '512m',
|
|
257
428
|
cpu: 1,
|
|
258
429
|
timeout: 30000
|
|
259
430
|
})
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
431
|
+
// HTTP API routes
|
|
432
|
+
.get('/info', (req, res) => {
|
|
433
|
+
res.json({
|
|
434
|
+
agent: 'example-agent',
|
|
435
|
+
status: 'running',
|
|
436
|
+
capabilities: ['direct-prompting', 'http-api'],
|
|
437
|
+
timestamp: new Date().toISOString()
|
|
438
|
+
});
|
|
439
|
+
})
|
|
440
|
+
.post('/chat', (req, res) => {
|
|
441
|
+
res.json({
|
|
442
|
+
message: 'Chat endpoint ready',
|
|
443
|
+
data: req.body,
|
|
444
|
+
timestamp: new Date().toISOString()
|
|
445
|
+
});
|
|
446
|
+
})
|
|
447
|
+
// Event handlers for prompt processing
|
|
448
|
+
.addHandler('request_output:start', (data) => {
|
|
449
|
+
console.log(\`[\${new Date().toISOString()}] Processing prompt:\`, data.conversationId);
|
|
450
|
+
console.log('Original prompt:', data.prompt);
|
|
451
|
+
|
|
452
|
+
// Enhance the prompt
|
|
453
|
+
const enhancedPrompt = \`[Enhanced] \${data.prompt}\\n\\nPlease provide a helpful and detailed response.\`;
|
|
454
|
+
|
|
455
|
+
return {
|
|
456
|
+
prompt: enhancedPrompt
|
|
457
|
+
};
|
|
458
|
+
})
|
|
459
|
+
.addHandler('request_output', (data) => {
|
|
460
|
+
console.log(\`[\${new Date().toISOString()}] LLM Response:\`, {
|
|
461
|
+
conversationId: data.conversationId,
|
|
462
|
+
promptModified: data.promptModified,
|
|
463
|
+
processingTime: data.processingTime,
|
|
464
|
+
model: data.model
|
|
465
|
+
});
|
|
466
|
+
})
|
|
467
|
+
.addHandler('request_output:end', (data) => {
|
|
468
|
+
console.log(\`[\${new Date().toISOString()}] Response completed in:\`, data.processingTime + 'ms');
|
|
469
|
+
|
|
470
|
+
// Enhance the response
|
|
471
|
+
const enhancedResponse = \`\${data.response}\\n\\n---\\nš¤ Powered by Dank Framework\`;
|
|
472
|
+
|
|
473
|
+
return {
|
|
474
|
+
response: enhancedResponse
|
|
475
|
+
};
|
|
476
|
+
})
|
|
477
|
+
.addHandler('request_output:error', (data) => {
|
|
478
|
+
console.error(\`[\${new Date().toISOString()}] Error processing prompt:\`, data.error);
|
|
479
|
+
})
|
|
480
|
+
// HTTP tool event handlers
|
|
481
|
+
.addHandler('tool:http-server:call', (data) => {
|
|
482
|
+
console.log(\`[\${new Date().toISOString()}] HTTP Request:\`, {
|
|
483
|
+
method: data.method,
|
|
484
|
+
path: data.path,
|
|
485
|
+
body: data.body
|
|
486
|
+
});
|
|
487
|
+
})
|
|
488
|
+
.addHandler('tool:http-server:response', (data) => {
|
|
489
|
+
console.log(\`[\${new Date().toISOString()}] HTTP Response:\`, {
|
|
490
|
+
statusCode: data.statusCode,
|
|
491
|
+
processingTime: data.processingTime
|
|
492
|
+
});
|
|
493
|
+
})
|
|
494
|
+
// System event handlers
|
|
495
|
+
.addHandler('output', (data) => {
|
|
496
|
+
console.log(\`[\${new Date().toISOString()}] Agent output:\`, data);
|
|
497
|
+
})
|
|
498
|
+
.addHandler('error', (error) => {
|
|
499
|
+
console.error(\`[\${new Date().toISOString()}] Agent error:\`, error);
|
|
273
500
|
});
|
|
274
501
|
|
|
275
502
|
module.exports = exampleAgent;
|