Skip to content

Commit

Permalink
Merge branch 'Pingdred-tools_refine' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
pieroit committed Jul 31, 2023
2 parents 9530c2f + 46f0c72 commit 26d6ba1
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
28 changes: 19 additions & 9 deletions core/cat/looking_glass/agent_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ def execute_memory_chain(self, agent_input, prompt_prefix, prompt_suffix):
"chat_history",
"episodic_memory",
"declarative_memory",
"tools_output"
]
)

Expand All @@ -85,6 +86,7 @@ def execute_memory_chain(self, agent_input, prompt_prefix, prompt_suffix):

out = memory_chain(agent_input)
out["output"] = out["text"]
del out["text"]
return out


Expand Down Expand Up @@ -122,22 +124,30 @@ def execute_agent(self, agent_input):
# " ".join([prompt_prefix, prompt_format_instructions, prompt_suffix]))


# Try to reply only with tools
# Try to get information from tools if there is some allowed
allowed_tools = mad_hatter.execute_hook("agent_allowed_tools")
tools_are_enough = False
tools_result = None
if len(allowed_tools) > 0:
try:
out = self.execute_tool_agent(agent_input, allowed_tools)
tools_are_enough = out["output"] != None
tools_result = self.execute_tool_agent(agent_input, allowed_tools)
except Exception as e:
error_description = str(e)
log(error_description, "ERROR")
tools_are_enough = False
log(error_description, "ERROR")

# if tools were not enough, use memory # TODO: refine tool output?
if not tools_are_enough:
#Adding the tools_output key in agent input, needed by the memory chain
if tools_result != None:
# If tools_result["output"] is None the LLM has used the fake tool none_of_the_others
# so no relevant information has been obtained from the tools.
agent_input["tools_output"] = "## Tools output: \n" + tools_result["output"] if tools_result["output"] else ""

# Execute the memory chain
out = self.execute_memory_chain(agent_input, prompt_prefix, prompt_suffix)

# If some tools are used the intermediate step are added to the agent output
out["intermediate_steps"] = list(map(lambda x:((x[0].tool, x[0].tool_input), x[1]), tools_result["intermediate_steps"]))
else:
out["intermediate_steps"] = list(map(lambda x:((x[0].tool, x[0].tool_input), x[1]), out["intermediate_steps"]))
agent_input["tools_output"] = ""
# Execute the memory chain
out = self.execute_memory_chain(agent_input, prompt_prefix, prompt_suffix)

return out
2 changes: 2 additions & 0 deletions core/cat/mad_hatter/core_plugin/hooks/prompt.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ def agent_prompt_suffix(cat) -> str:
{declarative_memory}
{tools_output}
## Conversation until now:{chat_history}
- Human: {input}
- AI: """
Expand Down

0 comments on commit 26d6ba1

Please sign in to comment.