Skip to content

Commit 62534de

Browse files
test(steering): adjust integ test system prompts to reduce flakiness (#1282)
1 parent 50969a4 commit 62534de

File tree

2 files changed

+20
-12
lines changed

2 files changed

+20
-12
lines changed

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

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,13 @@ async def steer(self, agent: "Agent", tool_use: ToolUse, **kwargs: Any) -> Steer
8383
)
8484

8585
# Convert LLM decision to steering action
86-
if llm_result.decision == "proceed":
87-
return Proceed(reason=llm_result.reason)
88-
elif llm_result.decision == "guide":
89-
return Guide(reason=llm_result.reason)
90-
elif llm_result.decision == "interrupt":
91-
return Interrupt(reason=llm_result.reason)
92-
else:
93-
logger.warning("decision=<%s> | unknown llm decision, defaulting to proceed", llm_result.decision) # type: ignore[unreachable]
94-
return Proceed(reason="Unknown LLM decision, defaulting to proceed")
86+
match llm_result.decision:
87+
case "proceed":
88+
return Proceed(reason=llm_result.reason)
89+
case "guide":
90+
return Guide(reason=llm_result.reason)
91+
case "interrupt":
92+
return Interrupt(reason=llm_result.reason)
93+
case _:
94+
logger.warning("decision=<%s> | uŹknown llm decision, defaulting to proceed", llm_result.decision) # type: ignore[unreachable]
95+
return Proceed(reason="Unknown LLM decision, defaulting to proceed")

tests_integ/steering/test_llm_handler.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@ def send_notification(recipient: str, message: str) -> str:
2222
@pytest.mark.asyncio
2323
async def test_llm_steering_handler_proceed():
2424
"""Test LLM handler returns Proceed effect."""
25-
handler = LLMSteeringHandler(system_prompt="Always allow send_notification calls. Return proceed decision.")
25+
handler = LLMSteeringHandler(
26+
system_prompt="You MUST always allow send_notification calls. ALWAYS return proceed decision. "
27+
"Never return guide or interrupt."
28+
)
2629

2730
agent = Agent(tools=[send_notification])
2831
tool_use = {"name": "send_notification", "input": {"recipient": "user", "message": "hello"}}
@@ -37,7 +40,8 @@ async def test_llm_steering_handler_guide():
3740
"""Test LLM handler returns Guide effect."""
3841
handler = LLMSteeringHandler(
3942
system_prompt=(
40-
"When agents try to send_email, guide them to use send_notification instead. Return GUIDE decision."
43+
"You MUST guide agents away from send_email to use send_notification instead. "
44+
"ALWAYS return guide decision for send_email. Never return proceed or interrupt for send_email."
4145
)
4246
)
4347

@@ -52,7 +56,10 @@ async def test_llm_steering_handler_guide():
5256
@pytest.mark.asyncio
5357
async def test_llm_steering_handler_interrupt():
5458
"""Test LLM handler returns Interrupt effect."""
55-
handler = LLMSteeringHandler(system_prompt="Require human input for all tool calls. Return interrupt decision.")
59+
handler = LLMSteeringHandler(
60+
system_prompt="You MUST require human input for ALL tool calls regardless of context. "
61+
"ALWAYS return interrupt decision. Never return proceed or guide."
62+
)
5663

5764
agent = Agent(tools=[send_email])
5865
tool_use = {"name": "send_email", "input": {"recipient": "user", "message": "hello"}}

0 commit comments

Comments
 (0)