generated from amazon-archives/__template_Apache-2.0
-
Couldn't load subscription status.
- Fork 451
feat: add structured_output_span #655
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
poshinchen
merged 2 commits into
strands-agents:main
from
poshinchen:feat/add-structure-output-span
Aug 13, 2025
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -980,6 +980,14 @@ def test_agent_callback_handler_custom_handler_used(): | |
|
|
||
|
|
||
| def test_agent_structured_output(agent, system_prompt, user, agenerator): | ||
| # Setup mock tracer and span | ||
| mock_strands_tracer = unittest.mock.MagicMock() | ||
| mock_otel_tracer = unittest.mock.MagicMock() | ||
| mock_span = unittest.mock.MagicMock() | ||
| mock_strands_tracer.tracer = mock_otel_tracer | ||
| mock_otel_tracer.start_as_current_span.return_value.__enter__.return_value = mock_span | ||
| agent.tracer = mock_strands_tracer | ||
|
|
||
| agent.model.structured_output = unittest.mock.Mock(return_value=agenerator([{"output": user}])) | ||
|
|
||
| prompt = "Jane Doe is 30 years old and her email is [email protected]" | ||
|
|
@@ -999,8 +1007,34 @@ def test_agent_structured_output(agent, system_prompt, user, agenerator): | |
| type(user), [{"role": "user", "content": [{"text": prompt}]}], system_prompt=system_prompt | ||
| ) | ||
|
|
||
| mock_span.set_attributes.assert_called_once_with( | ||
| { | ||
| "gen_ai.system": "strands-agents", | ||
| "gen_ai.agent.name": "Strands Agents", | ||
| "gen_ai.agent.id": "default", | ||
| "gen_ai.operation.name": "execute_structured_output", | ||
| } | ||
| ) | ||
|
|
||
| mock_span.add_event.assert_any_call( | ||
| "gen_ai.user.message", | ||
| attributes={"role": "user", "content": '[{"text": "Jane Doe is 30 years old and her email is [email protected]"}]'}, | ||
| ) | ||
|
|
||
| mock_span.add_event.assert_called_with( | ||
| "gen_ai.choice", | ||
| attributes={"message": json.dumps(user.model_dump())}, | ||
| ) | ||
|
|
||
|
|
||
| def test_agent_structured_output_multi_modal_input(agent, system_prompt, user, agenerator): | ||
| # Setup mock tracer and span | ||
| mock_strands_tracer = unittest.mock.MagicMock() | ||
| mock_otel_tracer = unittest.mock.MagicMock() | ||
| mock_span = unittest.mock.MagicMock() | ||
| mock_strands_tracer.tracer = mock_otel_tracer | ||
| mock_otel_tracer.start_as_current_span.return_value.__enter__.return_value = mock_span | ||
| agent.tracer = mock_strands_tracer | ||
| agent.model.structured_output = unittest.mock.Mock(return_value=agenerator([{"output": user}])) | ||
|
|
||
| prompt = [ | ||
|
|
@@ -1030,6 +1064,11 @@ def test_agent_structured_output_multi_modal_input(agent, system_prompt, user, a | |
| type(user), [{"role": "user", "content": prompt}], system_prompt=system_prompt | ||
| ) | ||
|
|
||
| mock_span.add_event.assert_called_with( | ||
| "gen_ai.choice", | ||
| attributes={"message": json.dumps(user.model_dump())}, | ||
| ) | ||
|
|
||
|
|
||
| @pytest.mark.asyncio | ||
| async def test_agent_structured_output_in_async_context(agent, user, agenerator): | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.