agent manager clean up

Former-commit-id: ceef4c9a39591b6e2a178c9a857712ddb9f84d4b
pull/160/head
Kye 2 years ago
parent c3828eb73f
commit 3832e249a2

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

Loading…
Cancel
Save