Skip to content

Commit d01ee8e

Browse files
committed
Add action picker critic
Force to critic the action before actually chosing
1 parent d08a097 commit d01ee8e

File tree

1 file changed

+22
-6
lines changed

1 file changed

+22
-6
lines changed

src/localagi/localagi.py

+22-6
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ def needs_to_do_action(self, user_input, agent_actions={}):
124124
{descriptions}"""},
125125
{"role": "user",
126126
"content": f"""{user_input}
127-
Function call: """
127+
Function call: """
128128
}
129129
]
130130
functions = [
@@ -202,7 +202,7 @@ def process_functions(self, user_input, action="",):
202202
{descriptions}"""},
203203
{"role": "user",
204204
"content": f"""{user_input}
205-
Function call: """
205+
Function call: """
206206
}
207207
]
208208
response = self.function_completion(messages, action=action)
@@ -314,9 +314,9 @@ def analyze(self, responses, prefix="Analyze the following text highlighting the
314314
"role": "user",
315315
"content": f"""{prefix}:
316316
317-
```
318-
{string}
319-
```
317+
```
318+
{string}
319+
```
320320
""",
321321
}
322322
]
@@ -478,7 +478,23 @@ def evaluate(self,user_input, conversation_history = [], critic=True, re_evaluat
478478
action_picker_message+="\n\nObservation: "+observation
479479
# if there is no action to do, we can just reply to the user with REPLY_ACTION
480480
try:
481-
action = self.needs_to_do_action(action_picker_message,agent_actions=picker_actions)
481+
critic_msg=""
482+
if critic:
483+
descriptions=self.action_description("", self.agent_actions)
484+
485+
messages = [
486+
{"role": "user",
487+
"content": f"""Transcript of AI assistant responding to user requests. Replies with the action to perform and the reasoning.
488+
{descriptions}"""},
489+
{"role": "user",
490+
"content": f"""
491+
This is the user input: {user_input}
492+
Decide now the function to call and give a detailed explaination"""
493+
}
494+
]
495+
critic_msg=self.analyze(messages, prefix="", suffix=f"")
496+
logger.info("==> Critic: {critic}", critic=critic_msg)
497+
action = self.needs_to_do_action(action_picker_message+"\n"+critic_msg,agent_actions=picker_actions)
482498
except Exception as e:
483499
logger.error("==> error: ")
484500
logger.error(e)

0 commit comments

Comments
 (0)