From 4e0b704758150e6cd2a883b03368ba9278621e6d Mon Sep 17 00:00:00 2001 From: jinno Date: Tue, 13 Aug 2024 09:43:53 +0900 Subject: [PATCH] fix: Error in RootListenersTracer.on_chain_end callback: ValueError() --- src/codeinterpreterapi/agents/structured_chat/agent.py | 2 +- .../agents/structured_chat/agent_executor.py | 8 +++++--- src/codeinterpreterapi/agents/tool_calling/agent.py | 2 +- .../agents/tool_calling/agent_executor.py | 8 +++++--- 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/codeinterpreterapi/agents/structured_chat/agent.py b/src/codeinterpreterapi/agents/structured_chat/agent.py index a2273dda..bb12131c 100644 --- a/src/codeinterpreterapi/agents/structured_chat/agent.py +++ b/src/codeinterpreterapi/agents/structured_chat/agent.py @@ -170,9 +170,9 @@ def create_structured_chat_agent( | create_complement_input(prompt) | prompt | llm_with_stop - | output_parser ) agent = assign_runnable_history(agent, runnable_config) + agent = agent | output_parser return agent diff --git a/src/codeinterpreterapi/agents/structured_chat/agent_executor.py b/src/codeinterpreterapi/agents/structured_chat/agent_executor.py index 00ef7c22..1924383f 100644 --- a/src/codeinterpreterapi/agents/structured_chat/agent_executor.py +++ b/src/codeinterpreterapi/agents/structured_chat/agent_executor.py @@ -17,7 +17,7 @@ def load_structured_chat_agent_executor( Load an agent executor(general purpose). """ prompt = create_structured_chat_agent_prompt(ci_params.is_ja) - if agent_def.agent_role is not None: + if agent_def and agent_def.agent_role is not None: prompt = prompt.partial(agent_role=agent_def.agent_role) input_variables = prompt.input_variables if ci_params.verbose_prompt: @@ -31,10 +31,12 @@ def load_structured_chat_agent_executor( runnable_config=ci_params.runnable_config, # stop_sequence=["Observation:", "最終回答", "Final Answer"], ) - agent_def.agent = agent + if agent_def: + agent_def.agent = agent agent_executor = AgentExecutor.from_agent_and_tools(agent=agent, tools=ci_params.tools, verbose=ci_params.verbose) - agent_def.agent_executor = agent_executor + if agent_def: + agent_def.agent_executor = agent_executor return agent_executor diff --git a/src/codeinterpreterapi/agents/tool_calling/agent.py b/src/codeinterpreterapi/agents/tool_calling/agent.py index a9fe4fd3..2be9a45f 100644 --- a/src/codeinterpreterapi/agents/tool_calling/agent.py +++ b/src/codeinterpreterapi/agents/tool_calling/agent.py @@ -105,9 +105,9 @@ def magic_function(input: int) -> int: | create_complement_input(prompt) | prompt | llm_with_tools - | output_parser ) agent = assign_runnable_history(agent, runnable_config) + agent = agent | output_parser return agent diff --git a/src/codeinterpreterapi/agents/tool_calling/agent_executor.py b/src/codeinterpreterapi/agents/tool_calling/agent_executor.py index 0bbd745e..6975435f 100644 --- a/src/codeinterpreterapi/agents/tool_calling/agent_executor.py +++ b/src/codeinterpreterapi/agents/tool_calling/agent_executor.py @@ -17,7 +17,7 @@ def load_tool_calling_agent_executor( Load an agent executor(general purpose). """ prompt = create_tool_calling_agent_prompt(ci_params.is_ja) - if agent_def.message_prompt_template is not None: + if agent_def and agent_def.message_prompt_template is not None: prompt = prompt.partial(agent_role=agent_def.agent_role) if ci_params.verbose_prompt: input_variables = prompt.input_variables @@ -30,10 +30,12 @@ def load_tool_calling_agent_executor( prompt=prompt, runnable_config=ci_params.runnable_config, ) - agent_def.agent = agent + if agent_def: + agent_def.agent = agent agent_executor = AgentExecutor.from_agent_and_tools(agent=agent, tools=ci_params.tools, verbose=ci_params.verbose) - agent_def.agent_executor = agent_executor + if agent_def: + agent_def.agent_executor = agent_executor return agent_executor