Skip to content

strands.experimental.steering.core.context

Steering context protocols for contextual guidance.

Defines protocols for context callbacks and providers that populate steering context data used by handlers to make guidance decisions.

Architecture: SteeringContextCallback → Handler.steering_context → SteeringHandler.steer() ↓ ↓ ↓ Update local context Store in handler Access via self.steering_context

Context lifecycle:

  1. Handler registers context callbacks for hook events
  2. Callbacks update handler’s local steering_context on events
  3. Handler accesses self.steering_context in steer() method
  4. Context persists across calls within handler instance

Implementation: Each handler maintains its own JSONSerializableDict context. Callbacks are registered per handler instance for isolation. Providers can supply multiple callbacks for different events.

@dataclass
class SteeringContext()

Defined in: src/strands/experimental/steering/core/context.py:35

Container for steering context data.

class SteeringContextCallback(ABC, Generic[EventType])

Defined in: src/strands/experimental/steering/core/context.py:49

Abstract base class for steering context update callbacks.

@property
def event_type() -> type[HookEvent]

Defined in: src/strands/experimental/steering/core/context.py:53

Return the event type this callback handles.

def __call__(event: EventType, steering_context: "SteeringContext",
**kwargs: Any) -> None

Defined in: src/strands/experimental/steering/core/context.py:60

Update steering context based on hook event.

Arguments:

  • event - The hook event that triggered the callback
  • steering_context - The steering context to update
  • **kwargs - Additional keyword arguments for context updates
class SteeringContextProvider(ABC)

Defined in: src/strands/experimental/steering/core/context.py:71

Abstract base class for context providers that handle multiple event types.

@abstractmethod
def context_providers(**kwargs: Any) -> list[SteeringContextCallback]

Defined in: src/strands/experimental/steering/core/context.py:75

Return list of context callbacks with event types extracted from generics.