Skip to content

Update agent-sdk version and import paths#26

Merged
malhotra5 merged 9 commits intomainfrom
openhands/update-agent-sdk-version
Sep 3, 2025
Merged

Update agent-sdk version and import paths#26
malhotra5 merged 9 commits intomainfrom
openhands/update-agent-sdk-version

Conversation

@malhotra5
Copy link
Collaborator

Summary

This PR updates the agent-sdk dependency to the latest version and fixes the import paths as requested in issue #25.

Changes Made

  • Updated agent-sdk SHA: Changed from 288e440b344c67c66e2093215521a1394b1509b6 to ab8980714dd397f26fe811227afbc533c59fae70 (latest commit on main branch)
  • Updated subdirectory path: Changed from openhands/core to openhands/sdk to match the new repository structure
  • Updated import paths:
    • Changed from openhands.core.* imports to from openhands.sdk.*
    • Updated tools imports to use the new structure
    • Replaced CodeActAgent with Agent class
  • Updated lock file: Refreshed uv.lock with the new dependencies
  • Added pytest dependency: Added missing pytest dependency to dev dependencies

Testing

  • ✅ All existing tests pass (11/11)
  • ✅ Linting passes with no issues
  • ✅ Import paths work correctly with the new agent-sdk structure

Verification

The changes ensure compatibility with the latest agent-sdk version while maintaining all existing functionality. The import structure now matches the example provided in the agent-sdk repository.

Fixes #25

@malhotra5 can click here to continue refining the PR

- Update agent-sdk SHA to latest commit (ab8980714dd397f26fe811227afbc533c59fae70)
- Change subdirectory from openhands/core to openhands/sdk
- Update import paths from openhands.core.* to openhands.sdk.*
- Replace CodeActAgent with Agent class
- Update lock file with new dependencies
- All tests passing

Fixes #25

Co-authored-by: openhands <openhands@all-hands.dev>
@openhands-ai openhands-ai bot mentioned this pull request Sep 3, 2025
@malhotra5
Copy link
Collaborator Author

@OpenHands notice that the build and test binary logs are showing the error Error setting up agent: Prompt file /tmp/_MEIvkX3t5/openhands/sdk/agent/agent/prompts/system_prompt.j2 not found

We should do the following

  1. catch this in our GitHub CI when attempting to run the binary; successfully starting the CLI should open a session with no errors. Maybe in the code instead of throwing an exception and returning normally, return an error code instead.

  2. you'll need to update the PyInstaller specs with the new import paths for the agent-sdk library; look at the poetry file to see the changes made to it on this pr

@openhands-ai
Copy link

openhands-ai bot commented Sep 3, 2025

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

🔴 Solvability: HARD

This is a complex build system issue involving PyInstaller binary packaging where a system prompt file cannot be found, requiring updates to build specifications and CI integration. The issue involves multiple interconnected components including the agent SDK, build configuration, and deployment pipeline, making it challenging to resolve.

You can make the issue easier to resolve by addressing these concerns in the conversation:

• Provide step-by-step instructions for reproducing the build failure locally to help developers test their fixes
• Include the current PyInstaller configuration files and specify exactly which import paths need to be updated
• Share the specific poetry file changes mentioned so developers can see what modifications are required

- Update PyInstaller spec to use new agent-sdk import paths (openhands.sdk instead of openhands.core)
- Fix missing prompt file error by updating data collection paths
- Improve error handling to return proper exit codes instead of exceptions
- Update CI to properly test binary startup and catch errors
- Add comprehensive binary testing for missing API keys and prompt files
- Update tests to match new return code behavior

Fixes the 'Prompt file system_prompt.j2 not found' error in binary builds.
@openhands-ai
Copy link

openhands-ai bot commented Sep 3, 2025

I have successfully fixed the binary build error and implemented all requested improvements:

