mirror of
https://github.com/microsoft/agent-framework.git
synced 2026-06-16 21:04:09 +08:00
Python: Expose forwardedProps to agents and tools via session metadata (#5264)
* Expose forwarded_props to agents and tools via session metadata (#5239) Include forwarded_props from AG-UI request input_data in session.metadata (agent runner) and function_invocation_kwargs (workflow runner) so that agents, tools, and workflow executors can access request-level metadata such as invocation source flags from CopilotKit. - Add forwarded_props to base_metadata in _agent_run.py when present - Add 'forwarded_props' to AG_UI_INTERNAL_METADATA_KEYS to filter it from LLM-bound client metadata - Extract forwarded_props in _workflow_run.py and pass via function_invocation_kwargs to workflow.run() - Accept both snake_case and camelCase keys (forwarded_props/forwardedProps) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * fix(ag-ui): pass stream=True as literal to satisfy pyright overload resolution (#5239) The previous fix passed stream=True via **kwargs dict, which prevented pyright from resolving the Workflow.run() overload to the streaming variant. Pass stream=True as an explicit keyword argument so pyright can correctly infer the ResponseStream return type. Also remove unused pytest import in test file. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * fix: address PR review feedback for forwarded_props (#5239) - Use key-presence checks instead of truthiness for forwarded_props so empty dict {} is forwarded correctly - Gate function_invocation_kwargs on workflow.run() signature inspection to avoid TypeError for workflows without **kwargs - Change _build_safe_metadata to drop (with warning) keys whose serialized values exceed 512 chars instead of truncating into invalid JSON - Rewrite metadata tests to exercise _build_safe_metadata directly with JSON-decodability and truncation assertions - Add workflow tests for empty dict forwarded_props, stream=True assertion, and signature-gated kwarg dropping Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * test: add stream=True assertions to CapturingWorkflow tests (#5239) Guard against accidental removal of the explicit stream=True kwarg in all forwarded_props CapturingWorkflow test cases. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Address review feedback for #5239: Python: Expose forwardedProps to agents and tools via session metadata --------- Co-authored-by: Copilot <copilot@github.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
co-authored by
Copilot
Copilot
parent
04aaf0c1fe
commit
07f4c8a8d6
@@ -63,12 +63,12 @@ class TestBuildSafeMetadata:
|
||||
result = _build_safe_metadata(metadata)
|
||||
assert result == metadata
|
||||
|
||||
def test_truncates_long_strings(self):
|
||||
"""Truncates strings over 512 chars."""
|
||||
def test_drops_long_strings(self):
|
||||
"""Drops strings over 512 chars instead of truncating."""
|
||||
long_value = "x" * 1000
|
||||
metadata = {"key": long_value}
|
||||
result = _build_safe_metadata(metadata)
|
||||
assert len(result["key"]) == 512
|
||||
assert "key" not in result
|
||||
|
||||
def test_serializes_non_strings(self):
|
||||
"""Serializes non-string values to JSON."""
|
||||
@@ -77,12 +77,12 @@ class TestBuildSafeMetadata:
|
||||
assert result["count"] == "42"
|
||||
assert result["items"] == "[1, 2, 3]"
|
||||
|
||||
def test_truncates_serialized_values(self):
|
||||
"""Truncates serialized values over 512 chars."""
|
||||
def test_drops_oversized_serialized_values(self):
|
||||
"""Drops serialized values over 512 chars instead of truncating."""
|
||||
long_list = list(range(200))
|
||||
metadata = {"data": long_list}
|
||||
result = _build_safe_metadata(metadata)
|
||||
assert len(result["data"]) == 512
|
||||
assert "data" not in result
|
||||
|
||||
|
||||
class TestHasOnlyToolCalls:
|
||||
|
||||
Reference in New Issue
Block a user