Skip to content

Commit

Permalink
Prompt agent to ask questions if it's taking a while
Browse files Browse the repository at this point in the history
  • Loading branch information
roaga committed Nov 2, 2024
1 parent 7c01365 commit 0cf6ab4
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/seer/automation/autofix/autofix_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,22 @@ def should_continue(self, run_config: RunConfig) -> bool:
if self.context.state.get().steps[-1].status == AutofixStatus.WAITING_FOR_USER_RESPONSE:
return False

return super().should_continue(run_config)
if not super().should_continue(run_config):
return False

if (
self.config.interactive
and self.iterations > 0
and (
self.iterations == run_config.max_iterations - 3
or (self.iterations % 6 == 0 and self.iterations < run_config.max_iterations - 3)
)
):
self.add_user_message(
"You're taking a while. If you need help, ask me a concrete question using the tool provided."
)

return True

def run_iteration(self, run_config: RunConfig):
logger.debug(f"----[{self.name}] Running Iteration {self.iterations}----")
Expand Down
33 changes: 33 additions & 0 deletions tests/automation/autofix/test_autofix_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,3 +194,36 @@ def test_share_insights_no_new_insights(autofix_agent):
final_insights_count = len(autofix_agent.context.state.get().steps[-1].insights)

assert initial_insights_count == final_insights_count


def test_should_continue_prompts_for_help(interactive_autofix_agent, run_config):
# Test when iterations is at max_iterations - 3
run_config.max_iterations = 10
interactive_autofix_agent.iterations = 7

with interactive_autofix_agent.context.state.update() as state:
state.steps = [DefaultStep(status=AutofixStatus.PROCESSING, key="test", title="Test")]
state.request.options.disable_interactivity = False

assert interactive_autofix_agent.should_continue(run_config)
assert len(interactive_autofix_agent.memory) == 1
assert interactive_autofix_agent.memory[-1].content == (
"You're taking a while. If you need help, ask me a concrete question using the tool provided."
)

# Test when iterations is divisible by 6
interactive_autofix_agent.memory = []
interactive_autofix_agent.iterations = 6

assert interactive_autofix_agent.should_continue(run_config)
assert len(interactive_autofix_agent.memory) == 1
assert interactive_autofix_agent.memory[-1].content == (
"You're taking a while. If you need help, ask me a concrete question using the tool provided."
)

# Test when iterations is not at a prompt point
interactive_autofix_agent.memory = []
interactive_autofix_agent.iterations = 4

assert interactive_autofix_agent.should_continue(run_config)
assert len(interactive_autofix_agent.memory) == 0

0 comments on commit 0cf6ab4

Please sign in to comment.