Skip to content

Declare Python agents and dispatch their methods - #4518

Draft
noise64 wants to merge 3 commits into
python-runtimefrom
python-agents
Draft

noise64 wants to merge 3 commits into
python-runtimefrom
python-agents

Conversation

@noise64

@noise64 noise64 commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Part of GOL-1851. Stacked on #4516 (PY-02). PY-04 and PY-05 come next.

This PR adds agent declarations and method dispatch to the Python SDK. Methods are synchronous, and parameters and results have primitive types.

  • @agent and @method only record the class or the function and its file and line. They construct nothing. After pre-initialization imports every entry module, the bootstrap finalizes the registry. Finalization resolves the annotations in their defining scopes, so an annotation can name a type that the module defines later. It makes one declaration per agent type. Discovery and the argument and result checks use the same declaration.
  • Finalization reports every invalid declaration in one build error, each with its location. These are invalid: unsupported or missing annotations, including wrappers such as Annotated[int, ...], class annotations that fail to evaluate, a first parameter that is not positional (the method needs it for the instance), async or generator methods, default, variadic and keyword-only parameters, config, duplicate type names, @method outside an @agent class, and @method on __init__, a staticmethod or a classmethod. The error reaches the build through the stderr capture from Build Python components from prepared runtime assets #4516. A structured, bounded diagnostic channel is not part of this PR.
  • The types are bool, int (s64), float (f64), str, bytes (binary) and None (unit output). bool is not an int, and int is not a float. An int result outside the s64 range is an error, because s64 is the default int schema.
  • The constructor is the ordinary __init__. An instance initializes one agent, once. A second initialize fails and keeps the agent and its state. Only decorated methods are exported.
  • The guest decodes and checks the arguments before user code runs. Invalid arguments give invalid-input and change no state. An unknown type gives invalid-type, and an unknown method gives invalid-method. An exception from the constructor or a method gives a custom-error with a string payload, as the TypeScript SDK does. A result of the wrong type also gives a custom-error, but the method already ran, so its effects stay. Retry is not safe in that case.

The native tests in sdks/python/tests check declarations and dispatch without Wasm. The tests in golem-python-assembler/tests/assemble.rs build actual components from the prepared assets and run discovery, initialization and invocation on the shared engine. They use a stateful Counter with unequal updates, both s64 bounds, bool-versus-int inputs, and malformed inputs that would change the state if they reached the method. Golem CI does not run these integration tests yet, because they need the prepared assets.

Not in this PR: async methods, compound types, config, descriptions, HTTP mounts and declared errors (later SDK issues); the wheel (PY-04); CLI build, deploy and reconstruction (PY-05).

Verification

This head, cc279c3, merges the new #4516 head into the previous head 7d1342c. This layer has no other change. Checks on this head:

  • python -I -m unittest discover -s tests in sdks/python, on native CPython 3.14: pass.
  • cargo test -p golem-python-assembler --tests and --doc, cargo clippy -p golem-python-assembler --all-targets -- -D warnings and cargo fmt -p golem-python-assembler -- --check: pass.
  • ruff format --check: pass. ruff check: fails with the known findings BLE001 (twice, in _registry.py) and S102 (in tests/test_declarations.py).

CI: pull requests run no Golem tests. A missing result is not a pass.

This branch has not been deployed

No deployments
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.

1 participant