-
Notifications
You must be signed in to change notification settings - Fork 0
/
agent_factory.py
43 lines (36 loc) · 1.64 KB
/
agent_factory.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# agent_factory.py
# This module implements the Factory pattern for creating different types of AI agents.
# It provides a centralized way to instantiate specialized agents based on task requirements.
from typing import Dict, Any, Optional
from agents.base_agent import BaseAgent
from agents.research_agent import ResearchAgent
from agents.writing_agent import WritingAgent
from agents.analysis_agent import AnalysisAgent
from utils import TaskContext
class AgentFactory:
"""Factory class for creating specialized agents"""
@staticmethod
def create_agent(agent_type: str, parameters: Dict[str, Any]) -> Optional[BaseAgent]:
"""
Create a new agent based on the specified type and parameters
Args:
agent_type: Type of agent to create (research, writing, analysis)
parameters: Configuration parameters for the agent
Returns:
BaseAgent: An instance of the specified agent type
"""
# Create a task context with the provided parameters
context = TaskContext(agent_type, parameters)
# Return the appropriate agent type based on the request
if agent_type == "research":
return ResearchAgent(context)
elif agent_type == "writing":
return WritingAgent(context)
elif agent_type == "analysis":
return AnalysisAgent(context)
else:
raise ValueError(f"Unknown agent type: {agent_type}")
@staticmethod
def get_available_agent_types() -> list:
"""Get a list of available agent types"""
return ["research", "writing", "analysis"]