Extension API Reference¶
This page is the reference companion to Writing extensions and Events. It documents the
objects an extension’s register(mb) function receives and the types it works with.
register(mb) is called once at startup with an ExtensionContext
built from the module’s [extensions.config.<module>] section. Import and registration failures
are fatal — a module that cannot load stops startup rather than leaving the agent silently unable
to use its tools.
ExtensionContext¶
- class minibot.app.extensions.ExtensionContext(name, config, settings, event_bus, logger, entrypoint='daemon', tools=<factory>, subscriptions=<factory>, services=<factory>)[source]¶
Handed to an extension’s
register(mb)function.Deliberately narrow: the container is a class-level singleton, and passing it whole would make every one of its fields public API.
entrypointis"daemon","console", or"worker". Channel extensions must contribute nothing outside the daemon: those entrypoints do not drive channel services.- Parameters:
- settings: Settings¶
- event_bus: EventBus¶
- entrypoint: ExtensionEntrypoint = 'daemon'¶
- tools: list[ToolBinding]¶
- services: list[ExtensionService]¶
- tool(func)[source]¶
Register
funcas a tool: name from__name__, description from its docstring, parameters from its first argument’s pydantic model.For anything this does not cover — a name that is not a Python identifier, a hand-written schema, a description loaded from a file — build the
ToolBindingyourself and pass it toadd_tool.- Parameters:
func (Callable[[Any, ToolContext], Awaitable[Any]])
- Return type:
Callable[[Any, ToolContext], Awaitable[Any]]
- add_tool(bindings)[source]¶
- Parameters:
bindings (ToolBinding | Sequence[ToolBinding])
- Return type:
None
- add_service(service)[source]¶
- Parameters:
service (ExtensionService)
- Return type:
None
ExtensionService¶
Objects passed to mb.add_service implement this protocol. They are started when the entrypoint
starts and stopped on shutdown.
Tools¶
- class minibot.llm.tools.base.ToolBinding(tool: 'Tool', handler: 'ToolHandler')[source]¶
- Parameters:
- tool: Tool¶
Events¶
Subscribe to any of these with @mb.on(EventType) or mb.on(EventType, handler). See
Events for when each one fires and what its payload carries. Handlers are async and lossy:
a slow handler drops events rather than blocking the pipeline.
- class minibot.core.events.MessageEvent(*, event_id=<factory>, event_type='message', message)[source]¶
-
- message: ChannelMessage¶
- model_config = {}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class minibot.core.events.OutboundEvent(*, event_id=<factory>, event_type='outbound', response)[source]¶
-
- response: ChannelResponse¶
- model_config = {}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class minibot.core.events.OutboundFileEvent(*, event_id=<factory>, event_type='outbound_file', response)[source]¶
-
- response: ChannelFileResponse¶
- model_config = {}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class minibot.core.events.OutboundFormatRepairEvent(*, event_id=<factory>, event_type='outbound_format_repair', response, parse_error, attempt=1, chat_id, channel, user_id=None)[source]¶
- Parameters:
- response: ChannelResponse¶
- model_config = {}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class minibot.core.events.SystemEvent(*, event_id=<factory>, event_type='system', payload=None)[source]¶
-
- model_config = {}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class minibot.core.events.TurnStartedEvent(*, event_id=<factory>, event_type='turn_started', turn_id, channel, chat_id=None, user_id=None)[source]¶
Emitted when the dispatcher begins processing an inbound message.
- Parameters:
- model_config = {}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class minibot.core.events.TurnCompletedEvent(*, event_id=<factory>, event_type='turn_completed', turn_id, channel, chat_id=None, should_reply=True, llm_provider=None, llm_model=None, token_trace=<factory>, compaction_performed=None)[source]¶
Emitted once a turn is fully done.
Fires after the response has been dispatched to the channel, or deliberately suppressed when
should_replyis false — never before.- Parameters:
- model_config = {}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class minibot.core.events.TurnFailedEvent(*, event_id=<factory>, event_type='turn_failed', turn_id, channel, chat_id=None, error)[source]¶
Emitted when a turn raised before producing a response.
- Parameters:
- model_config = {}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class minibot.core.events.ReasoningEvent(*, event_id=<factory>, event_type='reasoning', text, step, turn_id=None, owner_id=None, channel=None, chat_id=None)[source]¶
Emitted as soon as one provider step returns reasoning, before the turn finishes.
Reasoning is also attached to the final response metadata; this event exists so a channel can show thinking while the turn is still running instead of only after it completes.
- Parameters:
- model_config = {}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class minibot.core.events.ToolCallEvent(*, event_id=<factory>, event_type='tool_call', phase, tool_name, turn_id=None, owner_id=None, channel=None, chat_id=None, detail='', error=None)[source]¶
Emitted around every tool handler invocation.
detailis already redacted and clipped byminibot/shared/tool_call_display.pybefore this event is published — the raw argument payload (which can hold credentials, e.g.http_requestheaders,bashenv,python_executecode) never leaves the tool-execution layer. Safe to log, persist, or forward to any subscriber, including extensions.- Parameters:
- phase: Literal['started', 'completed', 'failed']¶
- model_config = {}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].