Skip to content

Commit

Permalink
First tools early stop
Browse files Browse the repository at this point in the history
  • Loading branch information
Bobholamovic committed Jan 30, 2024
1 parent 23917c0 commit 8c0ea11
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion erniebot-agent/src/erniebot_agent/agents/function_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ async def _run(self, prompt: str, files: Optional[Sequence[File]] = None) -> Age
else:
# If tool choice did not work, issue a warning and try next one.
_logger.warning("The selected tool %r was not called.", tool.tool_name)
break

curr_iter = 0
while True:
Expand Down Expand Up @@ -195,9 +196,17 @@ async def _take_next_steps(
else:
llm_resp = await self.run_llm(messages=input_messages)

output_message = llm_resp.message

if selected_tool is not None:
if not (
output_message.function_call is not None
and output_message.function_call["name"] == selected_tool.tool_name
):
return [], []

new_steps: List[Union[AgentStep, AgentRunEnd]] = []
new_messages: List[Message] = []
output_message = llm_resp.message # AIMessage
new_messages.append(output_message)
if output_message.function_call is not None:
tool_name = output_message.function_call["name"]
Expand Down

0 comments on commit 8c0ea11

Please sign in to comment.