|
3 | 3 | A custom universal agent is a type of agent in CodeBolt designed to interact dynamically with user messages and handle specific actions or workflows. The agent interprets a structured `Message` payload and returns a tailored `ResponseMessage`, specifying instructions for various tasks such as code generation, testing, deployment, and more.
|
4 | 4 |
|
5 | 5 |
|
6 |
| -### Data Types |
7 |
| -* Message: Contains user input and details of the current context, including the selected agent, referenced files, folders, actions, and other agents involved in the request. |
| 6 | +### create custom universal Agent |
8 | 7 |
|
9 | 8 | ```bash
|
| 9 | +//you will get this request form codebolt |
10 | 10 | export type Message = {
|
11 | 11 | userMessage: string;
|
12 | 12 | currentFile: string;
|
13 | 13 | selectedAgent: { id: string; name: string; lastMessage: object };
|
14 | 14 | mentionedFiles: string[];
|
15 | 15 | mentionedFolders: string[];
|
16 | 16 | actions: string[];
|
17 |
| - mentionedAgents: any[]; |
| 17 | + mentionedAgents: any[]; // Specify the type if known |
18 | 18 | universalAgentLastMessage: string;
|
19 | 19 | };
|
20 |
| -``` |
21 |
| -
|
22 |
| -* Instruction: Describes a single action or step for an agent to take in response to the `Message`. |
23 | 20 |
|
24 |
| -```bash |
25 | 21 | export type Instruction = {
|
26 |
| - agentId: string; |
27 |
| - step: Steps; |
28 |
| - action: string; |
29 |
| - prompt: string; |
| 22 | + agentId: string; |
| 23 | + step: Steps; |
| 24 | + action: string; |
| 25 | + prompt: string; |
30 | 26 | };
|
31 | 27 |
|
32 |
| -``` |
33 |
| -
|
34 |
| -* ResponseMessage: The output format expected from the custom universal agent, containing a list of instructions. |
35 |
| -
|
36 |
| -```bash |
| 28 | +//this is type of response you need to send |
37 | 29 | export type ResponseMessage = {
|
38 |
| - instructions: Instruction[]; |
| 30 | + instructions: Instruction[]; |
39 | 31 | };
|
40 | 32 |
|
| 33 | +export enum Steps { |
| 34 | + USER_QUESTION = 'userquestion', |
| 35 | + CODE_GENERATION = 'codegeneration', |
| 36 | + TESTING = 'testing', |
| 37 | + DEPLOY = 'deploy', |
| 38 | + DOCUMENTATION = 'documentation', |
| 39 | + REVIEW = 'review' |
| 40 | +} |
| 41 | + |
41 | 42 | ```
|
42 | 43 |
|
| 44 | +* Message: Contains user input and details of the current context, including the selected agent, referenced files, folders, actions, and other agents involved in the request. |
| 45 | +
|
| 46 | +* Instruction: Describes a single action or step for an agent to take in response to the `Message`. |
| 47 | +
|
| 48 | +* ResponseMessage: The output format expected from the custom universal agent, containing a list of instructions. |
| 49 | +
|
43 | 50 | * Steps : Enumerates the different stages an agent might use to process the user's request, allowing for more organized workflows.
|
44 | 51 |
|
45 |
| -```bash |
46 |
| -export enum Steps { |
47 |
| - USER_QUESTION = 'userquestion', |
48 |
| - CODE_GENERATION = 'codegeneration', |
49 |
| - TESTING = 'testing', |
50 |
| - DEPLOY = 'deploy', |
51 |
| - DOCUMENTATION = 'documentation', |
52 |
| - REVIEW = 'review' |
53 |
| -} |
54 | 52 |
|
55 |
| -``` |
| 53 | +```bash |
| 54 | +const express = require('express'); |
| 55 | +const app = express(); |
| 56 | +const port = 3000; |
| 57 | +
|
| 58 | +// Middleware to parse JSON request bodies |
| 59 | +app.use(express.json()); |
| 60 | +
|
| 61 | +// Define your endpoint |
| 62 | +app.post('/message', (req, res) => { |
| 63 | + const message = req.body; // Extracting the Message from the request body |
| 64 | + |
| 65 | + // write you logic to filter agent based on user message |
| 66 | + const responseMessage = { |
| 67 | + instructions: [ |
| 68 | + { |
| 69 | + agentId: selectedAgent.id, |
| 70 | + step: 'USER_QUESTION', // As an example step |
| 71 | + action: 'Process the message', |
| 72 | + prompt: message.userMessage |
| 73 | + } |
| 74 | + ] |
| 75 | + }; |
| 76 | + //this is the format of respose you will need to send back |
| 77 | +
|
| 78 | + res.json(responseMessage); |
| 79 | +); |
| 80 | +// Start the server |
| 81 | +app.listen(port, () => { |
| 82 | + console.log(`Server is running on http://localhost:${port}`); |
| 83 | +}); |
| 84 | +``` |
0 commit comments