-
Notifications
You must be signed in to change notification settings - Fork 970
Python: Add orchestration ID to durable agent entity state and code refactor #2484
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
Conversation
Co-authored-by: larohra <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR adds orchestration ID tracking to durable agent entity state, porting functionality from the .NET implementation (PR #2137). This enables bidirectional correlation between orchestrations and agent requests, which is essential for tools like the DTS Dashboard to analyze agent state and trace requests back to their originating orchestration.
Key Changes
- Added
orchestration_idfield toRunRequestandDurableAgentStateRequestmodels with proper serialization asorchestrationId - Bumped schema version from
1.0.0to1.1.0to reflect the state structure change - Modified
DurableAIAgent.run()to automatically capture and propagatecontext.instance_idas the orchestration ID
Reviewed changes
Copilot reviewed 7 out of 8 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| python/packages/azurefunctions/agent_framework_azurefunctions/_models.py | Added orchestration_id field to RunRequest with camelCase serialization |
| python/packages/azurefunctions/agent_framework_azurefunctions/_durable_agent_state.py | Added orchestration_id to DurableAgentStateRequest, bumped schema version to 1.1.0, and refactored parsing helper functions |
| python/packages/azurefunctions/agent_framework_azurefunctions/_orchestration.py | Set orchestration_id from context.instance_id in DurableAIAgent.run() |
| python/packages/azurefunctions/tests/test_models.py | Added comprehensive tests for orchestration_id serialization/deserialization in RunRequest |
| python/packages/azurefunctions/tests/test_orchestration.py | Added tests verifying orchestration_id is set from context.instance_id |
| python/packages/azurefunctions/tests/test_entities.py | Added tests for orchestration_id in DurableAgentStateRequest and minor type annotation change |
| python/packages/azurefunctions/agent_framework_azurefunctions/_app.py | Unrelated refactoring: type annotations and code improvements in MCP tool handler |
| python/uv.lock | Dependency updates for a2a-sdk, pydantic, redisvl, and uv |
You can also share your feedback on Copilot code review for a chance to win a $100 gift card. Take the survey.
python/packages/azurefunctions/agent_framework_azurefunctions/_durable_agent_state.py
Show resolved
Hide resolved
python/packages/azurefunctions/agent_framework_azurefunctions/_models.py
Show resolved
Hide resolved
cgillum
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My remaining comment is not a blocker.
Motivation and Context
Enables correlation of agent requests back to their originating orchestration—currently this correlation only works in one direction (orchestration → agent). Tools like the DTS Dashboard need this to analyze agent state.
Fixes #2205 (similar to #2137)
Sample data in entity - (
"orchestrationId": "0b6fbdcf474946b38c37c293010f567d"){"schemaVersion": "1.1.0", "data": {"conversationHistory": [{"$type": "request", "correlationId": "5d16b15d-c915-5dec-93ce-67787dea8fd0", "createdAt": "2025-11-26T21:15:19.146197+00:00", "messages": [{"role": "user", "contents": [{"$type": "text", "text": "What is temperature?"}], "createdAt": "2025-11-26T21:15:19.146191+00:00"}], "orchestrationId": "0b6fbdcf474946b38c37c293010f567d", "responseType": "text"}, {"$type": "response", "correlationId": "5d16b15d-c915-5dec-93ce-67787dea8fd0", "createdAt": "2025-11-26T13:15:20+00:00", "messages": [{"role": "assistant", "contents": [{"$type": "text", "text": "Temperature, from a chemistry perspective, is a physical property that represents the average kinetic energy of the particles (atoms, ions, or molecules) in a substance. It reflects how much motion or energy is present within a system at the microscopic level. \n\nIn simple terms:\n- Higher temperature means particles are moving faster (more kinetic energy).\n- Lower temperature means particles are moving slower (less kinetic energy).\n\nTemperature is crucial in chemistry because it affects the rate of chemical reactions, the phase of matter (solid, liquid, gas), and the properties of substances (e.g., solubility, viscosity). It is measured using scales like Celsius (\u00b0C), Kelvin (K), or Fahrenheit (\u00b0F), with Kelvin being favored in scientific contexts because it starts at absolute zero, the theoretical point where particle motion ceases completely."}], "authorName": "ChemistAgent"}], "usage": {"inputTokenCount": 30, "outputTokenCount": 166, "totalTokenCount": 196}}]}}azurefunctionspackage.Description
Propagates orchestration ID from
DurableOrchestrationContext.instance_idto the agent's entity state whenDurableAIAgent.run()is called within an orchestration.Changes:
_models.py: Addedorchestration_idfield toRunRequestwith serialization asorchestrationId_durable_agent_state.py: Addedorchestration_idtoDurableAgentStateRequest, updatedfrom_run_request()to transfer the field_durable_agent_state.py: Bumped schema version1.0.0→1.1.0_orchestration.py: Setorchestration_id=self.context.instance_idinDurableAIAgent.run()Usage in orchestration:
The
orchestrationIdfield appears in persisted entity state under each request entry, enabling reverse correlation from agent state to orchestration.Contribution Checklist
Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.