Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 14f7c98

Browse files
author
Dennis Tsai (RD-AS)
committed
test: Add system message ordering validation to agent structured output test
1 parent 11bf851 commit 14f7c98

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

tests/strands/agent/test_agent.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
from strands.handlers.callback_handler import PrintingCallbackHandler, null_callback_handler
1919
from strands.models.bedrock import DEFAULT_BEDROCK_MODEL_ID, BedrockModel
2020
from strands.session.repository_session_manager import RepositorySessionManager
21+
from strands.telemetry.tracer import serialize
2122
from strands.types.content import Messages
2223
from strands.types.exceptions import ContextWindowOverflowException, EventLoopException
2324
from strands.types.session import Session, SessionAgent, SessionMessage, SessionType
@@ -1028,6 +1029,23 @@ def test_agent_structured_output(agent, system_prompt, user, agenerator):
10281029
}
10291030
)
10301031

1032+
if system_prompt:
1033+
mock_span.add_event.assert_any_call(
1034+
"gen_ai.system.message",
1035+
attributes={"role": "system", "content": serialize([{"text": system_prompt}])},
1036+
)
1037+
1038+
calls = mock_span.add_event.call_args_list
1039+
system_call_index = None
1040+
user_call_index = None
1041+
1042+
for i, call in enumerate(calls):
1043+
if call[0][0] == "gen_ai.system.message":
1044+
system_call_index = i
1045+
elif call[0][0] == "gen_ai.user.message" and user_call_index is None:
1046+
user_call_index = i
1047+
assert system_call_index < user_call_index, "gen_ai.system.message should come before gen_ai.user.message"
1048+
10311049
mock_span.add_event.assert_any_call(
10321050
"gen_ai.user.message",
10331051
attributes={"role": "user", "content": '[{"text": "Jane Doe is 30 years old and her email is [email protected]"}]'},

0 commit comments

Comments
 (0)