Issues Resolved:

  1. Fixed "system_prompt.j2 not found" error: Updated PyInstaller spec to use correct agent-sdk paths (openhands.sdk instead of openhands.core)

  2. Improved error handling: Functions now return proper exit codes instead of throwing exceptions:

    • 0: Success
    • 1: Missing API key
    • 2: Agent setup error
    • 3: Unexpected error
  3. Enhanced GitHub CI: Added comprehensive binary testing that:

    • Tests graceful failure without API key
    • Detects missing prompt file errors
    • Prevents similar issues in future builds
  4. Updated PyInstaller configuration: Aligned with new agent-sdk import structure

Verification Results:

  • ✅ Binary builds successfully (42.8 MB)
  • ✅ No more prompt file errors
  • ✅ Proper exit codes returned
  • ✅ All 11 tests pass
  • ✅ Linting passes

The binary now starts cleanly and the CI will catch any similar issues automatically. Changes have been committed and pushed to PR #26.

View full conversation

- Created AgentSetupError exception class with exit_code attribute
- Modified setup_agent() to raise AgentSetupError instead of returning exit codes
- Updated run_agent_chat() to catch AgentSetupError and return appropriate exit code
- This allows GitHub CI to properly catch and handle setup failures

Co-authored-by: openhands <openhands@all-hands.dev>
@malhotra5
Copy link
Collaborator Author

@OpenHands please rework the agent chat and CI

we want to build and test the executable binary but we don't want to rely so heavily on returning exact exit codes in the program, it's very messy

in the actual program, raise errors and exit the application normally

in the CI, look for specific message outputs. Note that when the executable is running, it is long lived. It won't exit without an interrupt or /exit command, so take that into consideration when designing the CI/test.

@openhands-ai
Copy link

openhands-ai bot commented Sep 3, 2025

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

🔴 Solvability: HARD

This is a complex architectural refactoring request that involves reworking multiple system components including agent chat functionality, CI/CD pipeline, and executable binary testing strategies. The issue lacks concrete technical details, specific error scenarios, and clear implementation guidance, making it challenging to resolve without significant additional context.

You can make the issue easier to resolve by addressing these concerns in the conversation:

• Provide specific examples of the current "messy" exit code behavior and which exact exit codes are problematic
• Include concrete examples of the specific message outputs that the CI should look for during testing
• Describe the current agent chat implementation and specify which aspects need to be reworked

- Remove exit code dependencies from agent_chat.py and simple_main.py
- Functions now raise exceptions and exit normally with sys.exit()
- Update CI to test message outputs for long-lived process behavior
- Add comprehensive CI tests for interactive commands (/help, /status, /exit)
- Update unit tests to expect SystemExit exceptions instead of return codes
- Improve error handling to be more natural and maintainable

Co-authored-by: openhands <openhands@all-hands.dev>
@openhands-ai
Copy link

openhands-ai bot commented Sep 3, 2025

Summary

I have successfully reworked the agent chat and CI system as requested. Here's what was accomplished:

Request Fulfillment Checklist:

  1. Removed exit code dependencies from the program

    • Eliminated exit_code parameter from AgentSetupError class
    • Changed functions to return None instead of int exit codes
    • Replaced return-based error handling with normal exception raising and sys.exit()
  2. Updated program to raise errors and exit normally

    • Functions now raise exceptions naturally instead of returning error codes
    • Use sys.exit(1) for error conditions in main entry points
    • Maintained clear error messages for users while simplifying the code flow
  3. Updated CI to test message outputs instead of exit codes

    • No API key test: Checks for "No API key found" message in output
    • Successful startup test: Looks for "Let's start building!" or "OpenHands CLI" messages
    • Interactive commands test: Verifies /help, /status, and /exit commands work correctly
  4. Handled long-lived process behavior in CI

    • CI now sends /exit command to gracefully terminate the long-lived process
    • Uses timeout with appropriate durations (30s) to prevent hanging
    • Tests multiple scenarios: startup without API key, startup with dummy key, and interactive commands
  5. Updated unit tests accordingly

    • Tests now expect SystemExit exceptions instead of return codes
    • Proper use of pytest.raises(SystemExit) for error conditions
    • Maintained test coverage while adapting to new error handling approach

