Documentation / @agentick/core / dispatchProcedure
Function: dispatchProcedure()
dispatchProcedure<
TArgs,TResult>(options,handler,args,contextOverrides?):Promise<TResult>
Defined in: kernel/src/procedure.ts:1757
Create a procedure on-the-fly and run it once. Use this for operations whose procedure identity (name, metadata) isn't known until request time — e.g., MCP tool dispatches like mcp:tool:call:<toolName>, RPC handlers named after the incoming message, dynamically-registered plugin endpoints.
For statically-named operations (tools, models, hooks the framework declares at design time) prefer createProcedure(...) and reuse the callable. Use this helper only when the procedure's identity is request-shaped.
The optional contextOverrides are merged with the ambient kernel context via Context.run, letting callers inject per-dispatch context (most importantly middleware) without requiring an outer Session or caller-managed wrap. When contextOverrides is omitted, the procedure runs in whatever ambient ALS context exists.
Type Parameters
TArgs
TArgs extends any[]
TResult
TResult
Parameters
options
handler
(...args) => Promise<TResult>
args
TArgs
contextOverrides?
Partial<KernelContext>
Returns
Promise<TResult>
Example
// Dispatch a request-named operation through middleware:
const result = await dispatchProcedure(
{ name: `mcp:tool:call:${toolName}`, metadata: { tool: toolName } },
async (input, ctx) => userTool.handler(input, ctx),
[input, handlerCtx],
{ middleware: agentickInstance },
);