validation executor

Former-commit-id: 06d842bc61670c132787749c80ba5812edb07250
pull/160/head
Kye 2 years ago
parent 4358f1a152
commit da4e6e0acd

@ -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):

Loading…
Cancel
Save