Key Improvements:

  • Cleaner code: Removed messy exit code logic throughout the application
  • Better error handling: More natural exception flow with proper logging
  • Comprehensive CI testing: Tests actual user-facing behavior and messages
  • Long-lived process support: CI properly handles the interactive nature of the CLI

Testing Results:

  • ✅ All unit tests pass (11/11)
  • ✅ Linting passes with no issues
  • ✅ Binary builds successfully
  • ✅ Manual testing confirms proper message outputs and graceful exit behavior

The changes have been committed and pushed to the openhands/update-agent-sdk-version branch, updating the existing PR #26.

View full conversation

- Remove complex error checking and multiple test jobs
- Use single test job with LITELLM_API_KEY and LITELLM_MODEL already exported
- Test /status, /help, and /exit commands in sequence
- Simply display output without explicit validation checks
- Cleaner and more maintainable CI approach

Co-authored-by: openhands <openhands@all-hands.dev>
@malhotra5
Copy link
Collaborator Author

@OpenHands lets simplify the build and CI tests

make sure that application starts, we can send the /help command, and we verify the output that's expected from the command

remove any other complexity in the testing phase

@openhands-ai
Copy link

openhands-ai bot commented Sep 3, 2025

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

🟡 Solvability: MEDIUM

This is a medium-complexity task requesting simplification of build and CI testing processes with clear expectations for application startup and command verification. The issue benefits from straightforward language and well-defined success criteria, though it involves coordinating changes across multiple system components.

You can make the issue easier to resolve by addressing these concerns in the conversation:

• Provide more specific details about the current build and CI setup to better understand what complexity needs to be removed
• Include information about the current testing environment and any specific tools or frameworks being used
• Clarify what constitutes "expected output" from the /help command to ensure proper verification criteria

Positive feedback:

• The request uses clear, simple language that makes the desired outcome easy to understand
• Expected behavior is well-defined with specific verification steps (application starts, /help command works, output verification)
• The task doesn't require deep technical implementation knowledge, making it more accessible

- Focus CI on core functionality: app startup and /help command
- Remove complex exit code testing and error handling verification
- Simplify build.py test_executable() to test /help command output
- Update CI workflow to verify expected help output content
- Maintain all existing functionality while reducing test complexity

Co-authored-by: openhands <openhands@all-hands.dev>
@openhands-ai
Copy link

openhands-ai bot commented Sep 3, 2025

Summary

I have successfully simplified the build and CI tests as requested. Here's what was accomplished:

Request Fulfillment Checklist:

  1. ✅ Simplified build and CI tests - Removed complex exit code testing and error handling verification
  2. ✅ Application startup verification - CI now tests that the binary starts successfully with dummy API credentials
  3. /help command functionality - CI sends /help command and verifies it works correctly
  4. ✅ Expected output verification - CI checks for specific content:
    • "🤖 OpenHands CLI Help" (help title)
    • "Available commands:" (commands section)
    • "/exit - Exit the application" (specific command example)
  5. ✅ Removed testing complexity - Eliminated complex two-phase testing, API key error handling, and prompt file checks

Key Changes Made:

CI Workflow (.github/workflows/build-test.yml):

  • Simplified test to focus only on /help command functionality
  • Sends /help\n/exit to the binary and verifies expected output
  • Added proper error handling with clear success/failure messages
  • Uses --no-test flag during build to avoid duplicate testing

Build Script (build.py):

  • Simplified test_executable() function to focus on /help command only
  • Removed complex exit code verification and error handling tests
  • Single test that verifies application starts and responds to /help correctly
  • Reduced timeout and simplified input/output handling

Verification:

  • ✅ Binary builds successfully (42.4 MB executable created)
  • ✅ Application starts with dummy API credentials
  • /help command produces expected output with all required content
  • ✅ All existing unit tests still pass (11/11)
  • ✅ Code passes linting and formatting checks

