NOETIC
Framework
Operators

withContext

Attach context layers to descendant steps without creating an isolated context.

Quick Example

import { callModel, withContext } from '@noetic-tools/core';

const withLayers = withContext({
  id: 'with-knowledge',
  child: callModel({
    id: 'researcher',
    model: 'openai/gpt-4o',
    instructions: 'Research the topic thoroughly.',
  }),
  context: [knowledgeLayer, steeringLayer],
});

What It Does

withContext attaches context layers to a subtree of steps without creating an isolated context. Like React's Context.Provider, layers become available to all descendant steps -- the child shares the parent's ItemLog and conversation history.

This is the primitive for scoping context layers to a section of your execution tree. Any StepCallModel descendant will have access to the provided layers during recall, store, and steering hooks.

spawn and detachedSpawn break the inheritance chain. If a descendant step spawns a child, the provided layers do not propagate into the spawn boundary.

API Reference

PropertyTypeRequiredDescription
idstringYesUnique step identifier
childStep<TContext, I, O>YesThe step to execute with the provided layers
contextContextConfig | ContextLayer[]YesContext layers available to all descendant steps

Example: Scoped Knowledge Layer

Attach a knowledge base layer only to a specific subtree, without affecting sibling steps:

import { callModel, withContext } from '@noetic-tools/core';

const researchPhase = withContext({
  id: 'research-with-knowledge',
  child: {
    kind: 'loop',
    id: 'research-loop',
    steps: [callModel({
      id: 'researcher-llm',
      model: 'openai/gpt-4o',
      instructions: 'You are a research assistant.',
      tools: [searchTool],
    })],
    until: until.noToolCalls(),
    maxIterations: 10,
  },
  context: [semanticRecallLayer, steeringLayer],
});
  • spawn -- context isolation with spawn-local context layers.
  • Context Layers -- context layer system overview.
  • Overview -- how withContext fits into the step primitives.

On this page