Skip to content

Documentation / @agentick/core / withExecution

Function: withExecution() ​

withExecution<T>(nameOrOptions, fn): Promise<T>

Defined in: kernel/src/execution-helpers.ts:252

Create a named execution boundary around an operation.

Use this to mark semantically meaningful operations that should appear as distinct executions in DevTools. The execution will be linked as a child of the current execution (if any).

Type Parameters ​

T ​

T

Parameters ​

nameOrOptions ​

Execution name string or options object

string | WithExecutionOptions

fn ​

() => Promise<T>

The async function to execute within this boundary

Returns ​

Promise<T>

The result of the function

Example ​

typescript
// Simple usage with just a name
const summary = await withExecution("Summarize Context", async () => {
  return model.generate(summarizePrompt);
});

// With options
const result = await withExecution({
  name: "Validate Response",
  type: "validation",
  metadata: { validator: "schema" },
}, async () => {
  return validateSchema(response);
});

// In a hook
onAfterCompile: async (ctx) => {
  await withExecution("Context Compaction", async () => {
    const summary = await model.generate(compactPrompt);
    ctx.updateContext(summary);
  });
}

Released under the ISC License.