From da4e6e0acd10c18ae9f5f9ff6cad2a0920dcc684 Mon Sep 17 00:00:00 2001 From: Kye Date: Thu, 13 Jul 2023 14:03:28 -0400 Subject: [PATCH] validation executor Former-commit-id: 06d842bc61670c132787749c80ba5812edb07250 --- swarms/agents/utils/AgentManager.py | 43 ++++++++++++++++++++++------- 1 file changed, 33 insertions(+), 10 deletions(-) diff --git a/swarms/agents/utils/AgentManager.py b/swarms/agents/utils/AgentManager.py index 6e44b9a7..e392cfee 100644 --- a/swarms/agents/utils/AgentManager.py +++ b/swarms/agents/utils/AgentManager.py @@ -41,9 +41,6 @@ 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() @@ -55,12 +52,19 @@ 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(), @@ -73,18 +77,37 @@ class AgentManager: for tool in tools: tool.callback_manager = callback_manager - # Ensure the 'agent' key is present in the values dictionary - values = {'agent': agent, 'tools': tools} - - executor = AgentExecutor.from_agent_and_tools(**values) - + # # Ensure the 'agent' key is present in the values dictionary + # values = {'agent': agent, 'tools': tools} + + # executor = AgentExecutor.from_agent_and_tools( + # agent=agent, + # tools=tools, + # memory=memory, + # callback_manager=callback_manager, + # verbose=True, + # ) + + # Prepare the arguments for the executor + executor_args = { + 'agent': agent, + 'tools': tools, + 'memory': memory, + 'callback_manager': callback_manager, + 'verbose': True # Or any other value based on your requirement + } + + executor = AgentExecutor.from_agent_and_tools(**executor_args) + + if 'agent' not in executor.__dict__: + executor.__dict__['agent'] = agent 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):