From 3832e249a278a5f78acd3a5d3c0400230c11e078 Mon Sep 17 00:00:00 2001 From: Kye Date: Sun, 16 Jul 2023 16:00:47 -0400 Subject: [PATCH] agent manager clean up Former-commit-id: ceef4c9a39591b6e2a178c9a857712ddb9f84d4b --- swarms/agents/utils/AgentManager.py | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/swarms/agents/utils/AgentManager.py b/swarms/agents/utils/AgentManager.py index caa262a2..c77df285 100644 --- a/swarms/agents/utils/AgentManager.py +++ b/swarms/agents/utils/AgentManager.py @@ -41,6 +41,7 @@ class AgentManager: builder = AgentBuilder(self.toolsets) builder.build_parser() + callbacks = [] eval_callback = EVALCallbackHandler() eval_callback.set_parser(builder.get_parser()) @@ -51,16 +52,16 @@ 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") @@ -76,19 +77,19 @@ class AgentManager: for tool in tools: tool.callback_manager = callback_manager - executor_args = { - 'agent': agent, - 'tools': tools, - 'memory': memory, - 'callback_manager': callback_manager, - 'verbose': True - } - - executor = AgentExecutor.from_agent_and_tools(**executor_args) + # Ensure the 'agent' key is present in the values dictionary + # values = {'agent': agent, 'tools': tools} - if not hasattr(executor, 'agent'): - raise ValueError("Executor does not have an 'agent' attribute") + 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 return executor