π§ Director
The director module acts as the central coordinator for cross-feature transitions in the codex-bot framework.
π§ The Why
Decoupling Features
In a large bot, features often need to transition from one to another (e.g., from "Profile" to "Booking"). Without a central coordinator, features would need to import each other, creating circular dependencies and making the system brittle. The Director solves this by using a DI-container and Protocols to decouple features.
Stateless Context
Since Orchestrators are stateless, they need a way to access the current request's context (user ID, chat ID, FSM state). The Director is instantiated on every incoming request and passes itself as an argument to the Orchestrator's methods. This ensures that all user-specific data is isolated within the Director instance.
π The Flow
- Initialization: A handler creates a
Directorinstance with the currentFSMContext,user_id, andchat_id. - Transition: The handler calls
director.set_scene(feature="booking", payload=...). - Discovery: The
Directorretrieves the requested Orchestrator from the DI-container'sfeaturesregistry. - State Change: If the Orchestrator has an
expected_state, theDirectorautomatically sets the user's FSM state. - Execution: The
Directorcalls the Orchestrator'shandle_entry(director=self, payload=...)method. - Enrichment: The
Directorenriches the resultingUnifiedViewDTOwith routing metadata before returning it.
πΊοΈ Module Map
| Component | Description |
|---|---|
| π API Reference | Technical details for the Director class. |
| π Protocols | OrchestratorProtocol, ContainerProtocol, and SceneConfig. |
Last Updated: 2025-02-07