strands.experimental.steering.handlers.llm.mappers
¶
LLM steering prompt mappers for generating evaluation prompts.
_STEERING_PROMPT_TEMPLATE = '# Steering Evaluation\n\n## Overview\n\nYou are a STEERING AGENT that evaluates a {action_type} that ANOTHER AGENT is attempting to make.\nYour job is to provide contextual guidance to help the other agent navigate workflows effectively.\nYou act as a safety net that can intervene when patterns in the context data suggest the agent\nshould try a different approach or get human input.\n\n**YOUR ROLE:**\n- Analyze context data for concerning patterns (repeated failures, inappropriate timing, etc.)\n- Provide just-in-time guidance when the agent is going down an ineffective path\n- Allow normal operations to proceed when context shows no issues\n\n**CRITICAL CONSTRAINTS:**\n- Base decisions ONLY on the context data provided below\n- Do NOT use external knowledge about domains, URLs, or tool purposes \n- Do NOT make assumptions about what tools "should" or "shouldn\'t" do\n- Focus ONLY on patterns in the context data\n\n## Context\n\n{context_str}\n\n## Event to Evaluate\n\n{event_description}\n\n## Steps\n\n### 1. Analyze the {action_type_title}\n\nReview ONLY the context data above. Look for patterns in the data that indicate:\n\n- Previous failures or successes with this tool\n- Frequency of attempts\n- Any relevant tracking information\n\n**Constraints:**\n- You MUST base analysis ONLY on the provided context data\n- You MUST NOT use external knowledge about tool purposes or domains\n- You SHOULD identify patterns in the context data\n- You MAY reference relevant context data to inform your decision\n\n### 2. Make Steering Decision\n\n**Constraints:**\n- You MUST respond with exactly one of: "proceed", "guide", or "interrupt"\n- You MUST base the decision ONLY on context data patterns\n- Your reason will be shown to the AGENT as guidance\n\n**Decision Options:**\n- "proceed" if context data shows no concerning patterns\n- "guide" if context data shows patterns requiring intervention\n- "interrupt" if context data shows patterns requiring human input\n'
module-attribute
¶
DefaultPromptMapper
¶
Bases: LLMPromptMapper
Default prompt mapper for steering evaluation.
Source code in strands/experimental/steering/handlers/llm/mappers.py
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 | |
create_steering_prompt(steering_context, tool_use=None, **kwargs)
¶
Create default steering prompt using Agent SOP structure.
Uses Agent SOP format for structured, constraint-based prompts. See: https://github.com/strands-agents/agent-sop
Source code in strands/experimental/steering/handlers/llm/mappers.py
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 | |
LLMPromptMapper
¶
Bases: Protocol
Protocol for mapping context and events to LLM evaluation prompts.
Source code in strands/experimental/steering/handlers/llm/mappers.py
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 | |
create_steering_prompt(steering_context, tool_use=None, **kwargs)
¶
Create steering prompt for LLM evaluation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
steering_context
|
SteeringContext
|
Steering context with populated data |
required |
tool_use
|
ToolUse | None
|
Tool use object for tool call events (None for other events) |
None
|
**kwargs
|
Any
|
Additional event data for other steering events |
{}
|
Returns:
| Type | Description |
|---|---|
str
|
Formatted prompt string for LLM evaluation |
Source code in strands/experimental/steering/handlers/llm/mappers.py
71 72 73 74 75 76 77 78 79 80 81 82 83 84 | |
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 | |
ToolUse
¶
Bases: TypedDict
A request from the model to use a specific tool with the provided input.
Attributes:
| Name | Type | Description |
|---|---|---|
input |
Any
|
The input parameters for the tool. Can be any JSON-serializable type. |
name |
str
|
The name of the tool to invoke. |
toolUseId |
str
|
A unique identifier for this specific tool use request. |
Source code in strands/types/tools.py
52 53 54 55 56 57 58 59 60 61 62 63 64 | |