agent-framework-core 1.20.0__tar.gz → 1.21.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (112) hide show
  1. {agent_framework_core-1.20.0 → agent_framework_core-1.21.0}/PKG-INFO +18 -18
  2. {agent_framework_core-1.20.0 → agent_framework_core-1.21.0}/agent_framework/_agent_hooks.py +2 -38
  3. {agent_framework_core-1.20.0 → agent_framework_core-1.21.0}/agent_framework/_agents.py +47 -4
  4. {agent_framework_core-1.20.0 → agent_framework_core-1.21.0}/agent_framework/_harness/_file_access.py +54 -10
  5. {agent_framework_core-1.20.0 → agent_framework_core-1.21.0}/agent_framework/_harness/_file_memory.py +9 -9
  6. {agent_framework_core-1.20.0 → agent_framework_core-1.21.0}/agent_framework/_middleware.py +32 -0
  7. {agent_framework_core-1.20.0 → agent_framework_core-1.21.0}/agent_framework/_tools.py +476 -143
  8. {agent_framework_core-1.20.0 → agent_framework_core-1.21.0}/agent_framework/_types.py +227 -44
  9. {agent_framework_core-1.20.0 → agent_framework_core-1.21.0}/agent_framework/security.py +310 -11
  10. {agent_framework_core-1.20.0 → agent_framework_core-1.21.0}/pyproject.toml +18 -18
  11. {agent_framework_core-1.20.0 → agent_framework_core-1.21.0}/LICENSE +0 -0
  12. {agent_framework_core-1.20.0 → agent_framework_core-1.21.0}/README.md +0 -0
  13. {agent_framework_core-1.20.0 → agent_framework_core-1.21.0}/agent_framework/__init__.py +0 -0
  14. {agent_framework_core-1.20.0 → agent_framework_core-1.21.0}/agent_framework/__init__.pyi +0 -0
  15. {agent_framework_core-1.20.0 → agent_framework_core-1.21.0}/agent_framework/_clients.py +0 -0
  16. {agent_framework_core-1.20.0 → agent_framework_core-1.21.0}/agent_framework/_compaction.py +0 -0
  17. {agent_framework_core-1.20.0 → agent_framework_core-1.21.0}/agent_framework/_docstrings.py +0 -0
  18. {agent_framework_core-1.20.0 → agent_framework_core-1.21.0}/agent_framework/_evaluation.py +0 -0
  19. {agent_framework_core-1.20.0 → agent_framework_core-1.21.0}/agent_framework/_feature_stage.py +0 -0
  20. {agent_framework_core-1.20.0 → agent_framework_core-1.21.0}/agent_framework/_filesystem.py +0 -0
  21. {agent_framework_core-1.20.0 → agent_framework_core-1.21.0}/agent_framework/_harness/__init__.py +0 -0
  22. {agent_framework_core-1.20.0 → agent_framework_core-1.21.0}/agent_framework/_harness/_agent.py +0 -0
  23. {agent_framework_core-1.20.0 → agent_framework_core-1.21.0}/agent_framework/_harness/_agent.pyi +0 -0
  24. {agent_framework_core-1.20.0 → agent_framework_core-1.21.0}/agent_framework/_harness/_background_agents.py +0 -0
  25. {agent_framework_core-1.20.0 → agent_framework_core-1.21.0}/agent_framework/_harness/_loop.py +0 -0
  26. {agent_framework_core-1.20.0 → agent_framework_core-1.21.0}/agent_framework/_harness/_memory.py +0 -0
  27. {agent_framework_core-1.20.0 → agent_framework_core-1.21.0}/agent_framework/_harness/_mode.py +0 -0
  28. {agent_framework_core-1.20.0 → agent_framework_core-1.21.0}/agent_framework/_harness/_todo.py +0 -0
  29. {agent_framework_core-1.20.0 → agent_framework_core-1.21.0}/agent_framework/_harness/_tool_approval.py +0 -0
  30. {agent_framework_core-1.20.0 → agent_framework_core-1.21.0}/agent_framework/_in_memory.py +0 -0
  31. {agent_framework_core-1.20.0 → agent_framework_core-1.21.0}/agent_framework/_mcp.py +0 -0
  32. {agent_framework_core-1.20.0 → agent_framework_core-1.21.0}/agent_framework/_serialization.py +0 -0
  33. {agent_framework_core-1.20.0 → agent_framework_core-1.21.0}/agent_framework/_sessions.py +0 -0
  34. {agent_framework_core-1.20.0 → agent_framework_core-1.21.0}/agent_framework/_settings.py +0 -0
  35. {agent_framework_core-1.20.0 → agent_framework_core-1.21.0}/agent_framework/_skills.py +0 -0
  36. {agent_framework_core-1.20.0 → agent_framework_core-1.21.0}/agent_framework/_telemetry.py +0 -0
  37. {agent_framework_core-1.20.0 → agent_framework_core-1.21.0}/agent_framework/_vector_filters.py +0 -0
  38. {agent_framework_core-1.20.0 → agent_framework_core-1.21.0}/agent_framework/_vectors.py +0 -0
  39. {agent_framework_core-1.20.0 → agent_framework_core-1.21.0}/agent_framework/_workflows/__init__.py +0 -0
  40. {agent_framework_core-1.20.0 → agent_framework_core-1.21.0}/agent_framework/_workflows/_agent.py +0 -0
  41. {agent_framework_core-1.20.0 → agent_framework_core-1.21.0}/agent_framework/_workflows/_agent_executor.py +0 -0
  42. {agent_framework_core-1.20.0 → agent_framework_core-1.21.0}/agent_framework/_workflows/_agent_utils.py +0 -0
  43. {agent_framework_core-1.20.0 → agent_framework_core-1.21.0}/agent_framework/_workflows/_checkpoint.py +0 -0
  44. {agent_framework_core-1.20.0 → agent_framework_core-1.21.0}/agent_framework/_workflows/_checkpoint_encoding.py +0 -0
  45. {agent_framework_core-1.20.0 → agent_framework_core-1.21.0}/agent_framework/_workflows/_const.py +0 -0
  46. {agent_framework_core-1.20.0 → agent_framework_core-1.21.0}/agent_framework/_workflows/_conversation_history.py +0 -0
  47. {agent_framework_core-1.20.0 → agent_framework_core-1.21.0}/agent_framework/_workflows/_edge.py +0 -0
  48. {agent_framework_core-1.20.0 → agent_framework_core-1.21.0}/agent_framework/_workflows/_edge_runner.py +0 -0
  49. {agent_framework_core-1.20.0 → agent_framework_core-1.21.0}/agent_framework/_workflows/_events.py +0 -0
  50. {agent_framework_core-1.20.0 → agent_framework_core-1.21.0}/agent_framework/_workflows/_executor.py +0 -0
  51. {agent_framework_core-1.20.0 → agent_framework_core-1.21.0}/agent_framework/_workflows/_function_executor.py +0 -0
  52. {agent_framework_core-1.20.0 → agent_framework_core-1.21.0}/agent_framework/_workflows/_functional.py +0 -0
  53. {agent_framework_core-1.20.0 → agent_framework_core-1.21.0}/agent_framework/_workflows/_message_utils.py +0 -0
  54. {agent_framework_core-1.20.0 → agent_framework_core-1.21.0}/agent_framework/_workflows/_model_utils.py +0 -0
  55. {agent_framework_core-1.20.0 → agent_framework_core-1.21.0}/agent_framework/_workflows/_request_info_mixin.py +0 -0
  56. {agent_framework_core-1.20.0 → agent_framework_core-1.21.0}/agent_framework/_workflows/_runner.py +0 -0
  57. {agent_framework_core-1.20.0 → agent_framework_core-1.21.0}/agent_framework/_workflows/_runner_context.py +0 -0
  58. {agent_framework_core-1.20.0 → agent_framework_core-1.21.0}/agent_framework/_workflows/_state.py +0 -0
  59. {agent_framework_core-1.20.0 → agent_framework_core-1.21.0}/agent_framework/_workflows/_typing_utils.py +0 -0
  60. {agent_framework_core-1.20.0 → agent_framework_core-1.21.0}/agent_framework/_workflows/_validation.py +0 -0
  61. {agent_framework_core-1.20.0 → agent_framework_core-1.21.0}/agent_framework/_workflows/_viz.py +0 -0
  62. {agent_framework_core-1.20.0 → agent_framework_core-1.21.0}/agent_framework/_workflows/_workflow.py +0 -0
  63. {agent_framework_core-1.20.0 → agent_framework_core-1.21.0}/agent_framework/_workflows/_workflow_builder.py +0 -0
  64. {agent_framework_core-1.20.0 → agent_framework_core-1.21.0}/agent_framework/_workflows/_workflow_context.py +0 -0
  65. {agent_framework_core-1.20.0 → agent_framework_core-1.21.0}/agent_framework/_workflows/_workflow_executor.py +0 -0
  66. {agent_framework_core-1.20.0 → agent_framework_core-1.21.0}/agent_framework/a2a/__init__.py +0 -0
  67. {agent_framework_core-1.20.0 → agent_framework_core-1.21.0}/agent_framework/a2a/__init__.pyi +0 -0
  68. {agent_framework_core-1.20.0 → agent_framework_core-1.21.0}/agent_framework/ag_ui/__init__.py +0 -0
  69. {agent_framework_core-1.20.0 → agent_framework_core-1.21.0}/agent_framework/ag_ui/__init__.pyi +0 -0
  70. {agent_framework_core-1.20.0 → agent_framework_core-1.21.0}/agent_framework/amazon/__init__.py +0 -0
  71. {agent_framework_core-1.20.0 → agent_framework_core-1.21.0}/agent_framework/amazon/__init__.pyi +0 -0
  72. {agent_framework_core-1.20.0 → agent_framework_core-1.21.0}/agent_framework/anthropic/__init__.py +0 -0
  73. {agent_framework_core-1.20.0 → agent_framework_core-1.21.0}/agent_framework/anthropic/__init__.pyi +0 -0
  74. {agent_framework_core-1.20.0 → agent_framework_core-1.21.0}/agent_framework/azure/__init__.py +0 -0
  75. {agent_framework_core-1.20.0 → agent_framework_core-1.21.0}/agent_framework/azure/__init__.pyi +0 -0
  76. {agent_framework_core-1.20.0 → agent_framework_core-1.21.0}/agent_framework/chatkit/__init__.py +0 -0
  77. {agent_framework_core-1.20.0 → agent_framework_core-1.21.0}/agent_framework/chatkit/__init__.pyi +0 -0
  78. {agent_framework_core-1.20.0 → agent_framework_core-1.21.0}/agent_framework/declarative/__init__.py +0 -0
  79. {agent_framework_core-1.20.0 → agent_framework_core-1.21.0}/agent_framework/declarative/__init__.pyi +0 -0
  80. {agent_framework_core-1.20.0 → agent_framework_core-1.21.0}/agent_framework/devui/__init__.py +0 -0
  81. {agent_framework_core-1.20.0 → agent_framework_core-1.21.0}/agent_framework/devui/__init__.pyi +0 -0
  82. {agent_framework_core-1.20.0 → agent_framework_core-1.21.0}/agent_framework/exceptions.py +0 -0
  83. {agent_framework_core-1.20.0 → agent_framework_core-1.21.0}/agent_framework/foundry/__init__.py +0 -0
  84. {agent_framework_core-1.20.0 → agent_framework_core-1.21.0}/agent_framework/foundry/__init__.pyi +0 -0
  85. {agent_framework_core-1.20.0 → agent_framework_core-1.21.0}/agent_framework/gemini/__init__.py +0 -0
  86. {agent_framework_core-1.20.0 → agent_framework_core-1.21.0}/agent_framework/gemini/__init__.pyi +0 -0
  87. {agent_framework_core-1.20.0 → agent_framework_core-1.21.0}/agent_framework/github/__init__.py +0 -0
  88. {agent_framework_core-1.20.0 → agent_framework_core-1.21.0}/agent_framework/github/__init__.pyi +0 -0
  89. {agent_framework_core-1.20.0 → agent_framework_core-1.21.0}/agent_framework/google/__init__.py +0 -0
  90. {agent_framework_core-1.20.0 → agent_framework_core-1.21.0}/agent_framework/google/__init__.pyi +0 -0
  91. {agent_framework_core-1.20.0 → agent_framework_core-1.21.0}/agent_framework/hyperlight/__init__.py +0 -0
  92. {agent_framework_core-1.20.0 → agent_framework_core-1.21.0}/agent_framework/lab/__init__.py +0 -0
  93. {agent_framework_core-1.20.0 → agent_framework_core-1.21.0}/agent_framework/mem0/__init__.py +0 -0
  94. {agent_framework_core-1.20.0 → agent_framework_core-1.21.0}/agent_framework/mem0/__init__.pyi +0 -0
  95. {agent_framework_core-1.20.0 → agent_framework_core-1.21.0}/agent_framework/microsoft/__init__.py +0 -0
  96. {agent_framework_core-1.20.0 → agent_framework_core-1.21.0}/agent_framework/microsoft/__init__.pyi +0 -0
  97. {agent_framework_core-1.20.0 → agent_framework_core-1.21.0}/agent_framework/mistral/__init__.py +0 -0
  98. {agent_framework_core-1.20.0 → agent_framework_core-1.21.0}/agent_framework/mistral/__init__.pyi +0 -0
  99. {agent_framework_core-1.20.0 → agent_framework_core-1.21.0}/agent_framework/monty/__init__.py +0 -0
  100. {agent_framework_core-1.20.0 → agent_framework_core-1.21.0}/agent_framework/monty/__init__.pyi +0 -0
  101. {agent_framework_core-1.20.0 → agent_framework_core-1.21.0}/agent_framework/observability.py +0 -0
  102. {agent_framework_core-1.20.0 → agent_framework_core-1.21.0}/agent_framework/ollama/__init__.py +0 -0
  103. {agent_framework_core-1.20.0 → agent_framework_core-1.21.0}/agent_framework/ollama/__init__.pyi +0 -0
  104. {agent_framework_core-1.20.0 → agent_framework_core-1.21.0}/agent_framework/openai/__init__.py +0 -0
  105. {agent_framework_core-1.20.0 → agent_framework_core-1.21.0}/agent_framework/openai/__init__.pyi +0 -0
  106. {agent_framework_core-1.20.0 → agent_framework_core-1.21.0}/agent_framework/orchestrations/__init__.py +0 -0
  107. {agent_framework_core-1.20.0 → agent_framework_core-1.21.0}/agent_framework/orchestrations/__init__.pyi +0 -0
  108. {agent_framework_core-1.20.0 → agent_framework_core-1.21.0}/agent_framework/py.typed +0 -0
  109. {agent_framework_core-1.20.0 → agent_framework_core-1.21.0}/agent_framework/redis/__init__.py +0 -0
  110. {agent_framework_core-1.20.0 → agent_framework_core-1.21.0}/agent_framework/redis/__init__.pyi +0 -0
  111. {agent_framework_core-1.20.0 → agent_framework_core-1.21.0}/agent_framework/tools/__init__.py +0 -0
  112. {agent_framework_core-1.20.0 → agent_framework_core-1.21.0}/agent_framework/tools/__init__.pyi +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: agent-framework-core
