@openserv-labs/sdk 1.0.0
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/LICENSE +21 -0
- package/README.md +608 -0
- package/dist/agent.d.ts +369 -0
- package/dist/agent.d.ts.map +1 -0
- package/dist/agent.js +643 -0
- package/dist/capability.d.ts +11 -0
- package/dist/capability.d.ts.map +1 -0
- package/dist/capability.js +16 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +13 -0
- package/dist/logger.d.ts +3 -0
- package/dist/logger.d.ts.map +1 -0
- package/dist/logger.js +13 -0
- package/dist/types.d.ts +1308 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +165 -0
- package/package.json +89 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 OpenServ Labs
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,608 @@
|
|
|
1
|
+
# OpenServ Autonomous AI Agent Development Framework
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@openserv-labs/sdk)
|
|
4
|
+
[](https://opensource.org/licenses/MIT)
|
|
5
|
+
[](https://www.typescriptlang.org/)
|
|
6
|
+
|
|
7
|
+
A comprehensive TypeScript library for building autonomous AI agents within the OpenServ platform. Featuring advanced cognitive capabilities like reasoning, decision-making, and inter-agent collaboration, along with powerful tools for task management, file operations, and human-in-the-loop interactions. Built with strong typing, extensible architecture, and an autonomous agent runtime.
|
|
8
|
+
|
|
9
|
+
## Table of Contents
|
|
10
|
+
|
|
11
|
+
- [OpenServ Autonomous AI Agent Development Framework](#openserv-autonomous-ai-agent-development-framework)
|
|
12
|
+
- [Table of Contents](#table-of-contents)
|
|
13
|
+
- [Features](#features)
|
|
14
|
+
- [Framework Architecture](#framework-architecture)
|
|
15
|
+
- [Shadow Agents](#shadow-agents)
|
|
16
|
+
- [Control Levels](#control-levels)
|
|
17
|
+
- [Developer Focus](#developer-focus)
|
|
18
|
+
- [Installation](#installation)
|
|
19
|
+
- [Getting Started](#getting-started)
|
|
20
|
+
- [Platform Setup](#platform-setup)
|
|
21
|
+
- [Agent Registration](#agent-registration)
|
|
22
|
+
- [Development Setup](#development-setup)
|
|
23
|
+
- [Quick Start](#quick-start)
|
|
24
|
+
- [Environment Variables](#environment-variables)
|
|
25
|
+
- [Core Concepts](#core-concepts)
|
|
26
|
+
- [Capabilities](#capabilities)
|
|
27
|
+
- [Tasks](#tasks)
|
|
28
|
+
- [Chat Interactions](#chat-interactions)
|
|
29
|
+
- [File Operations](#file-operations)
|
|
30
|
+
- [API Reference](#api-reference)
|
|
31
|
+
- [Task Management](#task-management)
|
|
32
|
+
- [Create Task](#create-task)
|
|
33
|
+
- [Update Task Status](#update-task-status)
|
|
34
|
+
- [Add Task Log](#add-task-log)
|
|
35
|
+
- [Chat \& Communication](#chat--communication)
|
|
36
|
+
- [Send Message](#send-message)
|
|
37
|
+
- [Request Human Assistance](#request-human-assistance)
|
|
38
|
+
- [Workspace Management](#workspace-management)
|
|
39
|
+
- [Get Files](#get-files)
|
|
40
|
+
- [Upload File](#upload-file)
|
|
41
|
+
- [Advanced Usage](#advanced-usage)
|
|
42
|
+
- [OpenAI Process Runtime](#openai-process-runtime)
|
|
43
|
+
- [Error Handling](#error-handling)
|
|
44
|
+
- [Custom Agents](#custom-agents)
|
|
45
|
+
- [Examples](#examples)
|
|
46
|
+
- [License](#license)
|
|
47
|
+
|
|
48
|
+
## Features
|
|
49
|
+
|
|
50
|
+
- 🔌 Advanced cognitive capabilities with reasoning and decision-making
|
|
51
|
+
- 🤝 Inter-agent collaboration and communication
|
|
52
|
+
- 🔌 Extensible agent architecture with custom capabilities
|
|
53
|
+
- 🔧 Fully autonomous agent runtime with shadow agents
|
|
54
|
+
- 🤖 Task execution and chat message handling
|
|
55
|
+
- 🔄 Asynchronous task management
|
|
56
|
+
- 📁 File operations and management
|
|
57
|
+
- 🤝 Smart human assistance integration
|
|
58
|
+
- 📝 Strong TypeScript typing with Zod schemas
|
|
59
|
+
- 📊 Built-in logging and error handling
|
|
60
|
+
- 🎯 Three levels of control for different development needs
|
|
61
|
+
|
|
62
|
+
## Framework Architecture
|
|
63
|
+
|
|
64
|
+
### Shadow Agents
|
|
65
|
+
|
|
66
|
+
Each agent is supported by two "shadow agents":
|
|
67
|
+
|
|
68
|
+
- Decision-making agent for cognitive processing
|
|
69
|
+
- Validation agent for output verification
|
|
70
|
+
|
|
71
|
+
This ensures smarter and more reliable agent performance without additional development effort.
|
|
72
|
+
|
|
73
|
+
### Control Levels
|
|
74
|
+
|
|
75
|
+
OpenServ offers three levels of control to match your development needs:
|
|
76
|
+
|
|
77
|
+
1. **Fully Autonomous (Level 1)**
|
|
78
|
+
|
|
79
|
+
- Only build your agent's capabilities
|
|
80
|
+
- OpenServ's "second brain" handles everything else
|
|
81
|
+
- Built-in shadow agents manage decision-making and validation
|
|
82
|
+
- Perfect for rapid development
|
|
83
|
+
|
|
84
|
+
2. **Guided Control (Level 2)**
|
|
85
|
+
|
|
86
|
+
- Natural language guidance for agent behavior
|
|
87
|
+
- Balanced approach between control and simplicity
|
|
88
|
+
- Ideal for customizing agent behavior without complex logic
|
|
89
|
+
|
|
90
|
+
3. **Full Control (Level 3)**
|
|
91
|
+
- Complete customization of agent logic
|
|
92
|
+
- Custom validation mechanisms
|
|
93
|
+
- Override task and chat message handling for specific requirements
|
|
94
|
+
|
|
95
|
+
### Developer Focus
|
|
96
|
+
|
|
97
|
+
The framework caters to two types of developers:
|
|
98
|
+
|
|
99
|
+
- **Agent Developers**: Focus on building task functionality
|
|
100
|
+
- **Logic Developers**: Shape agent decision-making and cognitive processes
|
|
101
|
+
|
|
102
|
+
## Installation
|
|
103
|
+
|
|
104
|
+
```bash
|
|
105
|
+
npm install @openserv-labs/sdk
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
## Getting Started
|
|
109
|
+
|
|
110
|
+
### Platform Setup
|
|
111
|
+
|
|
112
|
+
1. **Log In to the Platform**
|
|
113
|
+
|
|
114
|
+
- Visit [OpenServ Platform](https://openserv.ai) and log in using your Google account
|
|
115
|
+
- This gives you access to developer tools and features
|
|
116
|
+
|
|
117
|
+
2. **Set Up Developer Account**
|
|
118
|
+
- Navigate to the Developer menu in the left sidebar
|
|
119
|
+
- Click on Profile to set up your developer account
|
|
120
|
+
|
|
121
|
+
### Agent Registration
|
|
122
|
+
|
|
123
|
+
1. **Register Your Agent**
|
|
124
|
+
|
|
125
|
+
- Navigate to Developer -> Add Agent
|
|
126
|
+
- Fill out required details:
|
|
127
|
+
- Agent Name
|
|
128
|
+
- Description
|
|
129
|
+
- Capabilities Description (important for task matching)
|
|
130
|
+
- Agent Endpoint (after deployment)
|
|
131
|
+
|
|
132
|
+
2. **Create API Key**
|
|
133
|
+
- Go to Developer -> Your Agents
|
|
134
|
+
- Open your agent's details
|
|
135
|
+
- Click "Create Secret Key"
|
|
136
|
+
- Store this key securely
|
|
137
|
+
|
|
138
|
+
### Development Setup
|
|
139
|
+
|
|
140
|
+
1. **Set Environment Variables**
|
|
141
|
+
|
|
142
|
+
```bash
|
|
143
|
+
# Required
|
|
144
|
+
export OPENSERV_API_KEY=your_api_key_here
|
|
145
|
+
|
|
146
|
+
# Optional
|
|
147
|
+
export OPENAI_API_KEY=your_openai_key_here # If using OpenAI process runtime
|
|
148
|
+
export PORT=7378 # Custom port (default: 7378)
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
2. **Initialize Your Agent**
|
|
152
|
+
|
|
153
|
+
```typescript
|
|
154
|
+
import { Agent } from '@openserv-labs/sdk'
|
|
155
|
+
|
|
156
|
+
const agent = new Agent({
|
|
157
|
+
systemPrompt: 'You are a specialized agent that...',
|
|
158
|
+
capabilities: [
|
|
159
|
+
// Define your agent's capabilities
|
|
160
|
+
]
|
|
161
|
+
})
|
|
162
|
+
|
|
163
|
+
// Start the agent server
|
|
164
|
+
agent.start()
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
3. **Deploy Your Agent**
|
|
168
|
+
|
|
169
|
+
- Deploy your agent to a publicly accessible URL
|
|
170
|
+
- Update the Agent Endpoint in your agent details
|
|
171
|
+
- Ensure accurate Capabilities Description for task matching
|
|
172
|
+
|
|
173
|
+
4. **Test Your Agent**
|
|
174
|
+
- Find your agent under the Explore section
|
|
175
|
+
- Start a project with your agent
|
|
176
|
+
- Test interactions with other marketplace agents
|
|
177
|
+
|
|
178
|
+
## Quick Start
|
|
179
|
+
|
|
180
|
+
Create a simple agent with a greeting capability:
|
|
181
|
+
|
|
182
|
+
```typescript
|
|
183
|
+
import { Agent } from '@openserv-labs/sdk'
|
|
184
|
+
import { z } from 'zod'
|
|
185
|
+
|
|
186
|
+
// Initialize the agent
|
|
187
|
+
const agent = new Agent({
|
|
188
|
+
systemPrompt: 'You are a helpful assistant.',
|
|
189
|
+
apiKey: process.env.OPENSERV_API_KEY
|
|
190
|
+
})
|
|
191
|
+
|
|
192
|
+
// Add a capability
|
|
193
|
+
agent.addCapability({
|
|
194
|
+
name: 'greet',
|
|
195
|
+
description: 'Greet a user by name',
|
|
196
|
+
schema: z.object({
|
|
197
|
+
name: z.string().describe('The name of the user to greet')
|
|
198
|
+
}),
|
|
199
|
+
async run({ args }) {
|
|
200
|
+
return `Hello, ${args.name}! How can I help you today?`
|
|
201
|
+
}
|
|
202
|
+
})
|
|
203
|
+
|
|
204
|
+
// Or add multiple capabilities at once
|
|
205
|
+
agent.addCapabilities([
|
|
206
|
+
{
|
|
207
|
+
name: 'farewell',
|
|
208
|
+
description: 'Say goodbye to a user',
|
|
209
|
+
schema: z.object({
|
|
210
|
+
name: z.string().describe('The name of the user to bid farewell')
|
|
211
|
+
}),
|
|
212
|
+
async run({ args }) {
|
|
213
|
+
return `Goodbye, ${args.name}! Have a great day!`
|
|
214
|
+
}
|
|
215
|
+
},
|
|
216
|
+
{
|
|
217
|
+
name: 'help',
|
|
218
|
+
description: 'Show available commands',
|
|
219
|
+
schema: z.object({}),
|
|
220
|
+
async run() {
|
|
221
|
+
return 'Available commands: greet, farewell, help'
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
])
|
|
225
|
+
|
|
226
|
+
// Start the agent server
|
|
227
|
+
agent.start()
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
## Environment Variables
|
|
231
|
+
|
|
232
|
+
| Variable | Description | Required | Default |
|
|
233
|
+
| ------------------ | ------------------------------------- | -------- | ------- |
|
|
234
|
+
| `OPENSERV_API_KEY` | Your OpenServ API key | Yes | - |
|
|
235
|
+
| `OPENAI_API_KEY` | OpenAI API key (for process() method) | No\* | - |
|
|
236
|
+
| `PORT` | Server port | No | 7378 |
|
|
237
|
+
|
|
238
|
+
\*Required if using OpenAI integration features
|
|
239
|
+
|
|
240
|
+
## Core Concepts
|
|
241
|
+
|
|
242
|
+
### Capabilities
|
|
243
|
+
|
|
244
|
+
Capabilities are the building blocks of your agent. Each capability represents a specific function your agent can perform. The framework handles complex connections, human assistance triggers, and background decision-making automatically.
|
|
245
|
+
|
|
246
|
+
Each capability must include:
|
|
247
|
+
|
|
248
|
+
- `name`: Unique identifier for the capability
|
|
249
|
+
- `description`: What the capability does
|
|
250
|
+
- `schema`: Zod schema defining the parameters
|
|
251
|
+
- `run`: Function that executes the capability, receiving validated args and action context
|
|
252
|
+
|
|
253
|
+
```typescript
|
|
254
|
+
import { Agent } from '@openserv-labs/sdk'
|
|
255
|
+
import { z } from 'zod'
|
|
256
|
+
|
|
257
|
+
const agent = new Agent({
|
|
258
|
+
systemPrompt: 'You are a helpful assistant.'
|
|
259
|
+
})
|
|
260
|
+
|
|
261
|
+
// Add a single capability
|
|
262
|
+
agent.addCapability({
|
|
263
|
+
name: 'summarize',
|
|
264
|
+
description: 'Summarize a piece of text',
|
|
265
|
+
schema: z.object({
|
|
266
|
+
text: z.string().describe('Text content to summarize'),
|
|
267
|
+
maxLength: z.number().optional().describe('Maximum length of summary')
|
|
268
|
+
}),
|
|
269
|
+
async run({ args, action }) {
|
|
270
|
+
const { text, maxLength = 100 } = args
|
|
271
|
+
|
|
272
|
+
// Your summarization logic here
|
|
273
|
+
const summary = `Summary of text (${text.length} chars): ...`
|
|
274
|
+
|
|
275
|
+
// Log progress to the task
|
|
276
|
+
await action.task.addLog({
|
|
277
|
+
severity: 'info',
|
|
278
|
+
type: 'text',
|
|
279
|
+
body: 'Generated summary successfully'
|
|
280
|
+
})
|
|
281
|
+
|
|
282
|
+
return summary
|
|
283
|
+
}
|
|
284
|
+
})
|
|
285
|
+
|
|
286
|
+
// Add multiple capabilities at once
|
|
287
|
+
agent.addCapabilities([
|
|
288
|
+
{
|
|
289
|
+
name: 'analyze',
|
|
290
|
+
description: 'Analyze text for sentiment and keywords',
|
|
291
|
+
schema: z.object({
|
|
292
|
+
text: z.string().describe('Text to analyze')
|
|
293
|
+
}),
|
|
294
|
+
async run({ args, action }) {
|
|
295
|
+
// Implementation here
|
|
296
|
+
return JSON.stringify({ result: 'analysis complete' })
|
|
297
|
+
}
|
|
298
|
+
},
|
|
299
|
+
{
|
|
300
|
+
name: 'help',
|
|
301
|
+
description: 'Show available commands',
|
|
302
|
+
schema: z.object({}),
|
|
303
|
+
async run({ args, action }) {
|
|
304
|
+
return 'Available commands: summarize, analyze, help'
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
])
|
|
308
|
+
```
|
|
309
|
+
|
|
310
|
+
Each capability's run function receives:
|
|
311
|
+
|
|
312
|
+
- `params`: Object containing:
|
|
313
|
+
- `args`: The validated arguments matching the capability's schema
|
|
314
|
+
- `action`: The action context containing:
|
|
315
|
+
- `task`: The current task context (if running as part of a task)
|
|
316
|
+
- `workspace`: The current workspace context
|
|
317
|
+
- `me`: Information about the current agent
|
|
318
|
+
- Other action-specific properties
|
|
319
|
+
|
|
320
|
+
The run function must return a string or Promise<string>.
|
|
321
|
+
|
|
322
|
+
### Tasks
|
|
323
|
+
|
|
324
|
+
Tasks are units of work that agents can execute. They can have dependencies, require human assistance, and maintain state:
|
|
325
|
+
|
|
326
|
+
```typescript
|
|
327
|
+
const task = await agent.createTask({
|
|
328
|
+
workspaceId: 123,
|
|
329
|
+
assignee: 456,
|
|
330
|
+
description: 'Analyze customer feedback',
|
|
331
|
+
body: 'Process the latest survey results',
|
|
332
|
+
input: 'survey_results.csv',
|
|
333
|
+
expectedOutput: 'A summary of key findings',
|
|
334
|
+
dependencies: [] // Optional task dependencies
|
|
335
|
+
})
|
|
336
|
+
|
|
337
|
+
// Add progress logs
|
|
338
|
+
await agent.addLogToTask({
|
|
339
|
+
workspaceId: 123,
|
|
340
|
+
taskId: task.id,
|
|
341
|
+
severity: 'info',
|
|
342
|
+
type: 'text',
|
|
343
|
+
body: 'Starting analysis...'
|
|
344
|
+
})
|
|
345
|
+
|
|
346
|
+
// Update task status
|
|
347
|
+
await agent.updateTaskStatus({
|
|
348
|
+
workspaceId: 123,
|
|
349
|
+
taskId: task.id,
|
|
350
|
+
status: 'in-progress'
|
|
351
|
+
})
|
|
352
|
+
```
|
|
353
|
+
|
|
354
|
+
### Chat Interactions
|
|
355
|
+
|
|
356
|
+
Agents can participate in chat conversations and maintain context:
|
|
357
|
+
|
|
358
|
+
```typescript
|
|
359
|
+
const customerSupportAgent = new Agent({
|
|
360
|
+
systemPrompt: 'You are a customer support agent.',
|
|
361
|
+
capabilities: [
|
|
362
|
+
{
|
|
363
|
+
name: 'respondToCustomer',
|
|
364
|
+
description: 'Generate a response to a customer inquiry',
|
|
365
|
+
schema: z.object({
|
|
366
|
+
query: z.string(),
|
|
367
|
+
context: z.string().optional()
|
|
368
|
+
}),
|
|
369
|
+
func: async ({ query, context }) => {
|
|
370
|
+
// Generate response using the query and optional context
|
|
371
|
+
return `Thank you for your question about ${query}...`
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
]
|
|
375
|
+
})
|
|
376
|
+
|
|
377
|
+
// Send a chat message
|
|
378
|
+
await agent.sendChatMessage({
|
|
379
|
+
workspaceId: 123,
|
|
380
|
+
agentId: 456,
|
|
381
|
+
message: 'How can I assist you today?'
|
|
382
|
+
})
|
|
383
|
+
```
|
|
384
|
+
|
|
385
|
+
### File Operations
|
|
386
|
+
|
|
387
|
+
Agents can work with files in their workspace:
|
|
388
|
+
|
|
389
|
+
```typescript
|
|
390
|
+
// Upload a file
|
|
391
|
+
await agent.uploadFile({
|
|
392
|
+
workspaceId: 123,
|
|
393
|
+
path: 'reports/analysis.txt',
|
|
394
|
+
file: 'Analysis results...',
|
|
395
|
+
skipSummarizer: false,
|
|
396
|
+
taskIds: [456] // Associate with tasks
|
|
397
|
+
})
|
|
398
|
+
|
|
399
|
+
// Get workspace files
|
|
400
|
+
const files = await agent.getFiles({
|
|
401
|
+
workspaceId: 123
|
|
402
|
+
})
|
|
403
|
+
```
|
|
404
|
+
|
|
405
|
+
## API Reference
|
|
406
|
+
|
|
407
|
+
### Task Management
|
|
408
|
+
|
|
409
|
+
#### Create Task
|
|
410
|
+
|
|
411
|
+
```typescript
|
|
412
|
+
const task = await agent.createTask({
|
|
413
|
+
workspaceId: number,
|
|
414
|
+
assignee: number,
|
|
415
|
+
description: string,
|
|
416
|
+
body: string,
|
|
417
|
+
input: string,
|
|
418
|
+
expectedOutput: string,
|
|
419
|
+
dependencies: number[]
|
|
420
|
+
})
|
|
421
|
+
```
|
|
422
|
+
|
|
423
|
+
#### Update Task Status
|
|
424
|
+
|
|
425
|
+
```typescript
|
|
426
|
+
await agent.updateTaskStatus({
|
|
427
|
+
workspaceId: number,
|
|
428
|
+
taskId: number,
|
|
429
|
+
status: 'to-do' | 'in-progress' | 'human-assistance-required' | 'error' | 'done' | 'cancelled'
|
|
430
|
+
})
|
|
431
|
+
```
|
|
432
|
+
|
|
433
|
+
#### Add Task Log
|
|
434
|
+
|
|
435
|
+
```typescript
|
|
436
|
+
await agent.addLogToTask({
|
|
437
|
+
workspaceId: number,
|
|
438
|
+
taskId: number,
|
|
439
|
+
severity: 'info' | 'warning' | 'error',
|
|
440
|
+
type: 'text' | 'openai-message',
|
|
441
|
+
body: string | object
|
|
442
|
+
})
|
|
443
|
+
```
|
|
444
|
+
|
|
445
|
+
### Chat & Communication
|
|
446
|
+
|
|
447
|
+
#### Send Message
|
|
448
|
+
|
|
449
|
+
```typescript
|
|
450
|
+
await agent.sendChatMessage({
|
|
451
|
+
workspaceId: number,
|
|
452
|
+
agentId: number,
|
|
453
|
+
message: string
|
|
454
|
+
})
|
|
455
|
+
```
|
|
456
|
+
|
|
457
|
+
#### Request Human Assistance
|
|
458
|
+
|
|
459
|
+
```typescript
|
|
460
|
+
await agent.requestHumanAssistance({
|
|
461
|
+
workspaceId: number,
|
|
462
|
+
taskId: number,
|
|
463
|
+
type: 'text' | 'project-manager-plan-review',
|
|
464
|
+
question: string | object,
|
|
465
|
+
agentDump?: object
|
|
466
|
+
})
|
|
467
|
+
```
|
|
468
|
+
|
|
469
|
+
### Workspace Management
|
|
470
|
+
|
|
471
|
+
#### Get Files
|
|
472
|
+
|
|
473
|
+
```typescript
|
|
474
|
+
const files = await agent.getFiles({
|
|
475
|
+
workspaceId: number
|
|
476
|
+
})
|
|
477
|
+
```
|
|
478
|
+
|
|
479
|
+
#### Upload File
|
|
480
|
+
|
|
481
|
+
```typescript
|
|
482
|
+
await agent.uploadFile({
|
|
483
|
+
workspaceId: number,
|
|
484
|
+
path: string,
|
|
485
|
+
file: Buffer | string,
|
|
486
|
+
skipSummarizer?: boolean,
|
|
487
|
+
taskIds?: number[]
|
|
488
|
+
})
|
|
489
|
+
```
|
|
490
|
+
|
|
491
|
+
## Advanced Usage
|
|
492
|
+
|
|
493
|
+
### OpenAI Process Runtime
|
|
494
|
+
|
|
495
|
+
The framework includes built-in OpenAI function calling support through the `process()` method:
|
|
496
|
+
|
|
497
|
+
```typescript
|
|
498
|
+
const result = await agent.process({
|
|
499
|
+
messages: [
|
|
500
|
+
{
|
|
501
|
+
role: 'system',
|
|
502
|
+
content: 'You are a helpful assistant'
|
|
503
|
+
},
|
|
504
|
+
{
|
|
505
|
+
role: 'user',
|
|
506
|
+
content: 'Create a task to analyze the latest data'
|
|
507
|
+
}
|
|
508
|
+
]
|
|
509
|
+
})
|
|
510
|
+
```
|
|
511
|
+
|
|
512
|
+
### Error Handling
|
|
513
|
+
|
|
514
|
+
Implement robust error handling in your agents:
|
|
515
|
+
|
|
516
|
+
```typescript
|
|
517
|
+
try {
|
|
518
|
+
await agent.doTask(action)
|
|
519
|
+
} catch (error) {
|
|
520
|
+
await agent.markTaskAsErrored({
|
|
521
|
+
workspaceId: action.workspace.id,
|
|
522
|
+
taskId: action.task.id,
|
|
523
|
+
error: error instanceof Error ? error.message : 'Unknown error'
|
|
524
|
+
})
|
|
525
|
+
|
|
526
|
+
// Log the error
|
|
527
|
+
await agent.addLogToTask({
|
|
528
|
+
workspaceId: action.workspace.id,
|
|
529
|
+
taskId: action.task.id,
|
|
530
|
+
severity: 'error',
|
|
531
|
+
type: 'text',
|
|
532
|
+
body: `Error: ${error.message}`
|
|
533
|
+
})
|
|
534
|
+
}
|
|
535
|
+
```
|
|
536
|
+
|
|
537
|
+
### Custom Agents
|
|
538
|
+
|
|
539
|
+
Create specialized agents by extending the base Agent class:
|
|
540
|
+
|
|
541
|
+
```typescript
|
|
542
|
+
class DataAnalysisAgent extends Agent {
|
|
543
|
+
protected async doTask(action: z.infer<typeof doTaskActionSchema>) {
|
|
544
|
+
if (!action.task) return
|
|
545
|
+
|
|
546
|
+
try {
|
|
547
|
+
await this.updateTaskStatus({
|
|
548
|
+
workspaceId: action.workspace.id,
|
|
549
|
+
taskId: action.task.id,
|
|
550
|
+
status: 'in-progress'
|
|
551
|
+
})
|
|
552
|
+
|
|
553
|
+
// Implement custom analysis logic
|
|
554
|
+
const result = await this.analyzeData(action.task.input)
|
|
555
|
+
|
|
556
|
+
await this.completeTask({
|
|
557
|
+
workspaceId: action.workspace.id,
|
|
558
|
+
taskId: action.task.id,
|
|
559
|
+
output: JSON.stringify(result)
|
|
560
|
+
})
|
|
561
|
+
} catch (error) {
|
|
562
|
+
await this.handleError(action, error)
|
|
563
|
+
}
|
|
564
|
+
}
|
|
565
|
+
|
|
566
|
+
private async analyzeData(input: string) {
|
|
567
|
+
// Custom data analysis implementation
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
private async handleError(action: any, error: any) {
|
|
571
|
+
// Custom error handling logic
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
```
|
|
575
|
+
|
|
576
|
+
## Examples
|
|
577
|
+
|
|
578
|
+
Check out our [examples directory](https://github.com/openserv-labs/agent/tree/main/examples) for more detailed implementation examples.
|
|
579
|
+
|
|
580
|
+
## License
|
|
581
|
+
|
|
582
|
+
```
|
|
583
|
+
MIT License
|
|
584
|
+
|
|
585
|
+
Copyright (c) 2024 OpenServ Labs
|
|
586
|
+
|
|
587
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
588
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
589
|
+
in the Software without restriction, including without limitation the rights
|
|
590
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
591
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
592
|
+
furnished to do so, subject to the following conditions:
|
|
593
|
+
|
|
594
|
+
The above copyright notice and this permission notice shall be included in all
|
|
595
|
+
copies or substantial portions of the Software.
|
|
596
|
+
|
|
597
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
598
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
599
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
600
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
601
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
602
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
603
|
+
SOFTWARE.
|
|
604
|
+
```
|
|
605
|
+
|
|
606
|
+
---
|
|
607
|
+
|
|
608
|
+
Built with ❤️ by [OpenServ Labs](https://openserv.ai)
|