|
1 | | -# Prototype for OpenHands V1 |
2 | | - |
3 | | -This folder contains my tasks of completely refactor [OpenHands](https://github.com/All-Hands-AI/OpenHands) project V0 into the new V1 version. There's a lot of changes, including (non-exhausive): |
4 | | - |
5 | | -- Switching from poetry to uv as package manager |
6 | | -- better dependency management |
7 | | - - include `--dev` group for development only |
8 | | -- stricter pre-commit hooks `.pre-commit-config.yaml` that includes |
9 | | - - type check through pyright |
10 | | - - linting and formatter with `uv ruff` |
11 | | -- cleaner architecture for how a tool works and how it is executed |
12 | | - - read about how we define tools: [`openhands/core/runtime/tool.py`](openhands/core/runtime/tool.py) |
13 | | - - read about how we define schema (input/output) for tools: [`openhands/core/runtime/schema.py`](openhands/core/runtime/schema.py) |
14 | | - - read about patterns for how we define an executable tool: |
15 | | - - read [openhands/core/runtime/tools/str_replace_editor/impl.py](openhands/core/runtime/tools/str_replace_editor/impl.py) for tool execute_fn |
16 | | - - read [openhands/core/runtime/tools/str_replace_editor/definition.py](openhands/core/runtime/tools/str_replace_editor/definition.py) for how do we define a tool |
17 | | - - read [openhands/core/runtime/tools/str_replace_editor/__init__.py](openhands/core/runtime/tools/str_replace_editor/__init__.py) for how we define each tool module |
18 | | -- tools: `str_replace_editor`, `execute_bash` |
19 | | -- minimal config (OpenHandsConfig, LLMConfig, MCPConfig): `openhands/core/config` |
20 | | -- core set of LLM (w/o tests): `openhands/core/llm` |
21 | | -- core set of microagent functionality (w/o full integration): |
22 | | - - `openhands/core/context`: redesigned the triggering of microagents w.r.t. agents into the concept of two types context |
23 | | - - EnvContext (triggered at the begining of a convo) |
24 | | - - MessageContext (triggered at each user message) |
25 | | - - `openhands-v1/openhands/core/microagents`: old code from V1 that loads microagents from folders, etc |
26 | | -- minimal implementation of codeact agent: `openhands-v1/openhands/core/agenthub/codeact_agent` |
27 | | -- ... |
28 | | - |
29 | | - |
30 | | -**Check hello world example** |
| 1 | +# OpenHands Agent SDK |
| 2 | + |
| 3 | +A clean, modular SDK for building AI agents with OpenHands. This project represents a complete architectural refactor from OpenHands V0, emphasizing simplicity, maintainability, and developer experience. |
| 4 | + |
| 5 | +## Repository Structure |
| 6 | + |
| 7 | +``` |
| 8 | +agent-sdk/ |
| 9 | +├── .github/ |
| 10 | +│ └── workflows/ # CI/CD workflows |
| 11 | +│ ├── precommit.yml # Pre-commit hook validation |
| 12 | +│ └── tests.yml # Test execution pipeline |
| 13 | +├── .pre-commit-config.yaml # Pre-commit hooks configuration |
| 14 | +├── Makefile # Build and development commands |
| 15 | +├── README.md # This file |
| 16 | +├── pyproject.toml # Root project configuration |
| 17 | +├── uv.lock # Dependency lock file |
| 18 | +├── examples/ |
| 19 | +│ └── hello_world.py # Getting started example |
| 20 | +├── openhands/ # Main SDK packages |
| 21 | +│ ├── core/ # Core SDK functionality |
| 22 | +│ │ ├── agent/ # Agent implementations |
| 23 | +│ │ │ ├── base.py # Base agent interface |
| 24 | +│ │ │ └── codeact_agent/ # CodeAct agent implementation |
| 25 | +│ │ ├── config/ # Configuration management |
| 26 | +│ │ │ ├── llm_config.py # LLM configuration |
| 27 | +│ │ │ └── mcp_config.py # MCP configuration |
| 28 | +│ │ ├── context/ # Context management system |
| 29 | +│ │ │ ├── env_context.py # Environment context |
| 30 | +│ │ │ ├── message_context.py # Message context |
| 31 | +│ │ │ ├── history.py # Conversation history |
| 32 | +│ │ │ ├── manager.py # Context manager |
| 33 | +│ │ │ ├── prompt.py # Prompt management |
| 34 | +│ │ │ └── microagents/ # Microagent system |
| 35 | +│ │ ├── conversation/ # Conversation management |
| 36 | +│ │ │ ├── conversation.py # Core conversation logic |
| 37 | +│ │ │ ├── serializer.py # Conversation serialization |
| 38 | +│ │ │ ├── state.py # Conversation state |
| 39 | +│ │ │ ├── types.py # Type definitions |
| 40 | +│ │ │ └── visualizer.py # Conversation visualization |
| 41 | +│ │ ├── llm/ # LLM integration layer |
| 42 | +│ │ │ ├── llm.py # Main LLM interface |
| 43 | +│ │ │ ├── message.py # Message handling |
| 44 | +│ │ │ ├── metadata.py # LLM metadata |
| 45 | +│ │ │ └── utils/ # LLM utilities |
| 46 | +│ │ ├── tool/ # Tool system |
| 47 | +│ │ │ ├── tool.py # Core tool interface |
| 48 | +│ │ │ ├── schema.py # Tool schema definitions |
| 49 | +│ │ │ └── builtins/ # Built-in tools |
| 50 | +│ │ ├── utils/ # Core utilities |
| 51 | +│ │ ├── logger.py # Logging configuration |
| 52 | +│ │ ├── pyproject.toml # Core package configuration |
| 53 | +│ │ └── tests/ # Unit tests for core |
| 54 | +│ └── tools/ # Tool implementations |
| 55 | +│ ├── execute_bash/ # Bash execution tool |
| 56 | +│ ├── str_replace_editor/ # String replacement editor |
| 57 | +│ ├── utils/ # Tool utilities |
| 58 | +│ ├── pyproject.toml # Tools package configuration |
| 59 | +│ └── tests/ # Unit tests for tools |
| 60 | +└── tests/ # Integration tests |
| 61 | +``` |
| 62 | + |
| 63 | +## Quick Start |
| 64 | + |
| 65 | +```bash |
| 66 | +# Install dependencies |
| 67 | +make build |
| 68 | + |
| 69 | +# Run hello world example |
| 70 | +uv run python examples/hello_world.py |
| 71 | + |
| 72 | +# Run tests |
| 73 | +uv run pytest |
| 74 | + |
| 75 | +# Run pre-commit hooks |
| 76 | +uv run pre-commit run --all-files |
| 77 | +``` |
| 78 | + |
| 79 | +## Development Guidelines |
| 80 | + |
| 81 | +### Core Principles |
| 82 | + |
| 83 | +This project follows principles of simplicity, pragmatism, and maintainability: |
| 84 | + |
| 85 | +1. **Simplicity First**: If it needs more than 3 levels of indentation, redesign it |
| 86 | +2. **No Special Cases**: Good code eliminates edge cases through proper data structure design |
| 87 | +3. **Pragmatic Solutions**: Solve real problems, not imaginary ones |
| 88 | +4. **Never Break Userspace**: Backward compatibility is sacred |
| 89 | + |
| 90 | +### Architecture Overview |
| 91 | + |
| 92 | +The SDK is built around two core packages: |
| 93 | + |
| 94 | +- **`openhands/core`**: Core SDK functionality (agents, LLM, context, conversation) |
| 95 | +- **`openhands/tools`**: Tool implementations (bash execution, file editing) |
| 96 | + |
| 97 | +Each package is independently testable and deployable, with clear separation of concerns. |
| 98 | + |
| 99 | +### Development Workflow |
| 100 | + |
| 101 | +#### 1. Environment Setup |
31 | 102 |
|
32 | 103 | ```bash |
| 104 | +# Initial setup |
| 105 | +make build |
| 106 | + |
| 107 | +# Activate virtual environment (if needed) |
| 108 | +source .venv/bin/activate |
| 109 | +``` |
| 110 | + |
| 111 | +#### 2. Code Quality Standards |
| 112 | + |
| 113 | +- **Type Checking**: All code must pass `pyright` type checking |
| 114 | +- **Linting**: Code must pass `ruff` linting and formatting |
| 115 | +- **Testing**: Maintain test coverage for new functionality |
| 116 | +- **Documentation**: Code should be self-documenting; avoid redundant comments |
| 117 | + |
| 118 | +#### 3. Pre-commit Workflow |
| 119 | + |
| 120 | +Before every commit: |
| 121 | + |
| 122 | +```bash |
| 123 | +# Run pre-commit hooks on changed files |
| 124 | +uv run pre-commit run --files <filepath> |
| 125 | + |
| 126 | +# Or run on all files |
| 127 | +uv run pre-commit run --all-files |
| 128 | +``` |
| 129 | + |
| 130 | +#### 4. Testing Strategy |
| 131 | + |
| 132 | +**Unit Tests**: Located in package-specific test directories |
| 133 | +- `openhands/core/tests/` - Tests for core functionality |
| 134 | +- `openhands/tools/tests/` - Tests for tool implementations |
| 135 | + |
| 136 | +**Integration Tests**: Located in root `tests/` directory |
| 137 | +- Tests that involve both core and tools packages |
| 138 | + |
| 139 | +**Running Tests**: |
| 140 | +```bash |
| 141 | +# Run all tests |
| 142 | +uv run pytest |
| 143 | + |
| 144 | +# Run specific test file |
| 145 | +uv run pytest openhands/core/tests/tool/test_tool.py |
| 146 | + |
| 147 | +# Run with coverage |
| 148 | +uv run pytest --cov=openhands |
| 149 | +``` |
| 150 | + |
| 151 | +#### 5. Package Management |
| 152 | + |
| 153 | +This project uses `uv` for dependency management: |
| 154 | + |
| 155 | +```bash |
| 156 | +# Add a new dependency |
| 157 | +uv add package-name |
| 158 | + |
| 159 | +# Add a development dependency |
| 160 | +uv add --dev package-name |
| 161 | + |
| 162 | +# Update dependencies |
| 163 | +uv lock --upgrade |
| 164 | + |
| 165 | +# Install from lock file |
33 | 166 | uv sync |
34 | | -uv run python examples/hello.py |
35 | 167 | ``` |
0 commit comments