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:
- Handler registers context callbacks for hook events
- Callbacks update handler’s local steering_context on events
- Handler accesses self.steering_context in steer() method
- 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.
SteeringContext
@dataclassclass SteeringContext()Defined in: src/strands/experimental/steering/core/context.py:35
Container for steering context data.
SteeringContextCallback
class SteeringContextCallback(ABC, Generic[EventType])Defined in: src/strands/experimental/steering/core/context.py:49
Abstract base class for steering context update callbacks.
event_type
@propertydef event_type() -> type[HookEvent]Defined in: src/strands/experimental/steering/core/context.py:53
Return the event type this callback handles.
__call__
def __call__(event: EventType, steering_context: "SteeringContext", **kwargs: Any) -> NoneDefined in: src/strands/experimental/steering/core/context.py:60
Update steering context based on hook event.
Arguments:
event- The hook event that triggered the callbacksteering_context- The steering context to update**kwargs- Additional keyword arguments for context updates
SteeringContextProvider
class SteeringContextProvider(ABC)Defined in: src/strands/experimental/steering/core/context.py:71
Abstract base class for context providers that handle multiple event types.
context_providers
@abstractmethoddef 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.