Cordis Context and Plugins: The Container Pattern Behind Agent Frameworks
Agent frameworks are inherently modular—tools, sessions, prompts, and loops all need to share state and respond to events. A container-based plugin system like Cordis avoids the wiring spaghetti that comes from manual dependency injection or global singletons, and the three plugin forms give teams a clear gradient from quick script to production service without changing the architecture.
Cordis, the framework underneath Koishi and DeepSeek Harness, reduces its core to two abstractions: a Context container and plugins that populate it. A Context holds services that any plugin can register with `ctx.provide('name', implementation)` and any other code can retrieve as `ctx.name`. Plugins come in three forms—functions for quick prototypes, objects when a name or metadata is needed, and classes for stateful components that accept configuration through the constructor.
The pattern is a service locator with explicit registration order. Plugins activate asynchronously via `ctx.plugin()`, so awaiting registration is mandatory before consuming a service. Internal state stays private inside closures or class fields; only the methods exposed through `ctx.provide()` are reachable from outside.
This container model becomes the foundation for the Agent framework built in later installments: Session management, tool systems, prompt assembly, and the agent loop will each be services living inside the same Context, wired together through the same provide-and-consume mechanism.
The three plugin forms are not about capability—they all end up calling `ctx.provide()`. The choice is purely about code organization: how much ceremony a given module deserves.
Private state in closures (function and object plugins) is a deliberate encapsulation boundary. External code cannot reach the `logs` array or `count` variable directly, only through the methods exposed on the service object.
Cordis uses a service locator pattern rather than constructor-based dependency injection. Plugins don't declare what they need; they just reach into the Context and grab it, which means ordering and activation timing matter.
The framework's minimal surface area—two concepts, three plugin forms—suggests the complexity in an Agent system will come from the services themselves, not from the wiring between them.