feat(atelier): worker_engine_factory state convention + helper#6
Merged
Conversation
Adds the optional state-key convention that lets host wrappers (AtelierOS,
OpenClaw, ...) inject a WorkerEngine factory into the AWP state dict so
workers can route their LLM calls through the host's engine layer instead
of bypassing it. Closes the architecture gap identified during the
AtelierOS Phase-4 wiring (ADR-0003 § Architecture invariant): host-side
"engine_id" audit events have no enclosing AWP-task-id correlation when
workers reach for an LLM directly.
The convention is OPTIONAL — workers ignoring the key keep working
exactly as before. Only workers wanting host-engine routing need to
adopt it.
Three changes:
* awp/atelier_integration.py — pure-Python helper module:
- WORKER_ENGINE_FACTORY_KEY constant ("worker_engine_factory")
- extract_engine_factory(state) → callable | None
- extract_engine_id(state, default) → str | None
- resolve_engine(state, engine_id?) → WorkerEngine | None (composes
factory lookup + call, fail-graceful)
- has_atelier_context(state) → bool
Zero hard deps on AtelierOS; works for any host following the same
convention.
* spec/versions/1.0/layers/04-memory-state.md — adds "worker_engine_factory"
to the reserved-keys table in §2.3 with OPTIONAL status. Workers MUST
NOT write to this key directly; orchestrator (host) owns it.
* reference/python/tests/test_atelier_integration.py — 20 unittest cases
covering all four helpers' happy + edge + failure paths (None state,
non-callable value, wrong-type meta, raising factory, etc.).
Backwards compatibility: 100%. Workers and hosts that don't know about
this key see no behaviour change. Spec status: OPTIONAL convention.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds the optional state-key convention (
state["worker_engine_factory"]) that lets host wrappers (AtelierOS, OpenClaw, ...) inject aWorkerEnginefactory into the AWP state dict so workers can route their LLM calls through the host's engine layer instead of bypassing it.This closes the architecture gap surfaced during AtelierOS Phase-4 integration: host-side
engine_idaudit events have no enclosing AWP-task-id correlation when AWP-workers reach for an LLM directly.The convention is OPTIONAL — workers ignoring the key keep working exactly as before. Only workers wanting host-engine routing need to adopt it.
Changes
awp/atelier_integration.pyextract_engine_factory,extract_engine_id,resolve_engine,has_atelier_context. Zero hard deps on AtelierOS; any host following the convention works.spec/versions/1.0/layers/04-memory-state.mdworker_engine_factoryto the reserved-keys table in §2.3 with OPTIONAL status. Workers MUST NOT write to this key directly; the orchestrator (host) owns it.reference/python/tests/test_atelier_integration.pyBackwards compatibility
100%. Workers and hosts that don't know about this key see no behaviour change.
Test plan
python -m unittest reference.python.tests.test_atelier_integration -v— 20/20 greenstatefor a stub workerHow a worker uses it
Generated with Claude Code