|
18 | 18 | from strands.handlers.callback_handler import PrintingCallbackHandler, null_callback_handler
|
19 | 19 | from strands.models.bedrock import DEFAULT_BEDROCK_MODEL_ID, BedrockModel
|
20 | 20 | from strands.session.repository_session_manager import RepositorySessionManager
|
| 21 | +from strands.telemetry.tracer import serialize |
21 | 22 | from strands.types.content import Messages
|
22 | 23 | from strands.types.exceptions import ContextWindowOverflowException, EventLoopException
|
23 | 24 | from strands.types.session import Session, SessionAgent, SessionMessage, SessionType
|
@@ -1028,15 +1029,23 @@ def test_agent_structured_output(agent, system_prompt, user, agenerator):
|
1028 | 1029 | }
|
1029 | 1030 | )
|
1030 | 1031 |
|
1031 |
| - mock_span.add_event.assert_any_call( |
1032 |
| - "gen_ai.user.message", |
1033 |
| - attributes={ "role": "user", "content": '[{"text": "Jane Doe is 30 years old and her email is [email protected]"}]'}, |
1034 |
| - ) |
| 1032 | + # ensure correct otel event messages are emitted |
| 1033 | + act_event_names = mock_span.add_event.call_args_list |
| 1034 | + exp_event_names = [ |
| 1035 | + unittest.mock.call( |
| 1036 | + "gen_ai.system.message", attributes={"role": "system", "content": serialize([{"text": system_prompt}])} |
| 1037 | + ), |
| 1038 | + unittest.mock.call( |
| 1039 | + "gen_ai.user.message", |
| 1040 | + attributes={ |
| 1041 | + "role": "user", |
| 1042 | + "content": '[{"text": "Jane Doe is 30 years old and her email is [email protected]"}]', |
| 1043 | + }, |
| 1044 | + ), |
| 1045 | + unittest.mock.call("gen_ai.choice", attributes={"message": json.dumps(user.model_dump())}), |
| 1046 | + ] |
1035 | 1047 |
|
1036 |
| - mock_span.add_event.assert_called_with( |
1037 |
| - "gen_ai.choice", |
1038 |
| - attributes={"message": json.dumps(user.model_dump())}, |
1039 |
| - ) |
| 1048 | + assert act_event_names == exp_event_names |
1040 | 1049 |
|
1041 | 1050 |
|
1042 | 1051 | def test_agent_structured_output_multi_modal_input(agent, system_prompt, user, agenerator):
|
|
0 commit comments