-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Python: Expose forwardedProps to agents and tools via session metadata #5264
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
Open
moonbox3
wants to merge
5
commits into
microsoft:main
Choose a base branch
from
moonbox3:agent/fix-5239-1
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
2edaa0a
Expose forwarded_props to agents and tools via session metadata (#5239)
786f382
fix(ag-ui): pass stream=True as literal to satisfy pyright overload r…
8513531
fix: address PR review feedback for forwarded_props (#5239)
eff3240
test: add stream=True assertions to CapturingWorkflow tests (#5239)
1f12ae4
Address review feedback for #5239: Python: Expose forwardedProps to a…
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
83 changes: 83 additions & 0 deletions
83
python/packages/ag-ui/tests/ag_ui/test_forwarded_props_in_metadata.py
|
moonbox3 marked this conversation as resolved.
|
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 |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| # Copyright (c) Microsoft. All rights reserved. | ||
|
|
||
| """Tests for forwarded_props inclusion in AG-UI session metadata.""" | ||
|
|
||
| import json | ||
| from typing import Any | ||
|
|
||
| from agent_framework_ag_ui._agent_run import AG_UI_INTERNAL_METADATA_KEYS, _build_safe_metadata | ||
|
|
||
|
|
||
| class TestForwardedPropsInSessionMetadata: | ||
| """Verify that forwarded_props is surfaced in session metadata and filtered from LLM metadata.""" | ||
|
|
||
| def test_forwarded_props_in_internal_metadata_keys(self): | ||
| """forwarded_props is listed in AG_UI_INTERNAL_METADATA_KEYS to prevent LLM leakage.""" | ||
| assert "forwarded_props" in AG_UI_INTERNAL_METADATA_KEYS | ||
|
|
||
| def test_forwarded_props_filtered_from_client_metadata(self): | ||
| """forwarded_props is filtered out when building LLM-bound client metadata.""" | ||
| session_metadata: dict[str, Any] = { | ||
| "ag_ui_thread_id": "t1", | ||
| "ag_ui_run_id": "r1", | ||
| "forwarded_props": '{"custom_flag": true}', | ||
| } | ||
|
|
||
| client_metadata = {k: v for k, v in session_metadata.items() if k not in AG_UI_INTERNAL_METADATA_KEYS} | ||
|
|
||
| assert "forwarded_props" not in client_metadata | ||
| assert "ag_ui_thread_id" not in client_metadata | ||
|
|
||
|
|
||
| class TestBuildSafeMetadata: | ||
| """Verify _build_safe_metadata handles various value types correctly.""" | ||
|
|
||
| def test_string_value_unchanged(self): | ||
| result = _build_safe_metadata({"key": "hello"}) | ||
| assert result == {"key": "hello"} | ||
|
|
||
| def test_dict_value_serialized_to_json(self): | ||
| result = _build_safe_metadata({"fp": {"flag": True, "source": "frontend"}}) | ||
| assert "fp" in result | ||
| assert isinstance(result["fp"], str) | ||
| # Must be valid, decodable JSON | ||
| decoded = json.loads(result["fp"]) | ||
| assert decoded == {"flag": True, "source": "frontend"} | ||
|
|
||
| def test_empty_dict_serialized_to_json(self): | ||
| result = _build_safe_metadata({"fp": {}}) | ||
| assert result["fp"] == "{}" | ||
| assert json.loads(result["fp"]) == {} | ||
|
|
||
| def test_value_within_limit_kept(self): | ||
| value = "x" * 512 | ||
| result = _build_safe_metadata({"key": value}) | ||
| assert result["key"] == value | ||
|
|
||
| def test_value_exceeding_limit_dropped(self): | ||
| """Values exceeding 512 chars are dropped entirely (not truncated).""" | ||
| value = "x" * 513 | ||
| result = _build_safe_metadata({"key": value}) | ||
| assert "key" not in result | ||
|
|
||
| def test_json_value_exceeding_limit_dropped(self): | ||
| """JSON-serialized dict exceeding 512 chars is dropped, not truncated into invalid JSON.""" | ||
| big_dict = {f"key_{i}": "v" * 100 for i in range(50)} | ||
| result = _build_safe_metadata({"forwarded_props": big_dict}) | ||
| assert "forwarded_props" not in result | ||
|
|
||
| def test_other_keys_preserved_when_one_dropped(self): | ||
| """Dropping one oversized key does not affect other keys.""" | ||
| result = _build_safe_metadata( | ||
| { | ||
| "small": "ok", | ||
| "big": "x" * 600, | ||
| } | ||
| ) | ||
| assert result == {"small": "ok"} | ||
|
|
||
| def test_none_input_returns_empty(self): | ||
| assert _build_safe_metadata(None) == {} | ||
|
|
||
| def test_empty_input_returns_empty(self): | ||
| assert _build_safe_metadata({}) == {} |
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
Oops, something went wrong.
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.