Python: Add orchestration ID to durable agent entity state and code refactor (#2484)

* Initial plan

* Add orchestration ID to durable agent entity state for Python

Co-authored-by: larohra <41490930+larohra@users.noreply.github.com>

* Fix type safety checks

* Fix tests

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: larohra <41490930+larohra@users.noreply.github.com>
Co-authored-by: Laveesh Rohra <larohra@microsoft.com>
This commit is contained in:
Copilot
2025-12-02 01:34:18 +00:00
committed by GitHub
co-authored by larohra copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Laveesh Rohra
parent 0d5d10d24a
commit cb343dd707
8 changed files with 355 additions and 131 deletions
@@ -302,6 +302,28 @@ class TestDurableAIAgent:
assert request["correlationId"] == "correlation-guid"
assert "thread_id" in request
assert request["thread_id"] == "thread-guid"
# Verify orchestration ID is set from context.instance_id
assert "orchestrationId" in request
assert request["orchestrationId"] == "test-instance-001"
def test_run_sets_orchestration_id(self) -> None:
"""Test that run() sets the orchestration_id from context.instance_id."""
mock_context = Mock()
mock_context.instance_id = "my-orchestration-123"
mock_context.new_uuid = Mock(side_effect=["thread-guid", "correlation-guid"])
entity_task = _create_entity_task()
mock_context.call_entity = Mock(return_value=entity_task)
agent = DurableAIAgent(mock_context, "TestAgent")
thread = agent.get_new_thread()
agent.run(messages="Test", thread=thread)
call_args = mock_context.call_entity.call_args
request = call_args[0][2]
assert request["orchestrationId"] == "my-orchestration-123"
def test_run_without_thread(self) -> None:
"""Test that run() works without explicit thread (creates unique session key)."""