diff --git a/swarms/agents/utils/AgentManager.py b/swarms/agents/utils/AgentManager.py index 34e87c79..6e44b9a7 100644 --- a/swarms/agents/utils/AgentManager.py +++ b/swarms/agents/utils/AgentManager.py @@ -41,6 +41,9 @@ class AgentManager: builder = AgentBuilder(self.toolsets) builder.build_parser() + agent = builder.get_agent() + if not agent: + raise ValueError("Agent not created") callbacks = [] eval_callback = EVALCallbackHandler() @@ -52,19 +55,12 @@ class AgentManager: execution_callback.set_parser(builder.get_parser()) callbacks.append(execution_callback) - #llm init callback_manager = CallbackManager(callbacks) + builder.build_llm(callback_manager, openai_api_key) - if builder.llm is None: - raise ValueError('LLM not created') builder.build_global_tools() - #agent init - agent = builder.get_agent() - if not agent: - raise ValueError("Agent not created") - memory: BaseChatMemory = self.get_or_create_memory(session) tools = [ *builder.get_global_tools(), @@ -77,22 +73,18 @@ class AgentManager: for tool in tools: tool.callback_manager = callback_manager - executor = AgentExecutor.from_agent_and_tools( - agent=agent, - tools=tools, - memory=memory, - callback_manager=callback_manager, - verbose=True, - ) - if 'agent' not in executor.__dict__: - executor.__dict__['agent'] = agent - self.executors[session] = executor + # Ensure the 'agent' key is present in the values dictionary + values = {'agent': agent, 'tools': tools} + executor = AgentExecutor.from_agent_and_tools(**values) + + self.executors[session] = executor return executor except Exception as e: logging.error(f"Error while creating executor: {str(e)}") raise e + @staticmethod def create(toolsets: list[BaseToolSet]) -> "AgentManager": if not isinstance(toolsets, list):