3
- Version: 1.20.0
3
+ Version: 1.21.0
4
4
  Summary: Microsoft Agent Framework for building AI Agents with Python. This is the core package that has all the core abstractions and implementations.
5
5
  Author-email: Microsoft <af-support@microsoft.com>
6
6
  Requires-Python: >=3.10
@@ -25,34 +25,34 @@ Requires-Dist: pyyaml>=6.0,<7.0
25
25
  Requires-Dist: regex>=2024.11.6
26
26
  Requires-Dist: mcp>=1.24.0,<2 ; extra == "all"
27
27
  Requires-Dist: agent-framework-a2a>=1.0.0b261002,<2 ; extra == "all"
28
- Requires-Dist: agent-framework-ag-ui>=1.5.0,<2 ; extra == "all"
29
- Requires-Dist: agent-framework-anthropic>=1.0.0b261002,<2 ; extra == "all"
28
+ Requires-Dist: agent-framework-ag-ui>=1.5.1,<2 ; extra == "all"
29
+ Requires-Dist: agent-framework-anthropic>=1.0.0b261008,<2 ; extra == "all"
30
30
  Requires-Dist: agent-framework-azure-ai-search>=1.0.0b261002,<2 ; extra == "all"
31
- Requires-Dist: agent-framework-azure-contentunderstanding>=1.0.0b261002,<2 ; extra == "all"
31
+ Requires-Dist: agent-framework-azure-contentunderstanding>=1.0.0b261008,<2 ; extra == "all"
32
32
  Requires-Dist: agent-framework-azure-cosmos>=1.0.0b261002,<2 ; extra == "all"
33
33
  Requires-Dist: agent-framework-azurefunctions>=1.0.0b260922,<2 ; extra == "all"
34
- Requires-Dist: agent-framework-bedrock>=1.0.0b261002,<2 ; extra == "all"
34
+ Requires-Dist: agent-framework-bedrock>=1.0.0b261008,<2 ; extra == "all"
35
35
  Requires-Dist: agent-framework-chatkit>=1.0.0b261002,<2 ; extra == "all"
36
36
  Requires-Dist: agent-framework-claude>=1.0.0b261002,<2 ; extra == "all"
37
37
  Requires-Dist: agent-framework-copilotstudio>=1.0.0b261002,<2 ; extra == "all"
38
- Requires-Dist: agent-framework-declarative>=1.2.0,<2 ; extra == "all"
39
- Requires-Dist: agent-framework-devui>=1.0.0b261002,<2 ; extra == "all"
38
+ Requires-Dist: agent-framework-declarative>=1.2.1,<2 ; extra == "all"
39
+ Requires-Dist: agent-framework-devui>=1.0.0b261008,<2 ; extra == "all"
40
40
  Requires-Dist: agent-framework-durabletask>=1.0.0b260922,<2 ; extra == "all"
41
- Requires-Dist: agent-framework-foundry>=1.14.0,<2 ; extra == "all"
42
- Requires-Dist: agent-framework-foundry-hosting>=1.0.0b261002,<2 ; extra == "all"
41
+ Requires-Dist: agent-framework-foundry>=1.14.1,<2 ; extra == "all"
42
+ Requires-Dist: agent-framework-foundry-hosting>=1.0.0b261008,<2 ; extra == "all"
43
43
  Requires-Dist: agent-framework-foundry-local>=1.0.0b260730,<2 ; extra == "all"
44
- Requires-Dist: agent-framework-gemini>=1.0.0b261002,<2 ; extra == "all"
45
- Requires-Dist: agent-framework-github-copilot>=2.0.1,<3 ; extra == "all" and ( python_version >= '3.11')
46
- Requires-Dist: agent-framework-hyperlight>=1.0.0b261002,<2 ; extra == "all" and ( python_version < '3.15' and ((sys_platform == 'linux' and platform_machine == 'x86_64') or (sys_platform == 'win32' and platform_machine == 'AMD64')))
44
+ Requires-Dist: agent-framework-gemini>=1.0.0b261008,<2 ; extra == "all"
45
+ Requires-Dist: agent-framework-github-copilot>=2.0.2,<3 ; extra == "all" and ( python_version >= '3.11')
46
+ Requires-Dist: agent-framework-hyperlight>=1.0.0b261008,<2 ; extra == "all" and ( python_version < '3.15' and ((sys_platform == 'linux' and platform_machine == 'x86_64') or (sys_platform == 'win32' and platform_machine == 'AMD64')))
47
47
  Requires-Dist: agent-framework-mem0>=1.0.0b261002,<2 ; extra == "all"
48
48
  Requires-Dist: agent-framework-mistral>=1.0.0b260918,<2 ; extra == "all"
49
- Requires-Dist: agent-framework-monty>=1.0.0b261002,<2 ; extra == "all"
50
- Requires-Dist: agent-framework-ollama>=1.0.0b261002,<2 ; extra == "all"
51
- Requires-Dist: agent-framework-openai>=1.15.0,<2 ; extra == "all"
52
- Requires-Dist: agent-framework-orchestrations>=1.3.0,<2 ; extra == "all"
53
- Requires-Dist: agent-framework-purview>=1.0.0b261002,<2 ; extra == "all"
49
+ Requires-Dist: agent-framework-monty>=1.0.0b261008,<2 ; extra == "all"
50
+ Requires-Dist: agent-framework-ollama>=1.0.0b261008,<2 ; extra == "all"
51
+ Requires-Dist: agent-framework-openai>=1.16.0,<2 ; extra == "all"
52
+ Requires-Dist: agent-framework-orchestrations>=1.3.1,<2 ; extra == "all"
53
+ Requires-Dist: agent-framework-purview>=1.0.0b261008,<2 ; extra == "all"
54
54
  Requires-Dist: agent-framework-redis>=1.0.0b261002,<2 ; extra == "all" and ( python_version < '3.15')
55
- Requires-Dist: agent-framework-tools>=1.0.0b261002,<2 ; extra == "all"
55
+ Requires-Dist: agent-framework-tools>=1.0.0b261008,<2 ; extra == "all"
56
56
  Project-URL: homepage, https://aka.ms/agent-framework
57
57
  Project-URL: issues, https://github.com/microsoft/agent-framework/issues
58
58
  Project-URL: release_notes, https://github.com/microsoft/agent-framework/releases?q=tag%3Apython-1&expanded=true
@@ -825,42 +825,6 @@ class _OutputCodec:
825
825
  # region Enforcement helpers
826
826
 
827
827
 
828
- def _chat_updates_from_response(response: ChatResponse[Any]) -> list[ChatResponseUpdate]:
829
- """Re-derive stream updates from a (transformed) assembled chat response."""
830
- updates = [
831
- ChatResponseUpdate(
832
- contents=list(message.contents),
833
- role=cast(Any, message.role),
834
- author_name=message.author_name,
835
- message_id=message.message_id,
836
- response_id=response.response_id,
837
- model=response.model,
838
- )
839
- for message in response.messages
840
- ]
841
- if not updates:
842
- updates = [ChatResponseUpdate(role="assistant", response_id=response.response_id)]
843
- updates[-1].finish_reason = response.finish_reason
844
- return updates
845
-
846
-
847
- def _agent_updates_from_response(response: AgentResponse[Any]) -> list[AgentResponseUpdate]:
848
- """Re-derive stream updates from a (transformed) assembled agent response."""
849
- updates = [
850
- AgentResponseUpdate(
851
- contents=list(message.contents),
852
- role=message.role,
853
- author_name=message.author_name,
854
- message_id=message.message_id,
855
- response_id=response.response_id,
856
- )
857
- for message in response.messages
858
- ]
859
- if not updates:
860
- updates = [AgentResponseUpdate(role="assistant", response_id=response.response_id)]
861
- return updates
862
-
863
-
864
828
  def _normalized_tools(tools: Any, *, point: str) -> list[Any]:
865
829
  """Normalize a tools value for projection; empty (with a warning) when it cannot be.
866
830
 
@@ -1313,7 +1277,7 @@ class _AgentHooksAgentMiddleware(_AgentHooksMiddlewareBase, AgentMiddleware):
1313
1277
  await self._emit_shutdown(state, "cancelled" if isinstance(exc, asyncio.CancelledError) else "error")
1314
1278
 
1315
1279
  context._stream_terminal_result_transforms.append(_transform) # pyright: ignore[reportPrivateUsage]
1316
- context._stream_terminal_result_to_updates = _agent_updates_from_response # pyright: ignore[reportPrivateUsage]
1280
+ context._stream_terminal_result_to_updates = AgentResponse.to_updates # pyright: ignore[reportPrivateUsage]
1317
1281
  context._stream_terminal_result_is_authoritative = True # pyright: ignore[reportPrivateUsage]
1318
1282
  context._stream_release_hooks.append(_release) # pyright: ignore[reportPrivateUsage]
1319
1283
  context._stream_release_error_hooks.append(_release_error) # pyright: ignore[reportPrivateUsage]
@@ -1443,7 +1407,7 @@ class _AgentHooksChatMiddleware(_AgentHooksMiddlewareBase, ChatMiddleware):
1443
1407
  gate_handle.drop()
1444
1408
 
1445
1409
  context._stream_terminal_result_transforms.append(_transform) # pyright: ignore[reportPrivateUsage]
1446
- context._stream_terminal_result_to_updates = _chat_updates_from_response # pyright: ignore[reportPrivateUsage]
1410
+ context._stream_terminal_result_to_updates = ChatResponse.to_updates # pyright: ignore[reportPrivateUsage]
1447
1411
  context._stream_terminal_result_is_authoritative = True # pyright: ignore[reportPrivateUsage]
1448
1412
  context._stream_release_hooks.append(_release) # pyright: ignore[reportPrivateUsage]
1449
1413
  context._stream_release_error_hooks.append(_release_error) # pyright: ignore[reportPrivateUsage]
@@ -81,6 +81,8 @@ else:
81
81
  from typing_extensions import Self, TypedDict # pragma: no cover
82
82
 
83
83
  if TYPE_CHECKING:
84
+ from collections.abc import Collection
85
+
84
86
  from mcp import types
85
87
  from mcp.server.lowlevel import Server
86
88
  from pydantic import BaseModel
@@ -113,6 +115,17 @@ def _tool_approval_source_ids(middleware: Sequence[MiddlewareTypes] | None) -> f
113
115
  return frozenset(item.source_id for item in middleware if isinstance(item, ToolApprovalMiddleware))
114
116
 
115
117
 
118
+ def _provider_service_session_state_keys(agent: object) -> frozenset[str]:
119
+ """Return provider-owned session-state keys declared by an agent or its client."""
120
+ keys: set[str] = set()
121
+ # A generic Agent can use a provider client that persists its own continuation state.
122
+ for owner in (agent, getattr(agent, "client", None)):
123
+ declared = getattr(owner, "service_session_state_keys", ())
124
+ if isinstance(declared, (list, tuple, set, frozenset)):
125
+ keys.update(key for key in cast("Collection[Any]", declared) if isinstance(key, str))
126
+ return frozenset(keys)
127
+
128
+
116
129
  def _merge_delegated_session_state(
117
130
  parent_state: MutableMapping[str, Any],
118
131
  initial_child_state: Mapping[str, Any],
@@ -665,9 +678,10 @@ class BaseAgent(SerializationMixin):
665
678
  propagate_session: If True, the parent agent's session is forwarded
666
679
  to this sub-agent's ``run()`` call. Application-state changes
667
680
  propagate back to the parent, while framework approval continuation
668
- state remains isolated. Defaults to False. The sub-agent always
669
- receives an AgentSession so session-backed middleware can run.
670
- When False, that session is private to this invocation.
681
+ state and provider-owned service session state remain isolated.
682
+ Defaults to False. The sub-agent always receives an AgentSession
683
+ so session-backed middleware can run. When False, that session is
684
+ private to this invocation.
671
685
 
672
686
  Returns:
673
687
  A FunctionTool that can be used as a tool by other agents.
@@ -683,6 +697,10 @@ class BaseAgent(SerializationMixin):
683
697
  values. The delegated call raises ToolExecutionException before running
684
698
  the child when their shared session-state keys overlap.
685
699
 
700
+ Direct or custom-loop invocation with ``propagate_session=True`` must set
701
+ :attr:`FunctionInvocationContext.parent_service_session_state_keys` when
702
+ the parent session is non-empty. Automatic function calling supplies it.
703
+
686
704
  Examples:
687
705
  .. code-block:: python
688
706
 
@@ -733,10 +751,24 @@ class BaseAgent(SerializationMixin):
733
751
  session = AgentSession()
734
752
  child_approval_source_ids = _tool_approval_source_ids(self.middleware)
735
753
  parent_approval_source_ids: frozenset[str] = frozenset()
754
+ parent_service_session_state_keys: frozenset[str] = frozenset()
736
755
 
737
756
  if propagate_session and parent_session is not None:
738
757
  from ._tools import _PARENT_TOOL_APPROVAL_SOURCE_IDS_CONTEXT_KEY # pyright: ignore[reportPrivateUsage]
739
758
 
759
+ # A custom loop can bypass the framework seam that identifies the parent provider's state.
760
+ # Refuse a non-empty shared session rather than guessing which keys are safe to delegate.
761
+ if ctx.parent_service_session_state_keys is None:
762
+ if parent_session.state:
763
+ raise ToolExecutionException(
764
+ f"Agent tool {tool_name!r} cannot safely propagate a non-empty parent session because "
765
+ "the invocation path did not provide parent provider-owned session state keys. "
766
+ "Use the automatic function-calling loop, set "
767
+ "FunctionInvocationContext.parent_service_session_state_keys in a custom loop, "
768
+ "or set propagate_session=False."
769
+ )
770
+ else:
771
+ parent_service_session_state_keys = ctx.parent_service_session_state_keys
740
772
  raw_parent_approval_source_ids = ctx.metadata.get(_PARENT_TOOL_APPROVAL_SOURCE_IDS_CONTEXT_KEY)
741
773
  parent_approval_source_ids = (
742
774
  cast("frozenset[str]", raw_parent_approval_source_ids)
@@ -770,6 +802,10 @@ class BaseAgent(SerializationMixin):
770
802
  _TOOL_APPROVAL_STATE_KEY,
771
803
  _FUNCTION_INVOCATION_BUDGET_STATE_KEY,
772
804
  _FUNCTION_RESULT_PAYLOAD_BUDGET_STATE_KEY,
805
+ # Service handles belong to one agent's remote resources, not shared application state.
806
+ # Exclude them in both directions so later children cannot inherit an earlier child's handles.
807
+ *_provider_service_session_state_keys(self),
808
+ *parent_service_session_state_keys,
773
809
  *child_approval_source_ids,
774
810
  *parent_approval_source_ids,
775
811
  })
@@ -1589,7 +1625,10 @@ class RawAgent(BaseAgent, Generic[OptionsCoT]):
1589
1625
 
1590
1626
  agent_name = self._get_agent_name()
1591
1627
  from ._mcp import MCPTool
1592
- from ._tools import _PARENT_TOOL_APPROVAL_SOURCE_IDS_CONTEXT_KEY # pyright: ignore[reportPrivateUsage]
1628
+ from ._tools import (
1629
+ _PARENT_SERVICE_SESSION_STATE_KEYS_CONTEXT_KEY, # pyright: ignore[reportPrivateUsage]
1630
+ _PARENT_TOOL_APPROVAL_SOURCE_IDS_CONTEXT_KEY, # pyright: ignore[reportPrivateUsage]
1631
+ )
1593
1632
 
1594
1633
  base_tools = _normalize_tools(chat_options.pop("tools", None))
1595
1634
  mcp_duplicate_message = "Tool names must be unique. Consider setting `tool_name_prefix` on the MCPTool."
@@ -1637,6 +1676,10 @@ class RawAgent(BaseAgent, Generic[OptionsCoT]):
1637
1676
  additional_function_arguments[_PARENT_TOOL_APPROVAL_SOURCE_IDS_CONTEXT_KEY] = _tool_approval_source_ids(
1638
1677
  self.middleware
1639
1678
  )
1679
+ # Recompute ownership for this invoking agent; caller kwargs must not replace its declarations.
1680
+ additional_function_arguments[_PARENT_SERVICE_SESSION_STATE_KEYS_CONTEXT_KEY] = (
1681
+ _provider_service_session_state_keys(self)
1682
+ )
1640
1683
 
1641
1684
  model = opts.pop("model", None)
1642
1685
 
@@ -28,6 +28,8 @@ import logging
28
28
  import os
29
29
  import threading
30
30
  import time
31
+ import unicodedata
32
+ import weakref
31
33
  from abc import ABC, abstractmethod
32
34
  from collections.abc import Awaitable, Mapping, MutableMapping
33
35
  from pathlib import Path
@@ -1718,6 +1720,52 @@ class _SearchFilesInput(BaseModel):
1718
1720
  ] = None
1719
1721
 
1720
1722
 
1723
+ # Locks handed out by ``_store_write_lock``. Values are held weakly, so an entry lasts only while an
1724
+ # edit holds or awaits its lock, and the map never grows with the number of paths ever edited.
1725
+ _STORE_WRITE_LOCKS: weakref.WeakValueDictionary[tuple[int, asyncio.AbstractEventLoop, str], asyncio.Lock] = (
1726
+ weakref.WeakValueDictionary()
1727
+ )
1728
+
1729
+
1730
+ def _store_write_lock(store: AgentFileStore, folder: str) -> asyncio.Lock:
1731
+ """Return the lock that serializes edits of the files directly inside ``folder`` in ``store``.
1732
+
1733
+ Mutating tools hold it across their read-modify-write. It belongs to the store
1734
+ instance rather than to one provider, so two providers sharing a store cannot both
1735
+ read a file before either writes it back and silently drop one of the edits.
1736
+ File-access tools lock the folder of the file they edit (see ``_parent_folder``) and
1737
+ file-memory tools lock their working folder, so the two kinds of provider also wait
1738
+ for each other when they edit the same file. Edits of different files in one folder
1739
+ therefore run one at a time.
1740
+
1741
+ The folder name is folded to NFC and lowercased because a store can treat such
1742
+ spellings as one folder: :class:`InMemoryAgentFileStore` ignores case, and macOS
1743
+ file systems resolve the NFC and NFD forms of a name to one entry. Elsewhere two
1744
+ spellings merely share a lock.
1745
+
1746
+ Locks are per event loop, because an :class:`asyncio.Lock` that has had a waiter on
1747
+ one loop raises when a caller has to wait for it on another. The key holds
1748
+ ``id(store)`` rather than the store, so a store need not be hashable (a default
1749
+ ``@dataclass`` is not) and is never kept alive by this map; the id cannot be reused
1750
+ while its lock is in use, because whoever holds or awaits the lock still references
1751
+ the store.
1752
+
1753
+ The lock is process-local: other processes, and other store instances over the same
1754
+ backing storage, are not coordinated.
1755
+ """
1756
+ key = (id(store), asyncio.get_running_loop(), unicodedata.normalize("NFC", folder).lower())
1757
+ lock = _STORE_WRITE_LOCKS.get(key)
1758
+ if lock is None:
1759
+ lock = asyncio.Lock()
1760
+ _STORE_WRITE_LOCKS[key] = lock
1761
+ return lock
1762
+
1763
+
1764
+ def _parent_folder(path: str) -> str:
1765
+ """Return the folder of a normalized store path (``""`` for a file at the root)."""
1766
+ return path.rpartition("/")[0]
1767
+
1768
+
1721
1769
  @experimental(feature_id=ExperimentalFeature.HARNESS)
1722
1770
  class FileAccessProvider(ContextProvider):
1723
1771
  """Context provider that gives an agent CRUD/search access to a shared file store.
