feat: implement autonomous agent loop with pause/continue functionality (do not merge)#27
Draft
Aaron ("AJ") Steers (aaronsteers) wants to merge 2 commits intomainfrom
Draft
Conversation
- 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>
Contributor
Original prompt from AJ Steers |
Contributor
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
⚙️ Control Options:
|
Contributor
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the ✨ Finishing touches🧪 Generate unit tests (beta)
Comment |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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_successorreport_failedtools.Requested by: Aaron ("AJ") Steers (@aaronsteers)
Link to Devin run: https://app.devin.ai/sessions/67b27f0064c744be9f53f4cac20779b2
What's Working ✅
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.
Conversation History Persistence - Fixed the bug where conversation history wasn't preserved. Converted from simple
dictstorage to PydanticAI'sModelMessageformat (ModelRequestandModelResponse), ensuring proper context is maintained across interactions.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 successfullyreport_failed(reason)- Agent calls this when task cannot be completedPause/Continue UI Button - Added a dynamic button to the chat sidebar that shows "⏸ Pause" when agent is running and "▶️ Continue" when paused.
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 checksself.agent_paused, but state updates from thetoggle_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):
Implementation Details
Files Changed
agentic_connector_builder_webapp.py (+135 -33)
chat_messagesfromlist[dict]tolist[ModelMessage]display_messagescomputed var to convert ModelMessage to UI formatagent_paused,agent_running,agent_should_stop_run_autonomous_loop()async generatorsend_message()to start autonomous looptoggle_pause()event handlerchat_agent.py (+28 -0)
report_success()toolreport_failed()toolcomponents/chat_sidebar.py (+18 -5)
Message Format Conversion
ModelRequestwithUserPromptPartModelResponsewithTextPartdatetime.now(tz=UTC)Autonomous Loop Logic
The agent continues in a
while not self.agent_paused and not self.agent_should_stoploop:message_historyto maintain contextNext Steps
To fix the pause button issue, we likely need to:
Testing
Tested locally by: