-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Python: Reserve HA session id as reserved for AGUI #8199
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
westey (westey-m)
wants to merge
3
commits into
microsoft:main
Choose a base branch
from
westey-m:python-session-id-reserved-agui
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
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 |
|---|---|---|
|
|
@@ -8,7 +8,7 @@ | |
| import json | ||
| import logging | ||
| import uuid | ||
| from collections.abc import AsyncIterable, Awaitable, Mapping, Sequence | ||
| from collections.abc import AsyncIterable, Awaitable, Collection, Mapping, Sequence | ||
| from dataclasses import dataclass, field | ||
| from functools import partial | ||
| from typing import TYPE_CHECKING, Any, cast | ||
|
|
@@ -139,6 +139,18 @@ | |
| _COLLECTED_APPROVAL_RESPONSES_KEY = "collected_approval_responses" | ||
| _PROVIDER_SERVICE_SESSION_ID_STATE_KEY = "__ag_ui_provider_service_session_id" | ||
|
|
||
| # Provider-owned session-state keys reserved unconditionally, independent of what the agent declares through | ||
| # ``service_session_state_keys``. Agents are expected to declare their own keys, but that resolves through the | ||
| # agent object AG-UI is handed, so a wrapper agent that does not forward the attribute would silently drop the | ||
| # protection. Keys naming a remote resource that the server's own credentialed call addresses are reserved here | ||
| # instead. The Foundry key is spelled literally rather than imported, because agent-framework-ag-ui does not | ||
| # depend on agent-framework-foundry and must protect the key even when it is absent or outdated. | ||
| # | ||
| # agent_framework_foundry.FOUNDRY_HOSTED_AGENT_SESSION_ID_KEY. Selects the Foundry hosted-agent runtime session, | ||
| # a VM-isolated sandbox with a persistent filesystem, so a client-supplied value would run the server's | ||
| # credentialed call inside another session's sandbox. | ||
| _RESERVED_SERVICE_SESSION_STATE_KEYS: frozenset[str] = frozenset({"foundry_hosted_agent_session_id"}) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is now being defined both here and in FoundryAgent's service_session_state_keys, do we need it in both places? |
||
|
|
||
|
|
||
| @dataclass | ||
| class _LocalApprovalOccurrence: | ||
|
|
@@ -2324,11 +2336,16 @@ def _request_state_protected_keys(agent: SupportsAgentRun) -> set[str]: | |
|
|
||
|
|
||
| def _provider_service_session_state_keys(agent: SupportsAgentRun) -> set[str]: | ||
| """Return provider-owned session-state keys that must not cross stateless runs.""" | ||
| keys = getattr(agent, "service_session_state_keys", ()) | ||
| if not isinstance(keys, (list, tuple, set, frozenset)): | ||
| return set() | ||
| return {key for key in keys if isinstance(key, str)} | ||
| """Return provider-owned session-state keys that must not cross stateless runs. | ||
|
|
||
| Always includes :data:`_RESERVED_SERVICE_SESSION_STATE_KEYS`, so the reserved keys stay server-owned even | ||
| when ``agent`` declares nothing, such as a wrapper agent that does not forward the attribute. | ||
| """ | ||
| keys = set(_RESERVED_SERVICE_SESSION_STATE_KEYS) | ||
| declared = getattr(agent, "service_session_state_keys", ()) | ||
| if isinstance(declared, (list, tuple, set, frozenset)): | ||
| keys.update(key for key in cast(Collection[Any], declared) if isinstance(key, str)) | ||
| return keys | ||
|
|
||
|
|
||
| def _serialize_session_continuation_state( | ||
|
|
||
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
7 changes: 7 additions & 0 deletions
7
python/packages/foundry/agent_framework_foundry/_constants.py
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 |
|---|---|---|
| @@ -1,3 +1,10 @@ | ||
| # Copyright (c) Microsoft. All rights reserved. | ||
|
|
||
| FOUNDRY_HOSTED_AGENT_SESSION_ID_KEY = "foundry_hosted_agent_session_id" | ||
| """``AgentSession.state`` key holding the Foundry hosted-agent session ID. | ||
|
|
||
| This is the hosted agent's runtime session, a VM-isolated sandbox with a persistent filesystem, sent as | ||
| ``extra_body["agent_session_id"]``. It is distinct from ``AgentSession.service_session_id``, which continues the | ||
| model-side response or conversation chain. The value is server-owned; see | ||
| ``RawFoundryAgent.service_session_state_keys``. | ||
| """ |
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.
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.