Skip to content

feat: implement autonomous agent loop with pause/continue functionality (do not merge)#27

Draft
Aaron ("AJ") Steers (aaronsteers) wants to merge 2 commits intomainfrom
devin/1759807694-agent-pause-continue-loop
Draft

feat: implement autonomous agent loop with pause/continue functionality (do not merge)#27
Aaron ("AJ") Steers (aaronsteers) wants to merge 2 commits intomainfrom
devin/1759807694-agent-pause-continue-loop

Conversation

@aaronsteers
Copy link
Contributor

@aaronsteers Aaron ("AJ") Steers (aaronsteers) commented Oct 7, 2025

Summary

This PR implements autonomous agent functionality for the Agentic Connector Builder WebApp. The agent now continues working on tasks until explicitly paused by the user or until it signals completion using the new report_success or report_failed tools.

Requested by: Aaron ("AJ") Steers (@aaronsteers)
Link to Devin run: https://app.devin.ai/sessions/67b27f0064c744be9f53f4cac20779b2

What's Working ✅

  1. Autonomous Agent Loop - The agent successfully continues working on tasks without requiring user input after each response. You can see this in action in the screenshot below where the agent made multiple "Continue working on the task" iterations automatically.

  2. Conversation History Persistence - Fixed the bug where conversation history wasn't preserved. Converted from simple dict storage to PydanticAI's ModelMessage format (ModelRequest and ModelResponse), ensuring proper context is maintained across interactions.

  3. Report Success/Failed Tools - Added two new tools that the agent can call to signal task completion:

    • report_success(summary) - Agent calls this when task is completed successfully
    • report_failed(reason) - Agent calls this when task cannot be completed
  4. Pause/Continue UI Button - Added a dynamic button to the chat sidebar that shows "⏸ Pause" when agent is running and "▶️ Continue" when paused.

  5. Auto-unpause on New Message - Typing a new message automatically unpauses the agent and starts the autonomous loop.

Known Issues ⚠️

CRITICAL: Pause button doesn't work - While the pause button renders correctly in the UI and has the correct event handler wired up, clicking it does not actually pause the running agent. The agent continues making autonomous iterations even after the button is clicked multiple times.

Root Cause: This appears to be a state synchronization issue with Reflex's handling of concurrent async generators. The _run_autonomous_loop() is a long-running async generator that checks self.agent_paused, but state updates from the toggle_pause() event handler don't appear to be immediately visible to the running loop.

Screenshots

The autonomous loop working (agent made multiple iterations without user intervention):

Autonomous Loop Running

Implementation Details

Files Changed

  1. agentic_connector_builder_webapp.py (+135 -33)

    • Converted chat_messages from list[dict] to list[ModelMessage]
    • Added display_messages computed var to convert ModelMessage to UI format
    • Added state vars: agent_paused, agent_running, agent_should_stop
    • Implemented _run_autonomous_loop() async generator
    • Modified send_message() to start autonomous loop
    • Added toggle_pause() event handler
  2. chat_agent.py (+28 -0)

    • Added report_success() tool
    • Added report_failed() tool
    • Updated system prompt to mention new tools
  3. components/chat_sidebar.py (+18 -5)

    • Added pause/continue button with conditional rendering
    • Button shows "⏸ Pause" when running, "▶️ Continue" when paused
    • Color scheme changes (orange for pause, green for continue)

Message Format Conversion

  • User messages: ModelRequest with UserPromptPart
  • Assistant messages: ModelResponse with TextPart
  • Properly timestamps all messages with datetime.now(tz=UTC)

Autonomous Loop Logic

The agent continues in a while not self.agent_paused and not self.agent_should_stop loop:

  1. First iteration: Uses the original user message as prompt
  2. Subsequent iterations: Uses "Continue working on the task." as continuation prompt
  3. Passes full message_history to maintain context
  4. Stops when: agent calls report_success/report_failed, encounters error, or user pauses

Next Steps

To fix the pause button issue, we likely need to:

  1. Investigate Reflex's state synchronization with long-running async generators
  2. Consider alternative approaches like using a separate background task or event-based cancellation
  3. Test with Reflex's latest version or consult their documentation on handling concurrent state updates

Testing

Tested locally by:

  • Sending initial message and verifying agent continues autonomously ✅
  • Observing multiple "Continue working on the task" iterations without user input ✅
  • Verifying conversation history is maintained across iterations ✅
  • Attempting to click pause button (button renders but doesn't pause) ❌
  • Typing new message while agent running (successfully unpauses) ✅

- Fix conversation history bug by using PydanticAI ModelMessage format
- Add pause/continue button to chat sidebar UI
- Implement autonomous agent loop that continues until paused or stopped
- Add report_success and report_failed tools for agent to signal completion
- Typing new message automatically unpauses the agent

Known issue: Pause button renders but doesn't actually pause the agent due to
state synchronization challenges with Reflex async generators.

Co-Authored-By: AJ Steers <aj@airbyte.io>
@devin-ai-integration
Copy link
Contributor

Original prompt from AJ Steers
@Devin - In the agentic connector builder webapp repo, create a loop for the agent to continue until the user pushes a (new) ":double_vertical_bar: Pause" button. The agent can also pause itself if it calls one of two new tools "report_success" or "report_failed". When paused, the button toggles to a ":black_right_pointing_triangle_with_double_vertical_bar: Continue" button. Typing a new message to the chatbot also unpauses it.

Note: The current implementation has a bug where it doesn't remember previous messages in the conversation thread. You may need to fix that also.
Thread URL: https://airbytehq-team.slack.com/archives/D089P0UPVT4/p1759806841987619?thread_ts=1759806841.987619

@devin-ai-integration
Copy link
Contributor

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 9, 2025

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch devin/1759807694-agent-pause-continue-loop

Comment @coderabbitai help to get the list of available commands and usage tips.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant