New proposed folder structure proposal for Agent-S...
# proj-sdk
c
New proposed folder structure proposal for Agent-SDK (cc @wooden-umbrella-84098) This is needed to fix some of the PyPI publish issue @quick-window-91705 is running into Why this is needed for PyPI: Publishing each component as a separate wheel while sharing the openhands namespace requires PEP 420 implicit namespace packages—i.e., *a physical openhands/ directory with no init.py*—so multiple distributions (openhands-sdk, openhands-tools, etc.) can safely contribute subpackages into the same top-level namespace without file collisions. This layout keeps paths shallow (no src/), works with find_namespace_packages, supports editable installs, and ensures that after users pip install any combination of the four wheels, imports like
from openhands.sdk import ...
and
from openhands.tools import ...
resolve cleanly side-by-side.
Copy code
openhands-sdk/
├─ pyproject.toml
├─ README.md
├─ LICENSE
├─ CHANGELOG.md
├─ openhands/                   # PEP 420 namespace (NO __init__.py)
│  └─ sdk/
│     ├─ __init__.py
│     ├─ agent/
│     │  ├─ __init__.py
│     │  └─ ...
│     ├─ context/
│     │  ├─ __init__.py
│     │  └─ ...
│     └─ py.typed               # if typing exports are intended
├─ tests/
│  └─ ...
└─ tox.ini / pytest.ini (optional)

openhands-tools/
├─ pyproject.toml
├─ README.md
├─ LICENSE
├─ CHANGELOG.md
├─ openhands/                   # PEP 420 namespace (NO __init__.py)
│  └─ tools/
│     ├─ __init__.py
│     ├─ registry/
│     │  ├─ __init__.py
│     │  └─ ...
│     ├─ runners/
│     │  ├─ __init__.py
│     │  └─ ...
│     └─ py.typed
├─ tests/
│  └─ ...
└─ tox.ini / pytest.ini (optional)

openhands-workspace/
├─ pyproject.toml
├─ README.md
├─ LICENSE
├─ CHANGELOG.md
├─ openhands/                   # PEP 420 namespace (NO __init__.py)
│  └─ workspace/
│     ├─ __init__.py
│     ├─ docker/
│     │  ├─ __init__.py
│     │  └─ ...
│     ├─ local/
│     │  ├─ __init__.py
│     │  └─ ...
│     └─ py.typed
├─ tests/
│  └─ ...
└─ tox.ini / pytest.ini (optional)

openhands-agent-server/
├─ pyproject.toml
├─ README.md
├─ LICENSE
├─ CHANGELOG.md
├─ openhands/                   # PEP 420 namespace (NO __init__.py)
│  └─ agent_server/
│     ├─ __init__.py
│     ├─ app/
│     │  ├─ __init__.py
│     │  └─ ...
│     ├─ cli.py                 # optional console entrypoint
│     └─ py.typed
├─ tests/
│  └─ ...
└─ tox.ini / pytest.ini (optional)
q
Is there a way to test this before the changes are made? We could cut a pre-release with these changes on a PR I suppose
c
yep, working on this now
q
Am I correct in understanding that it would be a lot simpler to package and think about if there were different namespaces per project openhands_sdk etc...? Similar to pydantic_core.
c
yeah i think that will make things a lot easier, if that's what we want 🙂
q
I like easy. It does looks like your proposed folder structure is reasonable. The Python packaging guide shows a similar layout (just with
src
, but also warns of potential caveates.
Namespace packages can be useful for a large collection of loosely-related packages (such as a large corpus of client libraries for multiple products from a single company). However, namespace packages come with several caveats and are not appropriate in all cases. A simple alternative is to use a prefix on all of your distributions such as
import mynamespace_subpackage_a
(you could even use
import mynamespace_subpackage_a as subpackage_a
to keep the import object short).
V1 will probably be the last clean chance for a long time to change the namespaces if we decide to. Maybe this workaround you've got now is the last of the trouble, but if there are more snags I'd suggest changing
👍 1
c
I don't have strong opinions here, I've been choosing
openhands.sdk
instead of
openhands-sdk
was primarily because the former feels cleaner/easier to read - but i can definitely be persuaded otherwise 🙂 Still dealing with the last bit of error on separating the package now..
Copy code
The root issue is that your DiscriminatedUnionMixin depends on __subclasses__() to discover all subclasses at runtime—but after moving to a PEP 420 namespace package split across multiple wheels, many of those subclasses now live in other distributions that aren't automatically imported. Python only registers a class in __subclasses__() when its module has been imported and executed, so until the openhands.tools, openhands.workspace, or openhands.agent_server modules are imported, their concrete types don't exist in memory. As a result, your dynamic union builder only sees partial subclass sets and fails to resolve or serialize correctly—not because of packaging boundaries per se, but because the new namespace layout changed import timing and visibility.
maybe @wooden-umbrella-84098 can comment on whether we want to do
from openhands.sdk import X
OR
from openhands_sdk import X
if we switch to latter, we will need to do some global replace on downstream repo, but it shouldn't be too bad
q
Yes, it wouldn't be hard for us internally later but would a breaking change for anyone who isn't us that uses SDK
nod 1
w
file structure here is a little ugly, but seems OK. I would remove the
openhands-
prefixes from top-level directories if possible
slight preference for
openhands.sdk
aesthetically, but I could see a pretty strong argument against different packages sharing the same top-level namespace
c
I would remove the
openhands-
prefixes from top-level directories if possible
yep this is possible
slight preference for
openhands.sdk
aesthetically
same here, looks like it is probably ok to keep this; and it will save us from doing the big global replace
I could see a pretty strong argument against different packages sharing the same top-level namespace
Although i do think this is a legit python namespace (PEP420), we are probably fine here..
👍 1