Skip to content

Commit 4e4534e

Browse files
authored
test(steering): Fix failing integ tests (#1580)
1 parent f814458 commit 4e4534e

5 files changed

Lines changed: 18 additions & 9 deletions

File tree

src/strands/experimental/steering/core/handler.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,7 @@ def _handle_tool_steering_action(
115115
logger.debug("tool_name=<%s> | tool call proceeding", tool_name)
116116
elif isinstance(action, Guide):
117117
logger.debug("tool_name=<%s> | tool call guided: %s", tool_name, action.reason)
118-
event.cancel_tool = (
119-
f"Tool call cancelled given new guidance. {action.reason}. Consider this approach and continue"
120-
)
118+
event.cancel_tool = f"Tool call cancelled. {action.reason} You MUST follow this guidance immediately."
121119
elif isinstance(action, Interrupt):
122120
logger.debug("tool_name=<%s> | tool call requires human input: %s", tool_name, action.reason)
123121
can_proceed: bool = event.interrupt(name=f"steering_input_{tool_name}", reason={"message": action.reason})

src/strands/experimental/steering/handlers/llm/llm_handler.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,13 @@ def __init__(
5050
system_prompt: System prompt defining steering guidance rules
5151
prompt_mapper: Custom prompt mapper for evaluation prompts
5252
model: Optional model override for steering evaluation
53-
context_providers: List of context providers for populating steering context
53+
context_providers: List of context providers for populating steering context.
54+
Defaults to [LedgerProvider()] if None. Pass an empty list to disable
55+
context providers.
5456
"""
55-
providers = context_providers or [LedgerProvider()]
57+
providers: list[SteeringContextProvider] = (
58+
[LedgerProvider()] if context_providers is None else context_providers
59+
)
5660
super().__init__(context_providers=providers)
5761
self.system_prompt = system_prompt
5862
self.prompt_mapper = prompt_mapper or DefaultPromptMapper()

tests/strands/agent/test_agent_result.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,4 +370,3 @@ def test__str__empty_interrupts_returns_agent_message(mock_metrics, simple_messa
370370

371371
# Empty list is falsy, should fall through to text content
372372
assert message_string == "Hello world!\n"
373-

tests/strands/experimental/steering/core/test_handler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ async def steer_before_tool(self, *, agent, tool_use, **kwargs):
9595
await handler._provide_tool_steering_guidance(event)
9696

9797
# Should set cancel_tool with guidance message
98-
expected_message = "Tool call cancelled given new guidance. Test guidance. Consider this approach and continue"
98+
expected_message = "Tool call cancelled. Test guidance You MUST follow this guidance immediately."
9999
assert event.cancel_tool == expected_message
100100

101101

tests_integ/steering/test_tool_steering.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,16 @@ def test_agent_with_tool_steering_e2e():
7575
"""End-to-end test of agent with steering handler guiding tool choice."""
7676
handler = LLMSteeringHandler(
7777
system_prompt=(
78-
"When agents try to use send_email, guide them to use send_notification instead for better delivery."
79-
)
78+
"CRITICAL INSTRUCTION - READ CAREFULLY:\n\n"
79+
"You are a steering agent. Your ONLY job is to decide based on the tool name.\n\n"
80+
"RULE 1: If tool name is 'send_email' -> return decision='guide' with "
81+
"reason='Use send_notification instead of send_email for better delivery.'\n\n"
82+
"RULE 2: If tool name is 'send_notification' -> return decision='proceed'\n\n"
83+
"RULE 3: For any other tool -> return decision='proceed'\n\n"
84+
"DO NOT analyze context. DO NOT consider arguments. ONLY look at the tool name.\n"
85+
"The tool name in this request is the ONLY thing that matters."
86+
),
87+
context_providers=[], # Disable ledger to avoid confusing context
8088
)
8189

8290
agent = Agent(tools=[send_email, send_notification], hooks=[handler])

0 commit comments

Comments
 (0)