I have a hosted agent on Foundry that implements a multi-agent workflow. As part of the workflow, there is a step that requires human input, during which the flow pauses and waits for a response.
I’m able to test this successfully in the foundry playground, where I can provide the required input after the pause and the workflow resumes as expected.
However, I’m facing an issue when trying to do this programmatically. When I send the response after the flow pauses, it is treated as a new input, and a new conversation is started, instead of resuming the existing workflow.
Below is my client code.
`from azure.identity import DefaultAzureCredential
from azure.ai.projects import AIProjectClient
PROJECT_ENDPOINT = "https://xxx.services.ai.azure.com/api/projects/xxx-aifoundry"
AGENT_NAME = "agent-with-mcp"
AGENT_VERSION = "35"
def main():
client = AIProjectClient(
endpoint=PROJECT_ENDPOINT,
credential=DefaultAzureCredential(),
)
openai_client = client.get_openai_client()
# 1. Trigger the flow
print("🚀 Starting agent flow...")
start_response = openai_client.responses.create(
input=[
{
"role": "user",
"content": "Investigate HRMS production outage and remediate."
}
],
extra_body={
"agent_reference": {
"name": AGENT_NAME,
"version": AGENT_VERSION,
"type": "agent_reference"
}
}
)
print("Response ID:", start_response.id)
print(start_response.output_text)
# 2. Detect HITL pause (FIXED)
paused = any(
getattr(item, "type", None) in ("mcp_approval_request", "tool_call")
for item in start_response.output
)
if not paused:
print("✅ Flow completed without approval.")
return
print("⏸️ Flow paused for approval.")
# 3. Send approval
approval_response = openai_client.responses.create(
previous_response_id=start_response.id,
input=[
{
"role": "user",
"content": "APPROVED"
}
],
extra_body={
"agent_reference": {
"name": AGENT_NAME,
"version": AGENT_VERSION,
"type": "agent_reference"
}
}
)
print("✅ Flow resumed and completed.")
print(approval_response.output_text)
if name == "main":
main()`
I have a hosted agent on Foundry that implements a multi-agent workflow. As part of the workflow, there is a step that requires human input, during which the flow pauses and waits for a response.
I’m able to test this successfully in the foundry playground, where I can provide the required input after the pause and the workflow resumes as expected.
However, I’m facing an issue when trying to do this programmatically. When I send the response after the flow pauses, it is treated as a new input, and a new conversation is started, instead of resuming the existing workflow.
Below is my client code.
`from azure.identity import DefaultAzureCredential
from azure.ai.projects import AIProjectClient
PROJECT_ENDPOINT = "https://xxx.services.ai.azure.com/api/projects/xxx-aifoundry"
AGENT_NAME = "agent-with-mcp"
AGENT_VERSION = "35"
def main():
client = AIProjectClient(
endpoint=PROJECT_ENDPOINT,
credential=DefaultAzureCredential(),
)
if name == "main":
main()`