Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 26, 2025

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}}]}}

  • Also fixes a bunch of type errors in the azurefunctions package.

Description

Propagates orchestration ID from DurableOrchestrationContext.instance_id to the agent's entity state when DurableAIAgent.run() is called within an orchestration.

Changes:

  • _models.py: Added orchestration_id field to RunRequest with serialization as orchestrationId
  • _durable_agent_state.py: Added orchestration_id to DurableAgentStateRequest, updated from_run_request() to transfer the field
  • _durable_agent_state.py: Bumped schema version 1.0.01.1.0
  • _orchestration.py: Set orchestration_id=self.context.instance_id in DurableAIAgent.run()

Usage in orchestration:

@app.orchestration_trigger(context_name="context")
def my_orchestration(context):
    agent = app.get_agent(context, "MyAgent")
    thread = agent.get_new_thread()
    # orchestration_id automatically captured from context.instance_id
    result = yield agent.run("Hello", thread=thread)

The orchestrationId field appears in persisted entity state under each request entry, enabling reverse correlation from agent state to orchestration.

Contribution Checklist

  • The code builds clean without any errors or warnings
  • The PR follows the Contribution Guidelines
  • All unit tests pass, and I have added new tests where possible
  • Is this a breaking change? If yes, add "[BREAKING]" prefix to the title of the PR.
Original prompt

This section details on the original issue you should resolve

<issue_title>Python: Add orchestration ID to durable agent entity state</issue_title>
<issue_description>Updates durable agent calls made within the context of an orchestration so that the orchestration ID gets propagated to the agent's underlying entity state. This allows tools that analyze agent state (such as the DTS Dashboard) to correlate individual requests to an agent back to the orchestration from which the request was made. (Currently that correlation can be done only one way, from the orchestration to the agent, but not vice-versa.)

Similar to #2137 </issue_description>

Comments on the Issue (you are @copilot in this section)


💡 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.

Copilot AI changed the title [WIP] Add orchestration ID to durable agent entity state Python: Add orchestration ID to durable agent entity state Nov 26, 2025
Copilot AI requested a review from larohra November 26, 2025 19:03
@larohra larohra marked this pull request as ready for review November 26, 2025 21:19
@larohra larohra requested a review from a team as a code owner November 26, 2025 21:19
Copilot AI review requested due to automatic review settings November 26, 2025 21:19
Copy link
Contributor

Copilot AI left a 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_id field to RunRequest and DurableAgentStateRequest models with proper serialization as orchestrationId
  • Bumped schema version from 1.0.0 to 1.1.0 to reflect the state structure change
  • Modified DurableAIAgent.run() to automatically capture and propagate context.instance_id as 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.

@larohra larohra changed the title Python: Add orchestration ID to durable agent entity state Python: Add orchestration ID to durable agent entity state and code refactor Nov 26, 2025
Copy link
Member

@cgillum cgillum left a 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.

@larohra larohra added this pull request to the merge queue Dec 1, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Dec 1, 2025
@markwallace-microsoft
Copy link
Member

Python Test Coverage

Python Test Coverage Report •
FileStmtsMissCoverMissing
packages/azurefunctions/agent_framework_azurefunctions
   _app.py3748078%197–198, 203–204, 422, 430–431, 451–453, 459–461, 467–469, 501–502, 562–563, 698, 701, 710–712, 714–716, 718, 720, 731, 733–736, 738, 740–741, 743, 750–751, 753–754, 756–757, 759, 763, 773–775, 777–778, 780–782, 789, 791–792, 794, 815, 820, 832, 908, 920, 927–929, 974, 988, 999–1001, 1003–1006, 1031, 1038, 1040, 1043
   _durable_agent_state.py45613570%64, 67–72, 91–92, 116–118, 139–140, 146–147, 154–155, 162–163, 169–172, 177–180, 186–189, 194–197, 228, 239, 257, 261, 263, 265, 267, 270–276, 319, 382, 393–394, 403–406, 408, 434–435, 438, 440–441, 510–511, 513, 571, 643, 654, 676, 730, 804, 807, 829–830, 833, 837, 840, 867, 876, 899–901, 904, 909–913, 915–918, 920, 923, 944–945, 948, 952, 955, 973, 976, 980, 983, 1002, 1005, 1011, 1014, 1056, 1059, 1063, 1066, 1086–1087, 1090, 1094, 1097, 1132, 1137–1139, 1143, 1154, 1162, 1185, 1188, 1192, 1195, 1214, 1217, 1221, 1224–1226
   _models.py1541292%204, 207, 210, 222, 225, 244, 247, 252, 257, 274, 333, 352
   _orchestration.py1121289%109–110, 114, 354, 359–366
TOTAL15871241584% 

Python Unit Test Overview

Tests Skipped Failures Errors Time
2277 130 💤 0 ❌ 0 🔥 59.251s ⏱️

@cgillum cgillum added this pull request to the merge queue Dec 2, 2025
Merged via the queue into main with commit cb343dd Dec 2, 2025
24 checks passed
@larohra larohra deleted the copilot/add-orchestration-id-to-agent-state branch December 2, 2025 01:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Python: Add orchestration ID to durable agent entity state

5 participants