MCPcopy Create free account
hub / github.com/InternScience/InternAgent / AgentFactory

Class AgentFactory

internagent/mas/agents/agent_factory.py:32–198  ·  view source on GitHub ↗

Factory for creating agent instances based on configuration. This factory maintains a registry of available agent types and creates properly configured instances as needed.

Source from the content-addressed store, hash-verified

30
31
32class AgentFactory:
33 """
34 Factory for creating agent instances based on configuration.
35
36 This factory maintains a registry of available agent types
37 and creates properly configured instances as needed.
38 """
39
40 # Registry of agent types
41 _agent_registry: Dict[str, Type[BaseAgent]] = {
42 "generation": GenerationAgent,
43 "reflection": ReflectionAgent,
44 "evolution": EvolutionAgent,
45 "method_development": MethodDevelopmentAgent,
46 "refinement": RefinementAgent,
47 "ranking": RankingAgent,
48 "survey": SurveyAgent,
49 "scholar": ScholarAgent,
50 "dr": DRAgent,
51 'prompt_evolver':PromptGeneratorAgent,
52 'experience':ExperienceAgent
53 }
54
55 # Cache of created agent instances
56 _agent_cache: Dict[str, BaseAgent] = {}
57
58 @classmethod
59 def register_agent_type(cls, agent_type: str, agent_class: Type[BaseAgent]) -> None:
60 """
61 Register a new agent type.
62
63 Args:
64 agent_type: Type identifier for the agent
65 agent_class: Agent class to register
66 """
67 if agent_type in cls._agent_registry:
68 logger.warning(f"Overriding existing agent type: {agent_type}")
69
70 cls._agent_registry[agent_type] = agent_class
71 logger.info(f"Registered agent type: {agent_type}")
72
73 @classmethod
74 def create_agent(cls,
75 agent_type: str,
76 config: Dict[str, Any],
77 model_factory: 'ModelFactory') -> BaseAgent:
78 """
79 Create an agent instance of the specified type.
80
81 Args:
82 agent_type: Type of agent to create
83 config: Configuration for the agent
84 model_factory: ModelFactory instance for creating models
85
86 Returns:
87 Configured agent instance
88
89 Raises:

Callers 3

__init__Method · 0.90
__init__Method · 0.90
__init__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected