Plugin context and runtime context in QiForge

Plugin code sees PluginContext at boot, with no user, and RuntimeContext per request, with an authenticated user. Learn what each holds and which hook to use.

Plugin code runs in one of two contexts, and the first thing to know about any hook is which one it gets. PluginContext exists at boot and has no user. RuntimeContext is built fresh for each request and carries the authenticated user. This page shows what each one holds and how to choose between a boot-time hook and a per-request hook.

Two contexts, two lifetimes

ContextLifetimeHas user?Where you receive it
PluginContextBoot (cached)NogetTools, getSubAgents, getMiddlewares, getNestModules
RuntimeContextFresh per requestYes (authenticated)Tool handlers, sub-agent handlers, middleware hooks, getRequestTools, getRequestSubAgents

The wrong context can't see what your code needs. A boot-time hook can't ask "who is the user", because there is no user yet. A per-request hook can't register a Nest module, because by then it is too late.

What each context carries

PluginContext: boot-time, no user

  • config: the merged, Zod-validated env (base + every plugin's configSchema).
  • identity: your oracle's identity (name, org, description, entityDid, prompt).
  • availablePlugins: the set of names of all loaded plugins, for soft-dependency branching.
  • logger: a plugin-scoped logger.

RuntimeContext: per request, authenticated user

Everything in PluginContext, plus:

FieldPurpose
userDID, Matrix user ID, UCAN delegation, timezone
sessionThread ID (= session.id), client (portal / matrix / slack), request ID, room ID
historymessages, recent(n), userContext, typed state view
secretsgetIndex(), getValues(keys) for per-user secrets
blobStoreShort-TTL keyed store for values the model must never echo verbatim (UCAN invocation CARs, JWTs): put() returns an opaque blob_<hex> id, get() resolves it server-side, isValidBlobId() checks the format. Blobs are scoped to the issuing user's DID
matrixScoped methods: postToRoom, getRoomState, getEventById
ucanrequireCapability, hasCapability, mintInvocation, resolveServiceDid, hasSigningKey(), createInvocationFromDelegation()
llmget(role, params) for the configured provider. role is 'main' / 'subagent' / 'utility'
emitTyped event emitter (toolCall, actionCall, renderComponent, reasoning, ...)
sharedTyped reads from other plugins' getSharedState
loadedPluginsSet of plugin names loaded for this thread
toolCallIdThe current tool call's id, needed when a tool returns a LangGraph Command
abortSignalRequest-scoped abort

The full field list and types are in the RuntimeContext reference.

Registration and execution

A tool registered through boot-time getTools(ctx) still receives a fresh RuntimeContext when its handler fires. "Boot-time" describes when the tool is registered, not when it runs. Both contexts exist over the lifetime of any tool.

Choosing the right hook

If a hook exists in both forms, pick by what your code reads:

If your code needs…Use
Only config + identityBoot-time hook (getTools(ctx))
Live state (loadedPlugins, userContext, browser tools)Per-request hook (getRequestTools(rtCtx))
The authenticated user's DID / timezone at registration timePer-request hook
Stable tool listBoot-time hook

When both hooks fire on the same plugin, their outputs are merged, so you don't have to choose one or the other.

Source: packages/oracle-runtime/src/runtime-context/ and PluginContext / RuntimeContext.