Skip to content

Conversation

@wolvever
Copy link

Summary

  • Implemented 4 core OH tools adapted from OpenHands for enhanced agent capabilities
  • Added comprehensive test suite with 41 tests achieving 77% code coverage
  • Integrated tools follow the existing agentic rollout framework patterns

Implementation Details

New Tools Added

  1. OHBashTool - Execute bash commands with timeout and session management

    • Supports command execution with configurable timeouts
    • Maintains persistent shell sessions
    • Handles long-running processes and user interaction
  2. OHStrReplaceEditorTool - File viewing, creation, and editing capabilities

    • View files with optional line ranges
    • Create new files with parent directory validation
    • String replacement with uniqueness checking
    • Insert lines at specific positions
    • Undo functionality for recent edits
  3. OHThinkTool - Log agent thought processes and reasoning

    • Captures agent reasoning for transparency
    • Maintains thought history per instance
    • Configurable thought truncation
  4. OHFinishTool - Signal task completion with status tracking

    • Tracks task completion status (complete/partial/failed)
    • Generates commit messages
    • Provides final user messages

Utility Functions

  • get_oh_tool(name, config) - Get individual tool with optional configuration
  • get_all_oh_tools(config) - Get all OH tools as a dictionary
  • OH_TOOLS registry for easy tool access

Testing

  • Created test_oh_tools.py with comprehensive test coverage
  • 41 tests covering all tools and edge cases
  • Integration test demonstrating tools working together
  • 77% code coverage across all OH tools modules

Dependencies Added

  • chardet>=5.2.0 - For file encoding detection
  • pytest>=8.3.5 - Testing framework
  • pytest-asyncio>=0.24.0 - Async test support
  • pytest-cov>=5.0.0 - Coverage reporting

Test Results

============================== 41 passed in 1.26s ==============================

Coverage Report:
Name                                           Stmts   Miss  Cover   Missing
----------------------------------------------------------------------------
workers/tools/oh_tools/__init__.py                13      0   100%
workers/tools/oh_tools/bash.py                    77     22    71%
workers/tools/oh_tools/finish.py                  52      3    94%
workers/tools/oh_tools/str_replace_editor.py     212     61    71%
workers/tools/oh_tools/think.py                   43      4    91%
----------------------------------------------------------------------------
TOTAL                                            397     90    77%

Usage Example

from workers.tools.oh_tools import get_oh_tool, get_all_oh_tools

# Get individual tool
bash_tool = get_oh_tool('bash')
result = await bash_tool.execute_tool(instance_id, {"command": "ls -la"})

# Get all tools
tools = get_all_oh_tools(config={"max_output_length": 5000})

🤖 Generated with Claude Code

- Implemented 4 core OH tools adapted from OpenHands:
  - OHBashTool: Execute bash commands with timeout and session management
  - OHStrReplaceEditorTool: File viewing, creation, and editing capabilities
  - OHThinkTool: Log agent thought processes and reasoning
  - OHFinishTool: Signal task completion with status tracking

- Added utility functions:
  - get_oh_tool(): Get individual tool by name with optional config
  - get_all_oh_tools(): Get all OH tools as a dictionary
  - OH_TOOLS registry for easy tool access

- Created comprehensive test suite (test_oh_tools.py):
  - 41 tests covering all tools and functionality
  - 77% code coverage across OH tools modules
  - Unit tests for each tool's core features
  - Integration test demonstrating tools working together

- Updated dependencies:
  - Added chardet for file encoding detection
  - Added pytest and pytest-asyncio for testing
  - Added pytest-cov for coverage reporting

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
Copy link
Member

@guru4elephant guru4elephant left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

需要支持k8s版本,参考r2e和kodo的组合方式。

# Execute new command
try:
# Run command with timeout
process = await asyncio.create_subprocess_shell(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个方案不行,得用k8s方案,kodo去pod执行。我会在远程启pod,然后用pod name 过去执行。参考r2e k8s的tools实现。

- Updated bash.py to support K8s pod execution via kodo library
- Added K8s configuration parameters (execution_mode, pod_name, namespace, kubeconfig_path)
- Implemented _run_k8s_command method for remote command execution
- Added get_execution_info method to report execution environment

- Updated str_replace_editor.py with comprehensive K8s support
- Implemented K8s-specific file operations using base64 encoding
- Added methods for K8s file operations (read, write, delete, exists)
- Maintained backward compatibility with local execution mode

Both tools now support:
- Local execution (default)
- K8s pod execution when configured with appropriate parameters
- Proper error handling and fallback mechanisms

All existing tests pass without modification.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
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.

3 participants