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.
EventType = TypeVar('EventType', bound=HookEvent, contravariant=True)
module-attribute
¶
logger = logging.getLogger(__name__)
module-attribute
¶
HookEvent
dataclass
¶
Bases: BaseHookEvent
Base class for single agent hook events.
Attributes:
| Name | Type | Description |
|---|---|---|
agent |
Agent
|
The agent instance that triggered this event. |
Source code in strands/hooks/registry.py
69 70 71 72 73 74 75 76 77 | |
JSONSerializableDict
¶
A key-value store with JSON serialization validation.
Provides a dict-like interface with automatic validation that all values are JSON serializable on assignment.
Source code in strands/types/json_dict.py
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 | |
__init__(initial_state=None)
¶
Initialize JSONSerializableDict.
Source code in strands/types/json_dict.py
15 16 17 18 19 20 21 22 | |
delete(key)
¶
Delete a specific key from the store.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
The key to delete |
required |
Source code in strands/types/json_dict.py
52 53 54 55 56 57 58 59 | |
get(key=None)
¶
Get a value or entire data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str | None
|
The key to retrieve (if None, returns entire data dict) |
None
|
Returns:
| Type | Description |
|---|---|
Any
|
The stored value, entire data dict, or None if not found |
Source code in strands/types/json_dict.py
38 39 40 41 42 43 44 45 46 47 48 49 50 | |
set(key, value)
¶
Set a value in the store.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
The key to store the value under |
required |
value
|
Any
|
The value to store (must be JSON serializable) |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If key is invalid, or if value is not JSON serializable |
Source code in strands/types/json_dict.py
24 25 26 27 28 29 30 31 32 33 34 35 36 | |
SteeringContext
dataclass
¶
Container for steering context data.
Source code in strands/experimental/steering/core/context.py
34 35 36 37 38 39 40 41 42 43 | |
SteeringContextCallback
¶
Bases: ABC, Generic[EventType]
Abstract base class for steering context update callbacks.
Source code in strands/experimental/steering/core/context.py
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 | |
event_type
property
¶
Return the event type this callback handles.
__call__(event, steering_context, **kwargs)
¶
Update steering context based on hook event.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
event
|
EventType
|
The hook event that triggered the callback |
required |
steering_context
|
SteeringContext
|
The steering context to update |
required |
**kwargs
|
Any
|
Additional keyword arguments for context updates |
{}
|
Source code in strands/experimental/steering/core/context.py
60 61 62 63 64 65 66 67 68 | |
SteeringContextProvider
¶
Bases: ABC
Abstract base class for context providers that handle multiple event types.
Source code in strands/experimental/steering/core/context.py
71 72 73 74 75 76 77 | |
context_providers(**kwargs)
abstractmethod
¶
Return list of context callbacks with event types extracted from generics.
Source code in strands/experimental/steering/core/context.py
74 75 76 77 | |