OpenHands icon indicating copy to clipboard operation
OpenHands copied to clipboard

Add Conversation and OpenHands classes for conversation management

Open rbren opened this issue 6 months ago • 7 comments

Description

This PR adds two new classes to the OpenHands core module:

  1. Conversation - A dataclass that serves as the main interface for conversations, containing:

    • conversation_id (string)
    • Runtime
    • LLM
    • EventStream
    • AgentController
  2. 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

rbren avatar May 28 '25 21:05 rbren

@openhands fix this issue: ModuleNotFoundError: No module named 'openhands.controller'; 'openhands' is not a package

rbren avatar May 28 '25 23:05 rbren

I'm on it! rbren can track my progress at all-hands.dev

openhands-ai[bot] avatar May 28 '25 23:05 openhands-ai[bot]

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:

  1. Identified the problem: The issue was in the test file tests/unit/test_core_conversation.py where it was trying to patch openhands.core.openhands.Agent, but the Agent class wasn't directly imported in the openhands/core/openhands.py file. Instead, the file was using create_agent from openhands.core.setup.

  2. Fixed the test file: I updated the test file to patch create_agent instead of Agent in both test methods:

    • Changed @patch('openhands.core.openhands.Agent') to @patch('openhands.core.openhands.create_agent')
    • Updated parameter names from mock_agent to mock_create_agent
    • Fixed the assertion for EventStream to check the sid parameter correctly
  3. Installed the package in development mode: I ran pip install -e . to ensure the package was properly installed and importable.

  4. Verified the fix: I confirmed that:

    • The import from openhands.controller import AgentController now works successfully
    • All tests in test_core_conversation.py pass
  5. Committed and pushed the changes: I committed the changes with a descriptive message and pushed them to the feature/add-conversation-classes branch.

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.

openhands-ai[bot] avatar May 28 '25 23:05 openhands-ai[bot]

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-ai[bot] avatar May 30 '25 17:05 openhands-ai[bot]

@openhands fix the python unit tests

rbren avatar Jun 10 '25 15:06 rbren

I'm on it! rbren can track my progress at all-hands.dev

openhands-ai[bot] avatar Jun 10 '25 15:06 openhands-ai[bot]

I fixed the Python unit tests by resolving circular import issues in the codebase. Here's a summary of what I did:

  1. Identified the circular import problem:

    • openhands/integrations/service_types.py was importing openhands.core.logger
    • This created a circular dependency chain through various modules
  2. Fixed the circular imports by:

    • Replacing the import from openhands.core.logger with standard Python logging in service_types.py
    • Similarly fixing openhands/storage/http.py to use standard logging instead of importing from core.logger
  3. 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
  4. 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.

openhands-ai[bot] avatar Jun 10 '25 15:06 openhands-ai[bot]