Python: implement ADR-0029 service_session_id lifecycle mapping#6724
Open
eavanvalkenburg wants to merge 5 commits into
Open
Python: implement ADR-0029 service_session_id lifecycle mapping#6724eavanvalkenburg wants to merge 5 commits into
eavanvalkenburg wants to merge 5 commits into
Conversation
- Extend AgentSession service_session_id to support structured values - Add agent-owned conversation id extraction for chat forwarding and telemetry - Migrate A2A durable continuation state to A2AServiceSessionId - Keep A2AAgentSession as compatibility shim and mark it deprecated - Update core/a2a tests and package guidance Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
Contributor
There was a problem hiding this comment.
Pull request overview
Implements ADR-0029’s Python session identity lifecycle mapping by allowing AgentSession.service_session_id to carry either a simple string (generic provider continuation) or a structured mapping (durable provider continuation state), while separating chat forwarding vs. telemetry conversation-id extraction. Updates A2A to persist context_id/task_id/task_state in a structured service_session_id, and keeps A2AAgentSession as a deprecated compatibility wrapper.
Changes:
- Extend core session typing to support
service_session_id: str | ServiceSessionId | Noneand introduce agent-owned hooks for extracting (a) provider chat conversation id and (b) OTel conversation id. - Update telemetry to use the agent hook for
gen_ai.conversation.idinstead of directly readingsession.service_session_id. - Add
A2AServiceSessionIdand migrate A2A durable continuation state into structuredservice_session_id, plus update exports/docs/tests and add a deprecation warning forA2AAgentSession.
Reviewed changes
Copilot reviewed 18 out of 18 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| python/packages/core/agent_framework/_sessions.py | Adds ServiceSessionId alias and broadens service_session_id typing for SessionContext/AgentSession. |
| python/packages/core/agent_framework/_agents.py | Introduces _get_chat_conversation_id and _get_otel_conversation_id; routes chat continuation and per-service-call history logic through the chat-extraction hook. |
| python/packages/core/agent_framework/observability.py | Uses agent-provided OTel conversation-id extraction hook when available (fallback to string service_session_id). |
| python/packages/core/agent_framework/init.py | Re-exports ServiceSessionId from the top-level package. |
| python/packages/core/agent_framework/a2a/init.py | Adds lazy export for A2AServiceSessionId. |
| python/packages/core/agent_framework/a2a/init.pyi | Updates stub exports to include A2AServiceSessionId. |
| python/packages/core/AGENTS.md | Documents ServiceSessionId and its role in AgentSession.service_session_id. |
| python/packages/a2a/agent_framework_a2a/_agent.py | Defines A2AServiceSessionId, persists A2A durable continuation state into structured service_session_id, and adds A2AAgentSession deprecation warning + compatibility syncing. |
| python/packages/a2a/agent_framework_a2a/init.py | Exports A2AServiceSessionId from the A2A package. |
| python/packages/a2a/AGENTS.md | Documents new A2A structured session-id shape and deprecation guidance for A2AAgentSession. |
| python/packages/a2a/tests/test_a2a_agent.py | Updates/extends tests for structured service_session_id persistence, OTel mapping, and deprecation warning behavior. |
| python/packages/core/tests/core/test_sessions.py | Adds coverage for structured service_session_id acceptance and serialization round-trip. |
| python/packages/core/tests/core/test_agents.py | Adds tests for structured get_session input and early rejection of structured ids in generic chat agent runs. |
| python/packages/core/tests/core/test_harness_agent.py | Updates harness test agent get_session typing to accept structured service_session_id. |
| python/packages/core/tests/core/test_harness_background_agents.py | Updates background agent test get_session typing to accept structured service_session_id. |
| python/packages/core/tests/workflow/test_workflow_agent.py | Updates workflow test scaffolding get_session typing to accept structured service_session_id. |
| python/packages/core/tests/workflow/test_full_conversation.py | Updates test private attribute typing to allow structured service_session_id. |
| python/packages/core/tests/workflow/test_agent_utils.py | Updates test agent protocol typing/imports for structured service_session_id. |
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Motivation & Context
This implements the accepted ADR-0029 decision for Python session identity lifecycles, where durable provider continuation state lives in
AgentSession.service_session_idand can be structured when needed (A2A immediate case).It addresses the current mismatch between lifecycle intent and implementation by separating:
This work follows the design direction that originated in #4893 and was finalized in ADR-0029.
Description & Review Guide
What are the major changes?
Extend core session typing so
service_session_idsupportsstr | ServiceSessionId | None.Add agent-owned conversation-id extraction hooks in core:
_get_chat_conversation_id(...)for generic provider forwarding (string-only; early error on incompatible structured values)_get_otel_conversation_id(...)for telemetry mapping.Update
AgentTelemetryLayerto use the agent extraction hook instead of directly readingsession.service_session_id.Introduce
A2AServiceSessionIdand migrate A2A durable state (context_id,task_id,task_state) to structuredservice_session_id.Keep
A2AAgentSessionas compatibility shim and emit a deprecation warning.Update lazy exports/stubs and core/a2a tests accordingly.
What is the impact of these changes?
Aligns Python behavior with ADR-0029 lifecycle rules.
Enables structured durable continuation state for A2A without overloading generic chat forwarding.
Improves failure mode for incompatible sessions by raising early in generic chat paths.
Preserves backward compatibility for existing serialized string sessions and existing A2A usage (with deprecation guidance).
What do you want reviewers to focus on?
Correctness of lifecycle boundaries between session continuation, request forwarding, and telemetry.
A2A mapping semantics for
context_id/task_id/task_stateand compatibility behavior.Whether early error behavior in generic chat paths is appropriately scoped and actionable.
Related Issue
Fixes #4673
Related to #4893
Contribution Checklist
breaking changelabel (or add "[BREAKING]" to the title prefix, before or after any language prefix) — a workflow keeps the label and title prefix in sync automatically.