import { readFile } from 'node:fs/promises'; import path from 'node:path'; import { fileURLToPath } from 'node:url'; import { AutomationContext, AutomationRunner, ChatService, workflow } from '@athree/runner'; import { dep } from 'mesh-ioc'; import { SimpleLearningAgentExtractInputsSchema, SimpleLearningAgentExtractOutputsSchema } from '../schema/SimpleLearningAgentExtract.js'; const __dirname = path.dirname(fileURLToPath(import.meta.url)); /** * Simple Learning Agent Extract Workflow * * Demonstrates the learning agent pattern: * 1. Loads instructions from a markdown file * 2. Sets up automation context with input/output schemas * 3. Uses AutomationRunner.learn() to execute with LLM guidance * 4. The LLM creates reusable stages to navigate and extract data * * Use this pattern for complex, multi-step automations. */ @workflow({ title: 'Simple Learning Agent Extract', }) export class SimpleLearningAgentExtractWorkflow { @dep() private chat!: ChatService; @dep() private automation!: AutomationContext; @dep() private automationRunner!: AutomationRunner; async run() { const url = 'https://example.com'; this.chat.addMessage({ content: 'Starting simple learning agent extract workflow', }); // Load instructions from markdown file const instructionsPath = path.join(__dirname, '..', 'instructions', 'SimpleLearningAgentExtract.instructions.md'); const instructions = await readFile(instructionsPath, 'utf-8'); this.chat.addMessage({ content: `Extracting content from ${url}`, }); // Run the learning agent const result = await this.automationRunner.learn({ automationId: 'simple-learning-agent-extract', instructions, inputs: { url }, inputsSchema: SimpleLearningAgentExtractInputsSchema, outputsSchema: SimpleLearningAgentExtractOutputsSchema, learningModel: 'gemini-3-flash-preview', }); // Get the extracted outputs const outputs = this.automation.outputs; this.chat.addMessage({ content: `Workflow complete: ${result.result}`, data: { result: result.result, outputs, }, }); } }