@@ -1878,12 +1926,6 @@ class FileAccessProvider(ContextProvider):
1878
1926
  self.disable_write_tool_approval = disable_write_tool_approval
1879
1927
  self.session_scoped = session_scoped
1880
1928
  self.scope = scope
1881
- # Serializes mutating tool operations (write/delete/replace/replace_lines).
1882
- # The provider is shared across sessions/agents, so read-modify-write tools
1883
- # (replace/replace_lines) could otherwise interleave and lose updates. Note
1884
- # this only serializes within a single event loop/process, not across
1885
- # processes sharing a FileSystemAgentFileStore on disk.
1886
- self._write_lock = asyncio.Lock()
1887
1929
 
1888
1930
  def _resolve_session_key(self, context: SessionContext) -> str:
1889
1931
  """Resolve the working folder key for session-scoped mode.
@@ -2036,7 +2078,9 @@ class FileAccessProvider(ContextProvider):
2036
2078
  try:
2037
2079
  normalized = _normalize_relative_path(file_name)
2038
2080
  store_path = _session_path(normalized)
2039
- async with self._write_lock:
2081
+ # Every mutating tool takes the lock of the file's folder, which all providers
2082
+ # on the store share, so a write cannot land between another edit's read and write.
2083
+ async with _store_write_lock(self.store, _parent_folder(store_path)):
2040
2084
  await self.store.write(store_path, content, overwrite=overwrite)
2041
2085
  except NotADirectoryError:
2042
2086
  return f"Could not write file '{file_name}': a parent path is already a file. Choose a different path."
@@ -2091,7 +2135,7 @@ class FileAccessProvider(ContextProvider):
2091
2135
  try:
2092
2136
  normalized = _normalize_relative_path(file_name)
2093
2137
  store_path = _session_path(normalized)
2094
- async with self._write_lock:
2138
+ async with _store_write_lock(self.store, _parent_folder(store_path)):
2095
2139
  deleted = await self.store.delete(store_path)
2096
2140
  except ValueError as exc:
2097
2141
  return f"Could not delete file '{file_name}': {exc}"
@@ -2132,7 +2176,7 @@ class FileAccessProvider(ContextProvider):
2132
2176
  try:
2133
2177
  normalized = _normalize_relative_path(file_name)
2134
2178
  store_path = _session_path(normalized)
2135
- async with self._write_lock:
2179
+ async with _store_write_lock(self.store, _parent_folder(store_path)):
2136
2180
  content = await self.store.read(store_path)
2137
2181
  if content is None:
2138
2182
  return f"File '{file_name}' not found."
@@ -2154,7 +2198,7 @@ class FileAccessProvider(ContextProvider):
2154
2198
  try:
2155
2199
  normalized = _normalize_relative_path(file_name)
2156
2200
  store_path = _session_path(normalized)
2157
- async with self._write_lock:
2201
+ async with _store_write_lock(self.store, _parent_folder(store_path)):
2158
2202
  content = await self.store.read(store_path)
2159
2203
  if content is None:
2160
2204
  return f"File '{file_name}' not found."
@@ -42,7 +42,6 @@ per-invocation :class:`~agent_framework.SessionContext` in
42
42
 
43
43
  from __future__ import annotations
44
44
 
45
- import asyncio
46
45
  import logging
47
46
  from typing import Annotated, Any
48
47
 
@@ -60,6 +59,7 @@ from ._file_access import (
60
59
  _line_edits, # pyright: ignore[reportPrivateUsage]
61
60
  _matches_glob, # pyright: ignore[reportPrivateUsage]
62
61
  _normalize_relative_path, # pyright: ignore[reportPrivateUsage]
62
+ _store_write_lock, # pyright: ignore[reportPrivateUsage]
63
63
  )
64
64
 
65
65
  logger = logging.getLogger(__name__)
@@ -297,10 +297,6 @@ class FileMemoryProvider(ContextProvider):
297
297
  self.store = store
298
298
  self.scope = scope
299
299
  self.instructions = instructions or DEFAULT_FILE_MEMORY_INSTRUCTIONS
300
- # Serializes write/delete operations (and their index rebuilds) so the
301
- # ``memories.md`` index stays consistent. A single per-instance lock is
302
- # sufficient for v1; concurrent writes across scopes are rare in practice.
303
- self._write_lock = asyncio.Lock()
304
300
 
305
301
  def _resolve_working_folder(self, context: SessionContext) -> str:
306
302
  """Resolve the working folder for the current invocation.
