Skip to content

Documentation / @agentick/core / Procedure

Variable: Procedure

Procedure: object

Defined in: kernel/src/procedure.ts:573

Namespace object for Procedure-related helpers, enabling Procedure.dispatch(...) calling style alongside the functional dispatchProcedure(...). Both forms point to the same implementation.

Procedure is also a generic interface (the callable shape of an authored procedure). TypeScript declaration merging permits a value and a type to share a name; both are independently importable.

Type Declaration

dispatch()

readonly dispatch: <TArgs, TResult>(options, handler, args, contextOverrides?) => Promise<TResult> = dispatchProcedure

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

ProcedureOptions

handler

(...args) => Promise<TResult>

args

TArgs

contextOverrides?

Partial<KernelContext>

Returns

Promise<TResult>

Example

typescript
// 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 },
);

Released under the ISC License.