Execution Patterns: Workflows & Teams
Agent Forge supports flexible execution patterns to orchestrate multiple agents, allowing you to build sophisticated applications. The two primary patterns highlighted are Sequential Workflows and Hierarchical Teams.
Sequential Workflows
Workflows in Agent Forge enable you to define a sequence of agents that execute tasks one after another. The output of one agent can potentially serve as the input for the next, allowing for a step-by-step problem-solving process.
Use Cases:
- Multi-stage processing: Research a topic with one agent, summarize the findings with another, and then translate the summary with a third.
- Data transformation pipelines: An agent extracts data, another cleans it, and a third analyzes it.
- Guided task completion: Breaking down a complex task into smaller, manageable steps, each handled by a specialized agent in sequence.
Defining and Running a Workflow:
import { Workflow, AgentForge, LLM, Agent } from "agent-forge"; // Assuming Agent is part of agent-forge or imported correctly
import dotenv from 'dotenv';
dotenv.config();
async function runWorkflowExample() {
const apiKey = process.env.OPENAI_API_KEY;
if (!apiKey) {
console.error("OPENAI_API_KEY not set. Please set it in your .env file.");
return;
}
const llmProvider = new LLM("openai", { apiKey });
const forge = new AgentForge(llmProvider);
// Load agent definitions from YAML (ensure these files exist and are valid)
// Example: ./research-agent.yaml, ./summary-agent.yaml
// Ensure these YAML files define agents compatible with the llmProvider (e.g., correct model names)
const researchAgent = await forge.loadAgent("./research-agent.yaml");
const summaryAgent = await forge.loadAgent("./summary-agent.yaml");
// Create a workflow
const workflow = new Workflow("ResearchAndSummarizeWorkflow") // Optional: Name your workflow
.addStep(researchAgent) // First agent in the sequence
.addStep(summaryAgent); // Second agent in the sequence
try {
// The initial input is passed to the first agent in the workflow.
const result = await workflow.run(
"Explain quantum computing advancements in 2023"
);
console.log("\nWorkflow Final Result:", result);
} catch (error) {
console.error("Error running workflow:", error);
}
}
// To run this example:
// runWorkflowExample().catch(console.error);
Key characteristics:
- Agents are added to the workflow in the desired order of execution.
- The
workflow.run()
method initiates the sequence, passing the initial input to the first agent. - The framework manages the flow of information between agents (details of this data flow would be specific to Agent Forge's implementation).
Hierarchical Teams
Teams in Agent Forge allow for a hierarchical execution model, where a manager agent delegates tasks to a group of specialized member agents. The manager is responsible for breaking down a larger objective, assigning sub-tasks, and potentially synthesizing the results from member agents.
Use Cases:
- Complex problem solving: A manager agent coordinates a coder agent, a QA agent, and a documentation agent to develop a software feature.
- Creative generation: A manager agent directs a writer agent, an artist agent, and a layout agent to produce a marketing brochure.
- Distributed task execution: A manager assigns different research aspects of a broad topic to multiple specialist research agents.
Defining and Running a Team:
import { Team, AgentForge, LLM, Agent } from "agent-forge"; // Assuming Agent is part of agent-forge or imported correctly
import dotenv from 'dotenv';
dotenv.config();
async function runTeamExample() {
const apiKey = process.env.OPENAI_API_KEY;
if (!apiKey) {
console.error("OPENAI_API_KEY not set. Please set it in your .env file.");
return;
}
const llmProvider = new LLM("openai", { apiKey });
const forge = new AgentForge(llmProvider);
// Load manager and specialized agents from YAML (ensure these files exist and are valid)
// Example: ./manager-agent.yaml, ./code-agent.yaml, ./design-agent.yaml
// Ensure these YAML files define agents compatible with the llmProvider
const managerAgent = await forge.loadAgent("./manager-agent.yaml");
const codeAgent = await forge.loadAgent("./code-agent.yaml");
const designAgent = await forge.loadAgent("./design-agent.yaml");
// Create a team with a manager
const team = new Team(managerAgent, "ProductLandingPageTeam") // The first agent passed is the manager. Optional: Name your team.
.addAgent(codeAgent) // Member agent
.addAgent(designAgent); // Another member agent
try {
const result = await team.run("Create a landing page for our new product");
console.log("\nTeam Final Result:", result);
} catch (error) {
console.error("Error running team:", error);
}
}
// To run this example:
// runTeamExample().catch(console.error);
Key characteristics:
- A
Team
is initialized with a designated manager agent. - Other agents are added as members of the team.
- When
team.run()
is called with an objective, the manager agent receives it. The manager then strategizes and delegates tasks to its member agents based on their roles and capabilities. - Agent Forge likely handles the communication and task management within the team structure.
These execution patterns provide developers with powerful constructs to design and implement complex multi-agent systems effectively.
Next Steps
- Learn about LLM Integration to understand how agents connect to language models.
- Dive into advanced features like Rate Limiting and Streaming Support for these patterns.