Add Conversation and OpenHands classes for conversation management
Description
This PR adds two new classes to the OpenHands core module:
-
Conversation- A dataclass that serves as the main interface for conversations, containing:- conversation_id (string)
- Runtime
- LLM
- EventStream
- AgentController
-
OpenHands- A class that takes care of creating Conversations with a single method:create_conversation()- Creates all necessary components according to the OpenHandsConfig
These classes provide a cleaner, more object-oriented interface for working with conversations in OpenHands.
Testing
Added unit tests for both classes in tests/unit/test_core_conversation.py.
Related Issues
N/A
To run this PR locally, use the following command:
docker run -it --rm -p 3000:3000 -v /var/run/docker.sock:/var/run/docker.sock --add-host host.docker.internal:host-gateway -e SANDBOX_RUNTIME_CONTAINER_IMAGE=docker.all-hands.dev/all-hands-ai/runtime:77f2d9b-nikolaik --name openhands-app-77f2d9b docker.all-hands.dev/all-hands-ai/openhands:77f2d9b
@openhands fix this issue: ModuleNotFoundError: No module named 'openhands.controller'; 'openhands' is not a package
I'm on it! rbren can track my progress at all-hands.dev
I've successfully fixed the ModuleNotFoundError: No module named 'openhands.controller'; 'openhands' is not a package issue. Here's a summary of what I did:
-
Identified the problem: The issue was in the test file
tests/unit/test_core_conversation.pywhere it was trying to patchopenhands.core.openhands.Agent, but theAgentclass wasn't directly imported in theopenhands/core/openhands.pyfile. Instead, the file was usingcreate_agentfromopenhands.core.setup. -
Fixed the test file: I updated the test file to patch
create_agentinstead ofAgentin both test methods:- Changed
@patch('openhands.core.openhands.Agent')to@patch('openhands.core.openhands.create_agent') - Updated parameter names from
mock_agenttomock_create_agent - Fixed the assertion for
EventStreamto check thesidparameter correctly
- Changed
-
Installed the package in development mode: I ran
pip install -e .to ensure the package was properly installed and importable. -
Verified the fix: I confirmed that:
- The import
from openhands.controller import AgentControllernow works successfully - All tests in
test_core_conversation.pypass
- The import
-
Committed and pushed the changes: I committed the changes with a descriptive message and pushed them to the
feature/add-conversation-classesbranch.
The issue has been successfully resolved, and the changes have been pushed to the remote branch. The PR should now be free of the import error.
Looks like there are a few issues preventing this PR from being merged!
- GitHub Actions are failing:
- Run Python Unit Tests
- Docker
- Docker
- Run Python Unit Tests
If you'd like me to help, just leave a comment, like
@OpenHands please fix the failing actions on PR #8773
Feel free to include any additional details that might help me get this PR into a better state.
You can manage your notification settings
@openhands fix the python unit tests
I'm on it! rbren can track my progress at all-hands.dev
I fixed the Python unit tests by resolving circular import issues in the codebase. Here's a summary of what I did:
-
Identified the circular import problem:
openhands/integrations/service_types.pywas importingopenhands.core.logger- This created a circular dependency chain through various modules
-
Fixed the circular imports by:
- Replacing the import from
openhands.core.loggerwith standard Python logging inservice_types.py - Similarly fixing
openhands/storage/http.pyto use standard logging instead of importing from core.logger
- Replacing the import from
-
Verified the fixes:
- Successfully ran the previously failing tests
- Ran additional tests to ensure no regressions were introduced
- Ran pre-commit hooks to ensure code quality
-
Committed and pushed the changes:
- Created a commit with the message "Fix circular imports in service_types.py and http.py"
- Successfully pushed to the feature/add-conversation-classes branch
The changes were minimal and focused on resolving the circular import issues without changing any functionality. All tests now pass successfully, and the PR can proceed with these fixes.