[BREAKING] Python: Add request-scoped Foundry agent factories - #8372
Roger Barreto (rogerbarreto) merged 12 commits into
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
Reused execution objects can escape detection, and functional continuations accept responses with incompatible types.
Get a fresh assessment by requesting another Copilot review.
Pull request overview
Adds request-scoped agent factories and durable workflow continuation to Python Foundry hosts.
Changes:
- Adds synchronous/asynchronous factory resolution, scoped locking, lifecycle cleanup, and workflow reuse detection.
- Persists workflow sessions and checkpoints for Responses and Invocations hosts.
- Migrates samples and adds extensive continuation, cancellation, isolation, and recovery tests.
File summaries
| File | Description |
|---|---|
responses/workflows/README.md |
Documents request-scoped workflow hosting. |
responses/workflows/main.py |
Migrates the workflow sample to a factory. |
responses/resilient_long_running_workflow/README.md |
Documents recovery ownership. |
responses/resilient_long_running_workflow/main.py |
Rebuilds recovery workflows per request. |
responses/declarative_customer_support/README.md |
Documents declarative factory behavior. |
responses/declarative_customer_support/main.py |
Creates declarative workflows per request. |
tests/test_state_store.py |
Tests separate Invocations namespaces. |
tests/test_responses.py |
Adapts workflow continuation tests. |
tests/test_responses_factory.py |
Covers Responses factory lifecycle and recovery. |
tests/test_invocations_factory.py |
Covers Invocations factories and persistence. |
foundry_hosting/README.md |
Documents factory and ownership contracts. |
_state_store.py |
Adds Invocations stores and checkpoint-error tracking. |
_responses.py |
Implements request-scoped Responses workflows. |
_invocations.py |
Implements factory-backed Invocations workflows. |
_agent_factory.py |
Adds shared factory and scope-lock utilities. |
test_functional_workflow.py |
Documents functional checkpoint limitations. |
0040-python-foundry-request-agent-factories.md |
Records the architectural decision. |
Review details
- Files reviewed: 17/17 changed files
- Comments generated: 2
- Review effort level: Balanced
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
There was a problem hiding this comment.
MAF Automated Review — Iteration 1
Result: Findings reported
Scope: full PR (1 commit(s)): 0a3b84d49650
Model: gpt-5.6-sol-fast
Overview
The PR adds request-scoped agent factories with strong same-scope serialization, user-isolated persistence, cancellation cleanup, checkpoint consistency checks, and extensive regression coverage. Two gaps remain: ordinary Invocations factory sessions accumulate permanently in a process-wide dictionary, and workflow reuse detection does not cover the mutable executors that the factory contract requires to be fresh. The latter can allow state to bleed between otherwise independent request-local workflows.
Reviewed the supplied pull-request change set across correctness, security/reliability, architecture, and failure behavior.
2 verified findings remained after source verification (1 high, 1 medium) across 2 files. Details are attached to the affected lines below.
Affected areas: python/packages/foundry_hosting/agent_framework_foundry_hosting/_agent_factory.py, python/packages/foundry_hosting/agent_framework_foundry_hosting/_invocations.py
|
Thanks for the contribution. Before this is ready, could you please:
Once those are addressed, please re-request review. Thanks! |
Validate functional response batches before state changes, persist ordinary Invocations factory sessions, and document fresh execution objects as the factory author responsibility. Stabilize recovery fixtures and correct CI test typing.
Require recorded completion for both Invocations workflow types. Preserve stored state when incomplete continuation is rejected.
Eduard van Valkenburg (eavanvalkenburg)
left a comment
There was a problem hiding this comment.
For me, the fix itself is overengineered and too complex for what it is trying to solve, and it really feels like a bandaid over something we need to fix in the first place (the use of workflow.as_agent itself, rather then just leveraging the workflow directly). So if we are making a breaking change in this space, we should fix that.
Keep checkpoint error policy with the workflow runtime. Add HTTP coverage for request-scoped factory behavior.
02e5dc3 to
0db17c0
Compare
|
Updated in a23359c. All inline discussions are answered and resolved, and the implementation now follows the revised |
Motivation & Context
Foundry-hosted workflows need request-scoped execution objects while continuing conversations from saved state. A workflow agent retains mutable executor and conversation state that should not be reused for independent requests.
This change adds factory-based construction to both Python Foundry hosts while preserving the existing instance API for ordinary agents.
Description & Review Guide
agent_factoryaccepting synchronous or asynchronous callables toResponsesHostServerandInvocationsHostServer. Keep each returned agent local to its request through streaming and cleanup. Restore workflow state from user-scoped conversation/session stores, serialize updates within a host, and document that factory implementers must construct fresh mutable objects. Migrate the three Responses workflow samples and document ownership and continuation behavior.Related Issue
No linked issue.
Contribution Checklist
agent_factory.