.use(...). Plugins add behavior without modifying core code.
Plugin Protocol
A plugin is any Python class implementing optional methods (no base class required):| Hook | Triggered | Purpose |
|---|---|---|
on_register(cogos) | On .use() | Plugin initialization |
before_build(state, registry) | Before build() | Pre-processing |
after_build(state, registry, result) | After build() | Post-processing |
before_chat(state, registry) | Before chat() | Pre-processing |
after_chat(state, registry, result, answer) | After chat() | Post-processing |
chat_prompt_vars(message, *, session_id, state, registry, recalled) | During chatbot prompt generation | Inject custom prompt variables |
Registering Plugins
Example: External RAG Plugin
A complete example that retrieves context from an external service and injects it into the chatbot prompt:Common Use Cases
- External RAG retrieval — call your own service, inject retrieved context
- Logging / metrics — track build and chat operations
- Safety filters / policy checks — validate inputs and outputs