Implementation:AIScientists Dev WorldSeed director resolver resolve
| Knowledge Sources | |
|---|---|
| Domains | API_Design, Distributed_Systems |
| Last Updated | 2026-10-26 18:00 GMT |
Overview
Concrete external DM resolve handler that applies a watcher-supplied judgment to a queued pending DM request, reusing the same validation, sanitization, and atomic application pipeline as in-process DM.
Description
The resolve function in `director_resolver.py` reads a `PendingDMRequest` from the director queue, validates and sanitizes the supplied effects through the same pipeline as in-process DM, applies them atomically via `apply_dm_response`, and marks the request resolved or failed in the queue.
The resolve flow:
- Fetch the pending DM request by ID
- Validate status is "pending"
- Parse effects from raw dicts into `EffectConfig` objects
- Validate effects via `validate_dm_effects`
- Sanitize effects via `sanitize_dm_effects`
- Apply atomically via `apply_dm_response` (with rollback on failure)
- Mark request resolved or failed in the queue
- Call `engine.refresh_perception_and_observe()` so observers see the new state
Usage
Import this function for external DM resolution. In production, called by `WorldEngine.resolve_director_dm_request()` which is invoked by the `POST /api/director/dm/{id}/resolve` endpoint.
Code Reference
Source Location
- Repository: WorldSeed
- File: src/worldseed/director_resolver.py
Signature
def resolve(
engine: WorldEngine,
request_id: str,
narrative: str,
effects_raw: list[dict[str, Any]],
) -> tuple[bool, str]:
"""Apply an external DM judgment. Returns (ok, reason)."""
Import
from worldseed import director_resolver
# Or via WorldEngine.resolve_director_dm_request()
Usage Examples
# Via WorldEngine facade
ok, reason = engine.resolve_director_dm_request(
request_id="abc123",
narrative="The tea was perfectly brewed.",
effects_raw=[
{"operator": "set", "target": "teapot.temperature", "value": 80},
{"operator": "increment", "target": "agent_1.satisfaction", "value": 5},
],
)
if ok:
print("DM request resolved successfully")
else:
print(f"Failed: {reason}")