@@ -382,7 +378,11 @@ class FileMemoryProvider(ContextProvider):
382
378
 
383
379
  path = _combine_paths(working_folder, normalized)
384
380
  desc_path = _combine_paths(working_folder, _description_file_name(normalized))
385
- async with self._write_lock:
381
+ # Every mutating tool locks the whole working folder, not just the file, because each
382
+ # write and delete rebuilds the folder's memories.md index. The lock is shared by all
383
+ # providers on the store, including file-access tools editing a file in this folder, so
384
+ # they cannot interleave edits or index rebuilds.
385
+ async with _store_write_lock(self.store, working_folder):
386
386
  try:
387
387
  await self.store.write(path, content)
388
388
  if description and description.strip():
@@ -427,7 +427,7 @@ class FileMemoryProvider(ContextProvider):
427
427
 
428
428
  path = _combine_paths(working_folder, normalized)
429
429
  desc_path = _combine_paths(working_folder, _description_file_name(normalized))
430
- async with self._write_lock:
430
+ async with _store_write_lock(self.store, working_folder):
431
431
  try:
432
432
  deleted = await self.store.delete(path)
433
433
  await self.store.delete(desc_path)
@@ -478,7 +478,7 @@ class FileMemoryProvider(ContextProvider):
478
478
  "Please choose a different file name."