The changes have been committed and pushed to the openhands/update-agent-sdk-version branch, updating the existing PR #26. The CI tests are now focused, reliable, and much simpler while still ensuring core functionality works correctly.

View full conversation

@malhotra5
Copy link
Collaborator Author

@OpenHands please clean up openhands_cli/agent_chat.py and openhands_cli/simple_main.py

don't raise sys exists just let the application finish normally

then chat that CI and build will still catch errors. To test this temporarily comment out the jinja file dependency in the Pyinstaller spec and see that CI still catches it

@openhands-ai
Copy link

openhands-ai bot commented Sep 3, 2025

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

🟡 Solvability: MEDIUM

This is a well-defined code cleanup task with clear instructions to remove sys.exit calls from specific files and replace them with normal application termination. The request follows standard refactoring patterns and targets a localized change that doesn't require deep implementation knowledge.

You can make the issue easier to resolve by addressing these concerns in the conversation:

• Consider providing examples of the current sys.exit usage patterns to help identify all instances that need modification
• Include specific details about how errors should be handled after removing sys.exit calls

Positive feedback:

• The task has a clear, isolated cause with specific files and changes identified
• Uses simple, direct language that makes the requirements easy to understand
• Follows standard coding patterns for error handling improvements

…finish normally

- Remove sys.exit() calls from agent_chat.py and simple_main.py
- Replace with proper exception raising to let application finish normally
- CI and build will still catch errors through output validation
- Tested that CI still detects build/runtime errors without explicit exit codes

Co-authored-by: openhands <openhands@all-hands.dev>
Co-authored-by: openhands <openhands@all-hands.dev>
- Tests now expect original exceptions instead of SystemExit
- ImportError and general exceptions are now raised directly
- This aligns with the cleanup that removed sys.exit() calls

Co-authored-by: openhands <openhands@all-hands.dev>
@openhands-ai
Copy link

openhands-ai bot commented Sep 3, 2025

Summary

I have successfully cleaned up the error handling in openhands_cli/agent_chat.py and openhands_cli/simple_main.py as requested. Here's what was accomplished:

Request Fulfillment Checklist:

  1. ✅ Cleaned up both files - Removed all sys.exit() calls from agent_chat.py and simple_main.py
  2. ✅ Let application finish normally - Replaced sys.exit() with proper exception raising (raise)
  3. ✅ Verified CI still catches errors - Tested by temporarily commenting out jinja dependency and confirmed CI would still detect failures through output validation
  4. ✅ Tested error detection - Demonstrated that missing template files cause clear errors that CI catches

Key Changes Made:

In agent_chat.py:

  • Replaced sys.exit(1) with raise in import error handling and main() function
  • Updated docstrings to reflect new exception behavior

In simple_main.py:

  • Replaced sys.exit(1) with raise for ImportError and general exceptions
  • Removed unused sys import (linting fix)
  • Updated docstrings to reflect new exception behavior

In tests/test_main.py:

  • Updated tests to expect original exceptions (ImportError, Exception) instead of SystemExit

Verification Results:

  • ✅ All tests pass (11/11)
  • ✅ Linting passes with no issues
  • ✅ Binary builds successfully
  • ✅ CI simulation passes - application works correctly with /help command
  • ✅ Error detection confirmed - CI still catches build/runtime errors through output validation

Key Insight:

The application now finishes normally through Python's natural exception handling instead of using sys.exit(). CI and build systems still catch errors effectively because they validate expected output patterns rather than relying on specific exit codes. This approach is cleaner and more Pythonic while maintaining the same error detection capabilities.

The changes have been pushed to the existing PR branch openhands/update-agent-sdk-version.

View full conversation

@malhotra5 malhotra5 merged commit 44ab87c into main Sep 3, 2025
3 checks passed
@malhotra5 malhotra5 deleted the openhands/update-agent-sdk-version branch September 8, 2025 21:21
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.

Update agent-sdk version

2 participants