|
| 1 | +--- |
| 2 | +name: TaskInstruction |
| 3 | +cbbaseinfo: |
| 4 | + description: Encapsulates task instructions and their metadata, handling loading/processing from YAML files. |
| 5 | +cbparameters: |
| 6 | + parameters: |
| 7 | + - name: tools |
| 8 | + typeName: Tools |
| 9 | + description: Object containing tool definitions with descriptions and usage examples |
| 10 | + - name: userMessage |
| 11 | + typeName: UserMessage |
| 12 | + description: User message content handler for prompt generation |
| 13 | + - name: filepath |
| 14 | + typeName: string |
| 15 | + description: Path to YAML file containing task definitions |
| 16 | + - name: refsection |
| 17 | + typeName: string |
| 18 | + description: Specific section key to load from the YAML file |
| 19 | + returns: |
| 20 | + signatureTypeName: TaskInstruction |
| 21 | + description: New TaskInstruction instance configured with provided parameters |
| 22 | + typeArgs: [] |
| 23 | +data: |
| 24 | + name: TaskInstruction |
| 25 | + category: task-management |
| 26 | + link: TaskInstruction.md |
| 27 | +--- |
| 28 | +<CBBaseInfo/> |
| 29 | +<CBParameters/> |
| 30 | + |
| 31 | +### Example |
| 32 | + |
| 33 | +```js |
| 34 | +import { TaskInstruction } from './task-instruction'; |
| 35 | +import { UserMessage } from './usermessage'; |
| 36 | + |
| 37 | +// Sample tools configuration |
| 38 | +const tools = { |
| 39 | + fileProcessor: { |
| 40 | + description: "Handles file operations", |
| 41 | + usage: "processFile(filename)", |
| 42 | + example: "processFile('data.txt')" |
| 43 | + } |
| 44 | +}; |
| 45 | + |
| 46 | +// Create a UserMessage instance |
| 47 | +const userMsg = new UserMessage(/* message configuration */); |
| 48 | + |
| 49 | +// Initialize task instruction loader |
| 50 | +const taskInstruction = new TaskInstruction( |
| 51 | + tools, |
| 52 | + userMsg, |
| 53 | + "./tasks/data_processing.yml", |
| 54 | + "data_cleanup" |
| 55 | +); |
| 56 | + |
| 57 | +// Generate prompts with task details |
| 58 | +try { |
| 59 | + const prompts = await taskInstruction.toPrompt(); |
| 60 | + console.log("Generated prompts:", prompts); |
| 61 | +} catch (error) { |
| 62 | + console.error("Failed to process task:", error); |
| 63 | +} |
0 commit comments