Skip to content

Conversation

@phenric26
Copy link

This PR addresses the blocking I/O issue in the CLI where users could not provide input while the agent was in the RUNNING state. It refactors the execution loop to support concurrency, allowing real-time feedback and interruptions without needing explicit pause commands.

Key Changes:

Non-blocking Input: Introduced InputManager in openhands_cli/tui.py using prompt_toolkit's async interface.

Concurrent Event Loop: Refactored ConversationRunner.run_concurrent_loop in openhands_cli/runner.py. It now uses asyncio.wait with FIRST_COMPLETED strategy to handle the race condition between user input and agent execution steps.

Safe Execution Wrapper: Added _step_agent_safe to offload synchronous agent steps to an executor, ensuring the main thread remains responsive.

Test Plan (TDD):

This feature was implemented using Test Driven Development (TDD). A comprehensive suite of unit tests was added to cover the concurrency logic:

tests/test_concurrency_flow.py:

    test_input_manager_reads_async: Verifies non-blocking read.

    test_concurrent_loop_exit: Ensures /exit command terminates the loop immediately.

    test_input_interrupts_agent: Validates that user input is processed and sent to the conversation even if the agent is busy.

Related Issue: Fixes #103

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.

[Enhancement] [CLI] Cannot type/queue prompts during actions (unlike other AI tools)

1 participant