479
479
  )
480
480
  path = _combine_paths(working_folder, normalized)
481
- async with self._write_lock:
481
+ async with _store_write_lock(self.store, working_folder):
482
482
  try:
483
483
  content = await self.store.read(path)
484
484
  if content is None:
@@ -506,7 +506,7 @@ class FileMemoryProvider(ContextProvider):
506
506
  "Please choose a different file name."
507
507
  )
508
508
  path = _combine_paths(working_folder, normalized)
509
- async with self._write_lock:
509
+ async with _store_write_lock(self.store, working_folder):
510
510
  try:
511
511
  content = await self.store.read(path)
512
512
  if content is None:
@@ -457,6 +457,10 @@ class FunctionInvocationContext:
457
457
  bare ``Content`` of type ``function_approval_request``, which the
458
458
  invocation layer passes through untouched to drive the approval flow.
459
459
  kwargs: Additional runtime keyword arguments forwarded to the function invocation.
460
+ parent_service_session_state_keys: Provider-owned keys in ``session.state`` declared by the invoking
461
+ parent agent and its client. The automatic function-calling loop supplies this value. Custom loops
462
+ that directly invoke an agent tool with session propagation must provide it explicitly, including
463
+ an empty collection when the parent declares no such keys.
460
464
  tools: The live, mutable list of tools available to the model for the current
461
465
  agent run, or ``None`` when the function is invoked outside of a
462
466
  function-calling loop (for example via ``FunctionTool.invoke`` directly).
@@ -504,6 +508,7 @@ class FunctionInvocationContext:
504
508
  result: Any = None,
505
509
  kwargs: Mapping[str, Any] | None = None,
506
510
  tools: list[ToolTypes] | None = None,
511
+ parent_service_session_state_keys: Collection[str] | None = None,
507
512
  ) -> None:
508
513
  """Initialize the FunctionInvocationContext.
509
514
 
@@ -520,6 +525,8 @@ class FunctionInvocationContext:
520
525
  tools: The live, mutable list of tools for the current agent run. When provided,
521
526
  this is the same list object the model sees on the next iteration, so
522
527
  appending or removing tools changes the model's available tools.
528
+ parent_service_session_state_keys: Provider-owned keys declared by the invoking parent agent and client,
529
+ or ``None`` when the invocation path cannot establish that ownership.
523
530
  """
524
531
  self.function = function
525
532
  self.arguments = arguments
@@ -527,6 +534,9 @@ class FunctionInvocationContext:
527
534
  self.metadata: dict[str, Any] = dict(metadata) if metadata is not None else {}
528
535
  self.result = result
529
536
  self.kwargs: dict[str, Any] = dict(kwargs) if kwargs is not None else {}
537
+ self.parent_service_session_state_keys: frozenset[str] | None = (
538
+ frozenset(parent_service_session_state_keys) if parent_service_session_state_keys is not None else None
539
+ )
530
540
  self.tools = tools
531
541
 
532
542
  @experimental(feature_id=ExperimentalFeature.PROGRESSIVE_TOOLS)
@@ -1348,6 +1358,26 @@ class BaseMiddlewarePipeline(ABC):
1348
1358
  )
1349
1359
 
1350
1360
 
1361
+ def _warn_unbuffered_result_gates(stream: ResponseStream[Any, Any]) -> None:
1362
+ """Warn when result gates are registered on a stream that releases updates unbuffered.
1363
+
1364
+ A result gate runs at finalization, so on an unbuffered stream the consumer has already
1365
+ received every update by the time the gate raises: the gate fails open. Buffering holds
1366
+ the updates until the gates pass. The check reads the final stream state, so gates and
1367
+ buffering a middleware configured directly on the stream are reflected too.
1368
+ """
1369
+ if not stream._stream_updates: # pyright: ignore[reportPrivateUsage]
1370
+ return
1371
+ if not (stream._result_gates_before or stream._result_gates_after): # pyright: ignore[reportPrivateUsage]
1372
+ return
1373
+ logger.warning(
1374
+ "Result gates are registered on a streamed run that releases updates unbuffered; "
1375
+ "updates reach the consumer before the gates run, so a gate that raises cannot hold "
1376
+ "the answer back. Enable buffering (stream_buffer_updates=True or buffer_updates()) "
1377
+ "to make the gates blocking."
1378
+ )
1379
+
1380
+
1351
1381
  class AgentMiddlewarePipeline(BaseMiddlewarePipeline):
1352
1382
  """Executes agent middleware in a chain.
1353
1383
 
@@ -1458,6 +1488,7 @@ class AgentMiddlewarePipeline(BaseMiddlewarePipeline):
1458
1488
  context.result._with_release_error_hook(hook) # pyright: ignore[reportPrivateUsage]
1459
1489
  for cleanup_hook in context.stream_cleanup_hooks:
1460
1490
  context.result.with_cleanup_hook(cleanup_hook)
1491
+ _warn_unbuffered_result_gates(context.result)
1461
1492
  return context.result
1462
1493
 
1463
1494
 
@@ -1668,6 +1699,7 @@ class ChatMiddlewarePipeline(BaseMiddlewarePipeline):
1668
1699
  context.result._with_release_error_hook(hook) # pyright: ignore[reportPrivateUsage]
1669
1700
  for cleanup_hook in context.stream_cleanup_hooks:
1670
1701
  context.result.with_cleanup_hook(cleanup_hook)
1702
+ _warn_unbuffered_result_gates(context.result)
1671
1703
  return context.result
1672
1704
 
1673
1705