Skip to content

Commit

Permalink
Fix disabled thoguhts in few shots in ReAct prompt
Browse files Browse the repository at this point in the history
  • Loading branch information
aorwall committed Jan 27, 2025
1 parent 6114c9c commit 6a85465
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
14 changes: 7 additions & 7 deletions moatless/agent/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
class ActionAgent(BaseModel):
system_prompt: str = Field(..., description="System prompt to be used for generating completions")
use_few_shots: bool = Field(False, description="Whether to use few-shot examples for generating completions")
thoughts_in_action: bool = Field(True, description="")
disable_thoughts: bool = Field(False, description="Whether to disable thoughts in the action")
actions: List[Action] = Field(default_factory=list)
message_generator: MessageHistoryGenerator = Field(
description="Generator for message history",
Expand Down Expand Up @@ -217,8 +217,8 @@ def generate_few_shots(self) -> str:
"InsertLinesArgs",
"FindCodeSnippetArgs",
]:
prompt += f"\nTask: {example.user_input}"
if self.thoughts_in_action:
prompt += f"\nTask: {example.user_input}\n"
if not self.disable_thoughts:
prompt += f"\nThought: {thoughts}\n"
prompt += f"Action: {str(example.action.name)}\n"

Expand Down Expand Up @@ -260,13 +260,13 @@ def generate_few_shots(self) -> str:

elif self.completion.response_format == LLMResponseFormat.TOOLS:
tools_json = {"tool": example.action.name}
if self.thoughts_in_action:
tools_json.update(example.action.model_dump())
else:
if self.disable_thoughts:
tools_json.update(example.action.model_dump(exclude={"thoughts"}))
else:
tools_json.update(example.action.model_dump())

prompt += f"Task: {example.user_input}\n"
if not self.thoughts_in_action:
if not self.disable_thoughts:
prompt += f"<thoughts>{example.action.thoughts}</thoughts>\n"
prompt += json.dumps(tools_json)
prompt += "\n\n"
Expand Down
2 changes: 1 addition & 1 deletion moatless/agent/code_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def create(
system_prompt += REACT_CORE_OPERATION_RULES

elif completion_model.response_format == LLMResponseFormat.TOOLS:
system_prompt += generate_react_guidelines(thoughts_in_action)
system_prompt += generate_react_guidelines(disable_thoughts)
else:
raise ValueError(f"Unsupported response format: {completion_model.response_format}")

Expand Down
4 changes: 2 additions & 2 deletions moatless/agent/code_prompts.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
"""


def generate_react_guidelines(thoughts_in_action: bool = True) -> str:
if not thoughts_in_action:
def generate_react_guidelines(disable_thoughts: bool = False) -> str:
if not disable_thoughts:
return """# Action and ReAct Guidelines
1. **Analysis First**
Expand Down

0 comments on commit 6a85465

Please sign in to comment.