@majkapp/plugin-kit 3.7.2 → 3.7.4
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/bin/promptable-cli.js +88 -0
- package/dist/generator/cli.js +0 -0
- package/dist/majk-interface-types.d.ts +1103 -0
- package/dist/majk-interface-types.d.ts.map +1 -1
- package/dist/transports.d.ts +59 -0
- package/dist/transports.d.ts.map +1 -0
- package/dist/transports.js +171 -0
- package/docs/AGENTS.md +641 -0
- package/docs/AUTH.md +248 -0
- package/docs/BATCH.md +256 -0
- package/docs/CONFIG_API.md +206 -0
- package/docs/CONVERSATIONS_API.md +283 -0
- package/docs/DELEGATION.md +196 -0
- package/docs/INDEX.md +38 -0
- package/docs/KNOWLEDGE.md +225 -0
- package/docs/PLUGINS.md +356 -0
- package/docs/REPORTS.md +271 -0
- package/docs/SCRIPTING.md +231 -0
- package/docs/SECRETS.md +412 -0
- package/docs/SKILLS.md +514 -0
- package/docs/TASKS.md +622 -0
- package/docs/TOOL_DISCOVERY.md +240 -0
- package/package.json +1 -1
package/docs/AGENTS.md
ADDED
|
@@ -0,0 +1,641 @@
|
|
|
1
|
+
# Agents API - AI Agent Management
|
|
2
|
+
|
|
3
|
+
The Agents API provides programmatic access to create, manage, and interact with AI agents in MAJK. Agents are AI assistants with configurable models, system prompts, and MCP server access that can be used to automate tasks and provide specialized AI capabilities.
|
|
4
|
+
|
|
5
|
+
## Quick Start
|
|
6
|
+
|
|
7
|
+
```typescript
|
|
8
|
+
import { PluginContext } from '@majkapp/plugin-kit';
|
|
9
|
+
|
|
10
|
+
async function exampleAgentUsage(ctx: PluginContext) {
|
|
11
|
+
// Create a new agent
|
|
12
|
+
const agent = await ctx.majk.agents.create({
|
|
13
|
+
name: 'Code Reviewer',
|
|
14
|
+
description: 'Specialized agent for reviewing code quality and security',
|
|
15
|
+
systemPrompt: 'You are an expert code reviewer. Focus on security, performance, and best practices.',
|
|
16
|
+
model: 'claude-3-sonnet-20240229',
|
|
17
|
+
temperature: 0.1,
|
|
18
|
+
maxTokens: 4000,
|
|
19
|
+
tags: ['code', 'review', 'security']
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
// Test the agent
|
|
23
|
+
const testResult = await ctx.majk.agents.test(agent.id, 'Review this function for potential issues');
|
|
24
|
+
|
|
25
|
+
// Clone the agent with modifications
|
|
26
|
+
const clonedAgent = await ctx.majk.agents.clone(agent.id, {
|
|
27
|
+
name: 'Senior Code Reviewer',
|
|
28
|
+
temperature: 0.05
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
console.log('Created agent:', agent.name);
|
|
32
|
+
console.log('Test successful:', testResult.success);
|
|
33
|
+
console.log('Cloned agent:', clonedAgent.name);
|
|
34
|
+
}
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## Core Concepts
|
|
38
|
+
|
|
39
|
+
### Agents vs Teammates
|
|
40
|
+
|
|
41
|
+
- **Agents**: Raw AI models with system prompts and configuration
|
|
42
|
+
- **Teammates**: Agents enhanced with skills, project assignments, and specialized roles
|
|
43
|
+
- Agents are the foundation; teammates build upon agents with additional context
|
|
44
|
+
|
|
45
|
+
### Agent Configuration
|
|
46
|
+
|
|
47
|
+
Agents support extensive configuration:
|
|
48
|
+
- **Model Selection**: Choose from available AI models
|
|
49
|
+
- **System Prompts**: Define the agent's personality and instructions
|
|
50
|
+
- **Temperature**: Control randomness in responses (0.0 = deterministic, 1.0 = creative)
|
|
51
|
+
- **Token Limits**: Set maximum response length
|
|
52
|
+
- **MCP Servers**: Grant access to external tools and data sources
|
|
53
|
+
|
|
54
|
+
## API Reference
|
|
55
|
+
|
|
56
|
+
### create(data: CreateAgentRequest): Promise<AgentHandle>
|
|
57
|
+
|
|
58
|
+
Creates a new AI agent with the specified configuration.
|
|
59
|
+
|
|
60
|
+
```typescript
|
|
61
|
+
const agent = await ctx.majk.agents.create({
|
|
62
|
+
name: 'Data Analyst',
|
|
63
|
+
description: 'Specialized in data analysis and visualization',
|
|
64
|
+
systemPrompt: 'You are a data analyst expert. Provide clear insights and actionable recommendations.',
|
|
65
|
+
model: 'claude-3-sonnet-20240229',
|
|
66
|
+
temperature: 0.2,
|
|
67
|
+
maxTokens: 8000,
|
|
68
|
+
mcpServerIds: ['data-tools-server'],
|
|
69
|
+
configuration: {
|
|
70
|
+
streaming: true,
|
|
71
|
+
timeout: 30000,
|
|
72
|
+
rateLimiting: {
|
|
73
|
+
requestsPerMinute: 60,
|
|
74
|
+
tokensPerMinute: 50000
|
|
75
|
+
}
|
|
76
|
+
},
|
|
77
|
+
tags: ['data', 'analysis'],
|
|
78
|
+
isActive: true
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
console.log('Agent created:', agent.id);
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
**Parameters**:
|
|
85
|
+
- `name` (string): Display name for the agent
|
|
86
|
+
- `description` (string, optional): Brief description of the agent's purpose
|
|
87
|
+
- `systemPrompt` (string): Instructions that define the agent's behavior
|
|
88
|
+
- `model` (string): AI model identifier (e.g., 'claude-3-sonnet-20240229')
|
|
89
|
+
- `temperature` (number, optional): Response randomness (0.0-1.0)
|
|
90
|
+
- `maxTokens` (number, optional): Maximum tokens in responses
|
|
91
|
+
- `mcpServerIds` (string[], optional): MCP servers the agent can access
|
|
92
|
+
- `configuration` (object, optional): Advanced settings
|
|
93
|
+
- `tags` (string[], optional): Tags for organization
|
|
94
|
+
- `isActive` (boolean, optional): Whether the agent is active (default: true)
|
|
95
|
+
|
|
96
|
+
### get(id: string): Promise<AgentHandle | null>
|
|
97
|
+
|
|
98
|
+
Retrieves an agent by ID.
|
|
99
|
+
|
|
100
|
+
```typescript
|
|
101
|
+
const agent = await ctx.majk.agents.get('agent-123');
|
|
102
|
+
if (agent) {
|
|
103
|
+
console.log('Found agent:', agent.name);
|
|
104
|
+
console.log('Model:', agent.model);
|
|
105
|
+
console.log('Active:', agent.isActive);
|
|
106
|
+
} else {
|
|
107
|
+
console.log('Agent not found');
|
|
108
|
+
}
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
### list(filter?: AgentFilter): Promise<AgentHandle[]>
|
|
112
|
+
|
|
113
|
+
Lists agents with optional filtering.
|
|
114
|
+
|
|
115
|
+
```typescript
|
|
116
|
+
// List all agents
|
|
117
|
+
const allAgents = await ctx.majk.agents.list();
|
|
118
|
+
|
|
119
|
+
// Filter by active agents
|
|
120
|
+
const activeAgents = await ctx.majk.agents.list({ isActive: true });
|
|
121
|
+
|
|
122
|
+
// Filter by model
|
|
123
|
+
const claudeAgents = await ctx.majk.agents.list({
|
|
124
|
+
model: 'claude-3-sonnet-20240229'
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
// Filter by tags
|
|
128
|
+
const codeAgents = await ctx.majk.agents.list({
|
|
129
|
+
tags: ['code', 'review']
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
console.log('Total agents:', allAgents.length);
|
|
133
|
+
console.log('Active agents:', activeAgents.length);
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
**Filter Options**:
|
|
137
|
+
- `isActive` (boolean): Filter by active status
|
|
138
|
+
- `model` (string): Filter by AI model
|
|
139
|
+
- `tags` (string[]): Filter by tags (agent must have all specified tags)
|
|
140
|
+
|
|
141
|
+
### update(id: string, updates: AgentUpdate): Promise<AgentHandle>
|
|
142
|
+
|
|
143
|
+
Updates an existing agent's configuration.
|
|
144
|
+
|
|
145
|
+
```typescript
|
|
146
|
+
const updatedAgent = await ctx.majk.agents.update('agent-123', {
|
|
147
|
+
name: 'Advanced Code Reviewer',
|
|
148
|
+
temperature: 0.15,
|
|
149
|
+
maxTokens: 6000,
|
|
150
|
+
tags: ['code', 'review', 'security', 'advanced'],
|
|
151
|
+
configuration: {
|
|
152
|
+
streaming: true,
|
|
153
|
+
timeout: 45000
|
|
154
|
+
}
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
console.log('Agent updated:', updatedAgent.name);
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
### delete(id: string): Promise<boolean>
|
|
161
|
+
|
|
162
|
+
Deletes an agent permanently.
|
|
163
|
+
|
|
164
|
+
```typescript
|
|
165
|
+
const deleted = await ctx.majk.agents.delete('agent-123');
|
|
166
|
+
if (deleted) {
|
|
167
|
+
console.log('Agent deleted successfully');
|
|
168
|
+
} else {
|
|
169
|
+
console.log('Agent not found or could not be deleted');
|
|
170
|
+
}
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
### exists(id: string): Promise<boolean>
|
|
174
|
+
|
|
175
|
+
Checks if an agent exists.
|
|
176
|
+
|
|
177
|
+
```typescript
|
|
178
|
+
const agentExists = await ctx.majk.agents.exists('agent-123');
|
|
179
|
+
console.log('Agent exists:', agentExists);
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
### count(filter?: AgentFilter): Promise<number>
|
|
183
|
+
|
|
184
|
+
Counts agents matching the filter criteria.
|
|
185
|
+
|
|
186
|
+
```typescript
|
|
187
|
+
const totalAgents = await ctx.majk.agents.count();
|
|
188
|
+
const activeAgents = await ctx.majk.agents.count({ isActive: true });
|
|
189
|
+
const codeAgents = await ctx.majk.agents.count({ tags: ['code'] });
|
|
190
|
+
|
|
191
|
+
console.log(`Total: ${totalAgents}, Active: ${activeAgents}, Code: ${codeAgents}`);
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
### test(agentId: string, message: string): Promise<TestResult>
|
|
195
|
+
|
|
196
|
+
Tests an agent with a message to verify it's working correctly.
|
|
197
|
+
|
|
198
|
+
```typescript
|
|
199
|
+
const testResult = await ctx.majk.agents.test('agent-123',
|
|
200
|
+
'Hello! Can you help me review this code snippet?'
|
|
201
|
+
);
|
|
202
|
+
|
|
203
|
+
if (testResult.success) {
|
|
204
|
+
console.log('Agent responded:', testResult.response);
|
|
205
|
+
console.log('Response time:', testResult.duration, 'ms');
|
|
206
|
+
} else {
|
|
207
|
+
console.error('Agent test failed:', testResult.error);
|
|
208
|
+
}
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
**TestResult Properties**:
|
|
212
|
+
- `success` (boolean): Whether the test succeeded
|
|
213
|
+
- `response` (string, optional): The agent's response
|
|
214
|
+
- `error` (string, optional): Error message if test failed
|
|
215
|
+
- `duration` (number, optional): Response time in milliseconds
|
|
216
|
+
|
|
217
|
+
### clone(agentId: string, modifications?: Partial<CreateAgentRequest>): Promise<AgentHandle>
|
|
218
|
+
|
|
219
|
+
Creates a copy of an existing agent with optional modifications.
|
|
220
|
+
|
|
221
|
+
```typescript
|
|
222
|
+
// Simple clone
|
|
223
|
+
const clonedAgent = await ctx.majk.agents.clone('agent-123');
|
|
224
|
+
|
|
225
|
+
// Clone with modifications
|
|
226
|
+
const modifiedClone = await ctx.majk.agents.clone('agent-123', {
|
|
227
|
+
name: 'Enhanced Code Reviewer',
|
|
228
|
+
temperature: 0.05,
|
|
229
|
+
maxTokens: 8000,
|
|
230
|
+
tags: ['code', 'review', 'enhanced'],
|
|
231
|
+
systemPrompt: 'You are an expert senior code reviewer with 10+ years experience...'
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
console.log('Cloned agent:', modifiedClone.name);
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
### channel(): any
|
|
238
|
+
|
|
239
|
+
Returns an event channel for real-time agent events.
|
|
240
|
+
|
|
241
|
+
```typescript
|
|
242
|
+
const channel = ctx.majk.agents.channel();
|
|
243
|
+
// Use for subscribing to agent creation, updates, deletion events
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
## Agent Handle Methods
|
|
247
|
+
|
|
248
|
+
When you retrieve an agent, you get an `AgentHandle` with additional methods:
|
|
249
|
+
|
|
250
|
+
```typescript
|
|
251
|
+
const agent = await ctx.majk.agents.get('agent-123');
|
|
252
|
+
|
|
253
|
+
// Test the agent directly
|
|
254
|
+
const testResult = await agent.test('Test message');
|
|
255
|
+
|
|
256
|
+
// Clone the agent
|
|
257
|
+
const clone = await agent.clone({ name: 'Agent Clone' });
|
|
258
|
+
|
|
259
|
+
// Update the agent
|
|
260
|
+
await agent.update({ temperature: 0.3 });
|
|
261
|
+
|
|
262
|
+
// Delete the agent
|
|
263
|
+
await agent.delete();
|
|
264
|
+
|
|
265
|
+
// Get MCP servers
|
|
266
|
+
const mcpServers = await agent.getMCPServers();
|
|
267
|
+
|
|
268
|
+
// Manage MCP servers
|
|
269
|
+
await agent.addMCPServer('new-server-id');
|
|
270
|
+
await agent.removeMCPServer('old-server-id');
|
|
271
|
+
|
|
272
|
+
// Event handlers
|
|
273
|
+
const unsubscribe = agent.onChange((updatedAgent) => {
|
|
274
|
+
console.log('Agent updated:', updatedAgent.name);
|
|
275
|
+
});
|
|
276
|
+
|
|
277
|
+
agent.onDelete(() => {
|
|
278
|
+
console.log('Agent was deleted');
|
|
279
|
+
});
|
|
280
|
+
|
|
281
|
+
// Convert to entity
|
|
282
|
+
const entity = agent.toEntity();
|
|
283
|
+
```
|
|
284
|
+
|
|
285
|
+
## Examples
|
|
286
|
+
|
|
287
|
+
### Creating a Specialized Code Review Agent
|
|
288
|
+
|
|
289
|
+
```typescript
|
|
290
|
+
async function createCodeReviewAgent(ctx: PluginContext) {
|
|
291
|
+
const agent = await ctx.majk.agents.create({
|
|
292
|
+
name: 'Security Code Reviewer',
|
|
293
|
+
description: 'Focuses on security vulnerabilities and best practices',
|
|
294
|
+
systemPrompt: `You are a security-focused code reviewer with expertise in:
|
|
295
|
+
- OWASP Top 10 vulnerabilities
|
|
296
|
+
- Secure coding practices
|
|
297
|
+
- Authentication and authorization
|
|
298
|
+
- Input validation and sanitization
|
|
299
|
+
- Cryptography best practices
|
|
300
|
+
|
|
301
|
+
When reviewing code:
|
|
302
|
+
1. Identify potential security vulnerabilities
|
|
303
|
+
2. Suggest specific fixes with code examples
|
|
304
|
+
3. Explain the security implications
|
|
305
|
+
4. Prioritize issues by severity (Critical, High, Medium, Low)
|
|
306
|
+
5. Be thorough but practical in your recommendations`,
|
|
307
|
+
model: 'claude-3-sonnet-20240229',
|
|
308
|
+
temperature: 0.1,
|
|
309
|
+
maxTokens: 6000,
|
|
310
|
+
tags: ['security', 'code-review', 'vulnerabilities'],
|
|
311
|
+
configuration: {
|
|
312
|
+
streaming: true,
|
|
313
|
+
timeout: 60000,
|
|
314
|
+
rateLimiting: {
|
|
315
|
+
requestsPerMinute: 30,
|
|
316
|
+
tokensPerMinute: 40000
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
});
|
|
320
|
+
|
|
321
|
+
// Test with a sample security issue
|
|
322
|
+
const testResult = await agent.test(`
|
|
323
|
+
Review this authentication function:
|
|
324
|
+
|
|
325
|
+
function authenticate(username, password) {
|
|
326
|
+
const query = "SELECT * FROM users WHERE username='" + username +
|
|
327
|
+
"' AND password='" + password + "'";
|
|
328
|
+
return database.query(query);
|
|
329
|
+
}
|
|
330
|
+
`);
|
|
331
|
+
|
|
332
|
+
console.log('Security review result:', testResult.response);
|
|
333
|
+
return agent;
|
|
334
|
+
}
|
|
335
|
+
```
|
|
336
|
+
|
|
337
|
+
### Creating Multiple Specialized Agents
|
|
338
|
+
|
|
339
|
+
```typescript
|
|
340
|
+
async function createDevelopmentTeam(ctx: PluginContext) {
|
|
341
|
+
const agents = [];
|
|
342
|
+
|
|
343
|
+
// Code Reviewer
|
|
344
|
+
const reviewer = await ctx.majk.agents.create({
|
|
345
|
+
name: 'Code Reviewer',
|
|
346
|
+
systemPrompt: 'Expert at code quality, best practices, and architectural review.',
|
|
347
|
+
model: 'claude-3-sonnet-20240229',
|
|
348
|
+
temperature: 0.2,
|
|
349
|
+
tags: ['code', 'review']
|
|
350
|
+
});
|
|
351
|
+
agents.push(reviewer);
|
|
352
|
+
|
|
353
|
+
// Documentation Writer
|
|
354
|
+
const documenter = await ctx.majk.agents.create({
|
|
355
|
+
name: 'Documentation Writer',
|
|
356
|
+
systemPrompt: 'Specialized in creating clear, comprehensive technical documentation.',
|
|
357
|
+
model: 'claude-3-sonnet-20240229',
|
|
358
|
+
temperature: 0.3,
|
|
359
|
+
tags: ['documentation', 'writing']
|
|
360
|
+
});
|
|
361
|
+
agents.push(documenter);
|
|
362
|
+
|
|
363
|
+
// Test Engineer
|
|
364
|
+
const tester = await ctx.majk.agents.create({
|
|
365
|
+
name: 'Test Engineer',
|
|
366
|
+
systemPrompt: 'Expert at designing comprehensive test suites and quality assurance.',
|
|
367
|
+
model: 'claude-3-sonnet-20240229',
|
|
368
|
+
temperature: 0.15,
|
|
369
|
+
tags: ['testing', 'qa']
|
|
370
|
+
});
|
|
371
|
+
agents.push(tester);
|
|
372
|
+
|
|
373
|
+
console.log(`Created ${agents.length} specialized agents`);
|
|
374
|
+
return agents;
|
|
375
|
+
}
|
|
376
|
+
```
|
|
377
|
+
|
|
378
|
+
### Agent Testing and Validation
|
|
379
|
+
|
|
380
|
+
```typescript
|
|
381
|
+
async function validateAgents(ctx: PluginContext) {
|
|
382
|
+
const agents = await ctx.majk.agents.list({ isActive: true });
|
|
383
|
+
const results = [];
|
|
384
|
+
|
|
385
|
+
for (const agent of agents) {
|
|
386
|
+
console.log(`Testing agent: ${agent.name}`);
|
|
387
|
+
|
|
388
|
+
const testResult = await agent.test(
|
|
389
|
+
'Please introduce yourself and describe your capabilities.'
|
|
390
|
+
);
|
|
391
|
+
|
|
392
|
+
results.push({
|
|
393
|
+
agentId: agent.id,
|
|
394
|
+
agentName: agent.name,
|
|
395
|
+
testPassed: testResult.success,
|
|
396
|
+
responseTime: testResult.duration,
|
|
397
|
+
error: testResult.error
|
|
398
|
+
});
|
|
399
|
+
|
|
400
|
+
if (testResult.success) {
|
|
401
|
+
console.log(`✅ ${agent.name} - Response time: ${testResult.duration}ms`);
|
|
402
|
+
} else {
|
|
403
|
+
console.log(`❌ ${agent.name} - Error: ${testResult.error}`);
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
return results;
|
|
408
|
+
}
|
|
409
|
+
```
|
|
410
|
+
|
|
411
|
+
### Agent Cloning for Variations
|
|
412
|
+
|
|
413
|
+
```typescript
|
|
414
|
+
async function createAgentVariations(ctx: PluginContext) {
|
|
415
|
+
const baseAgent = await ctx.majk.agents.create({
|
|
416
|
+
name: 'Base Code Reviewer',
|
|
417
|
+
systemPrompt: 'You are a code reviewer.',
|
|
418
|
+
model: 'claude-3-sonnet-20240229',
|
|
419
|
+
temperature: 0.2,
|
|
420
|
+
tags: ['code', 'review']
|
|
421
|
+
});
|
|
422
|
+
|
|
423
|
+
// Create conservative variation
|
|
424
|
+
const conservativeReviewer = await ctx.majk.agents.clone(baseAgent.id, {
|
|
425
|
+
name: 'Conservative Code Reviewer',
|
|
426
|
+
temperature: 0.05,
|
|
427
|
+
systemPrompt: 'You are a very thorough and conservative code reviewer. Be strict about best practices.',
|
|
428
|
+
tags: ['code', 'review', 'conservative']
|
|
429
|
+
});
|
|
430
|
+
|
|
431
|
+
// Create creative variation
|
|
432
|
+
const creativeReviewer = await ctx.majk.agents.clone(baseAgent.id, {
|
|
433
|
+
name: 'Creative Code Reviewer',
|
|
434
|
+
temperature: 0.4,
|
|
435
|
+
systemPrompt: 'You are a creative code reviewer who suggests innovative solutions and modern approaches.',
|
|
436
|
+
tags: ['code', 'review', 'creative']
|
|
437
|
+
});
|
|
438
|
+
|
|
439
|
+
return [baseAgent, conservativeReviewer, creativeReviewer];
|
|
440
|
+
}
|
|
441
|
+
```
|
|
442
|
+
|
|
443
|
+
## Best Practices
|
|
444
|
+
|
|
445
|
+
### Agent Design
|
|
446
|
+
|
|
447
|
+
1. **Clear Purpose**: Give each agent a specific, well-defined role
|
|
448
|
+
2. **Appropriate Temperature**: Use low values (0.0-0.2) for analytical tasks, higher (0.3-0.6) for creative work
|
|
449
|
+
3. **Descriptive Names**: Use names that clearly indicate the agent's function
|
|
450
|
+
4. **Comprehensive Prompts**: Provide detailed system prompts with examples and guidelines
|
|
451
|
+
5. **Proper Tagging**: Use consistent tags for organization and filtering
|
|
452
|
+
|
|
453
|
+
### System Prompt Guidelines
|
|
454
|
+
|
|
455
|
+
```typescript
|
|
456
|
+
// Good system prompt example
|
|
457
|
+
const systemPrompt = `You are a senior software architect with 15+ years of experience.
|
|
458
|
+
|
|
459
|
+
Your role:
|
|
460
|
+
- Review code architecture and design patterns
|
|
461
|
+
- Suggest improvements for scalability and maintainability
|
|
462
|
+
- Identify potential technical debt
|
|
463
|
+
- Recommend appropriate design patterns
|
|
464
|
+
|
|
465
|
+
When reviewing:
|
|
466
|
+
1. Focus on high-level architecture first
|
|
467
|
+
2. Consider long-term maintainability
|
|
468
|
+
3. Suggest specific improvements with rationale
|
|
469
|
+
4. Prioritize issues by impact
|
|
470
|
+
5. Provide code examples when helpful
|
|
471
|
+
|
|
472
|
+
Your expertise includes:
|
|
473
|
+
- Microservices architecture
|
|
474
|
+
- Domain-driven design
|
|
475
|
+
- SOLID principles
|
|
476
|
+
- Design patterns (GoF, Enterprise)
|
|
477
|
+
- Cloud-native architectures`;
|
|
478
|
+
```
|
|
479
|
+
|
|
480
|
+
### Testing and Validation
|
|
481
|
+
|
|
482
|
+
1. **Regular Testing**: Test agents periodically to ensure they're functioning correctly
|
|
483
|
+
2. **Performance Monitoring**: Monitor response times and success rates
|
|
484
|
+
3. **Prompt Iteration**: Refine system prompts based on actual usage patterns
|
|
485
|
+
4. **Version Control**: Keep track of prompt changes and their impact
|
|
486
|
+
|
|
487
|
+
### Resource Management
|
|
488
|
+
|
|
489
|
+
1. **Token Limits**: Set appropriate token limits based on use case
|
|
490
|
+
2. **Rate Limiting**: Configure rate limits to prevent abuse
|
|
491
|
+
3. **Cleanup**: Delete unused agents to reduce resource consumption
|
|
492
|
+
4. **Monitoring**: Track agent usage and performance metrics
|
|
493
|
+
|
|
494
|
+
## Error Handling
|
|
495
|
+
|
|
496
|
+
```typescript
|
|
497
|
+
async function robustAgentOperation(ctx: PluginContext) {
|
|
498
|
+
try {
|
|
499
|
+
const agent = await ctx.majk.agents.create({
|
|
500
|
+
name: 'Test Agent',
|
|
501
|
+
systemPrompt: 'You are a helpful assistant.',
|
|
502
|
+
model: 'claude-3-sonnet-20240229'
|
|
503
|
+
});
|
|
504
|
+
|
|
505
|
+
// Test the agent with error handling
|
|
506
|
+
try {
|
|
507
|
+
const testResult = await agent.test('Hello, are you working?');
|
|
508
|
+
if (!testResult.success) {
|
|
509
|
+
console.error('Agent test failed:', testResult.error);
|
|
510
|
+
// Handle test failure (retry, alert, etc.)
|
|
511
|
+
}
|
|
512
|
+
} catch (testError) {
|
|
513
|
+
console.error('Error testing agent:', testError);
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
return agent;
|
|
517
|
+
} catch (createError) {
|
|
518
|
+
console.error('Error creating agent:', createError);
|
|
519
|
+
|
|
520
|
+
// Check if it's a model availability issue
|
|
521
|
+
if (createError.message.includes('model')) {
|
|
522
|
+
console.log('Trying with different model...');
|
|
523
|
+
// Retry with different model
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
throw createError;
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
```
|
|
530
|
+
|
|
531
|
+
## Integration with Other APIs
|
|
532
|
+
|
|
533
|
+
### Using Agents with Tasks
|
|
534
|
+
|
|
535
|
+
```typescript
|
|
536
|
+
// Create agent and use it for task automation
|
|
537
|
+
const agent = await ctx.majk.agents.create({
|
|
538
|
+
name: 'Task Processor',
|
|
539
|
+
systemPrompt: 'You process and analyze task requirements.',
|
|
540
|
+
model: 'claude-3-sonnet-20240229'
|
|
541
|
+
});
|
|
542
|
+
|
|
543
|
+
// Use agent in task processing
|
|
544
|
+
const task = await ctx.majk.tasks.start({
|
|
545
|
+
title: 'Process user feedback',
|
|
546
|
+
message: 'Analyze the attached feedback and provide insights',
|
|
547
|
+
agentId: agent.id,
|
|
548
|
+
workingDirectory: '/project/feedback'
|
|
549
|
+
});
|
|
550
|
+
```
|
|
551
|
+
|
|
552
|
+
### Converting Agents to Teammates
|
|
553
|
+
|
|
554
|
+
```typescript
|
|
555
|
+
// Create agent first
|
|
556
|
+
const agent = await ctx.majk.agents.create({
|
|
557
|
+
name: 'Code Expert',
|
|
558
|
+
systemPrompt: 'Expert in software development.',
|
|
559
|
+
model: 'claude-3-sonnet-20240229'
|
|
560
|
+
});
|
|
561
|
+
|
|
562
|
+
// Convert to teammate with additional capabilities
|
|
563
|
+
const teammate = await ctx.majk.teammates.create({
|
|
564
|
+
name: agent.name,
|
|
565
|
+
role: 'Software Developer',
|
|
566
|
+
skills: {
|
|
567
|
+
primary: ['JavaScript', 'Python', 'React'],
|
|
568
|
+
secondary: ['Docker', 'AWS', 'Testing'],
|
|
569
|
+
languages: ['JavaScript', 'Python', 'TypeScript'],
|
|
570
|
+
frameworks: ['React', 'Node.js', 'Express'],
|
|
571
|
+
tools: ['Git', 'VSCode', 'Jest']
|
|
572
|
+
},
|
|
573
|
+
systemPrompt: agent.systemPrompt,
|
|
574
|
+
model: agent.model,
|
|
575
|
+
expertise: ['Web Development', 'API Design', 'Code Review']
|
|
576
|
+
});
|
|
577
|
+
```
|
|
578
|
+
|
|
579
|
+
## Troubleshooting
|
|
580
|
+
|
|
581
|
+
### Common Issues
|
|
582
|
+
|
|
583
|
+
**Agent Creation Fails**
|
|
584
|
+
- Check if the specified model is available
|
|
585
|
+
- Verify system prompt is not empty
|
|
586
|
+
- Ensure required fields are provided
|
|
587
|
+
|
|
588
|
+
**Test Failures**
|
|
589
|
+
- Check agent is active (`isActive: true`)
|
|
590
|
+
- Verify model is responding (check provider status)
|
|
591
|
+
- Test with simple message first
|
|
592
|
+
|
|
593
|
+
**Performance Issues**
|
|
594
|
+
- Adjust temperature for faster/more deterministic responses
|
|
595
|
+
- Reduce maxTokens if responses are too long
|
|
596
|
+
- Check rate limiting configuration
|
|
597
|
+
|
|
598
|
+
**Memory Usage**
|
|
599
|
+
- Delete unused agents regularly
|
|
600
|
+
- Monitor agent count with `ctx.majk.agents.count()`
|
|
601
|
+
- Use filtering to manage large numbers of agents
|
|
602
|
+
|
|
603
|
+
### Debugging
|
|
604
|
+
|
|
605
|
+
```typescript
|
|
606
|
+
async function debugAgent(ctx: PluginContext, agentId: string) {
|
|
607
|
+
const agent = await ctx.majk.agents.get(agentId);
|
|
608
|
+
if (!agent) {
|
|
609
|
+
console.log('Agent not found');
|
|
610
|
+
return;
|
|
611
|
+
}
|
|
612
|
+
|
|
613
|
+
console.log('Agent Details:', {
|
|
614
|
+
id: agent.id,
|
|
615
|
+
name: agent.name,
|
|
616
|
+
model: agent.model,
|
|
617
|
+
isActive: agent.isActive,
|
|
618
|
+
temperature: agent.temperature,
|
|
619
|
+
maxTokens: agent.maxTokens,
|
|
620
|
+
tags: agent.tags
|
|
621
|
+
});
|
|
622
|
+
|
|
623
|
+
// Test basic functionality
|
|
624
|
+
const testResult = await agent.test('Hello');
|
|
625
|
+
console.log('Basic test:', testResult.success ? 'PASS' : 'FAIL');
|
|
626
|
+
if (!testResult.success) {
|
|
627
|
+
console.log('Test error:', testResult.error);
|
|
628
|
+
}
|
|
629
|
+
|
|
630
|
+
// Check MCP servers
|
|
631
|
+
const mcpServers = await agent.getMCPServers();
|
|
632
|
+
console.log('MCP Servers:', mcpServers.length);
|
|
633
|
+
}
|
|
634
|
+
```
|
|
635
|
+
|
|
636
|
+
## Related APIs
|
|
637
|
+
|
|
638
|
+
- [Tasks API](./TASKS.md) - Use agents for automated task processing
|
|
639
|
+
- [Teammates API](./TEAMMATES.md) - Enhanced agents with skills and project assignments
|
|
640
|
+
- [AI API](./AI.md) - Lower-level AI model access
|
|
641
|
+
- [MCP Servers](./SERVICES.md) - External tools and data sources for agents
|