mirror of
https://github.com/microsoft/agent-framework.git
synced 2026-06-16 21:04:09 +08:00
Python: Fix streamed workflow agent continuation context by finalizing AgentExecutor streams (#3882)
* Fix streamed workflow agent continuation context by finalizing AgentExecutor streams * Fix stream handling * Fixes * Fix DevUI and tests
This commit is contained in:
committed by
GitHub
Unverified
parent
2203fa0f8b
commit
a276c1295a
+23
-4
@@ -8,9 +8,11 @@ from typing import Any
|
||||
|
||||
from agent_framework import (
|
||||
Agent,
|
||||
AgentResponseUpdate,
|
||||
Content,
|
||||
FileCheckpointStorage,
|
||||
Workflow,
|
||||
WorkflowEvent,
|
||||
tool,
|
||||
)
|
||||
from agent_framework.azure import AzureOpenAIResponsesClient
|
||||
@@ -183,8 +185,16 @@ async def main() -> None:
|
||||
initial_request = "Hi, my order 12345 arrived damaged. I need a refund."
|
||||
|
||||
# Phase 1: Initial run - workflow will pause when it needs user input
|
||||
results = await workflow.run(message=initial_request)
|
||||
request_events = results.get_request_info_events()
|
||||
print("Running initial workflow...")
|
||||
results = await workflow.run(message=initial_request, stream=True)
|
||||
|
||||
# Iterate through streamed events and collect request_info events
|
||||
request_events: list[WorkflowEvent] = []
|
||||
async for event in results:
|
||||
event: WorkflowEvent
|
||||
if event.type == "request_info":
|
||||
request_events.append(event)
|
||||
|
||||
if not request_events:
|
||||
print("Workflow completed without needing user input")
|
||||
return
|
||||
@@ -224,8 +234,17 @@ async def main() -> None:
|
||||
raise RuntimeError("No checkpoints found.")
|
||||
checkpoint_id = checkpoint.checkpoint_id
|
||||
|
||||
results = await workflow.run(responses=responses, checkpoint_id=checkpoint_id)
|
||||
request_events = results.get_request_info_events()
|
||||
print("Resuming workflow from checkpoint...")
|
||||
results = await workflow.run(responses=responses, checkpoint_id=checkpoint_id, stream=True)
|
||||
|
||||
# Iterate through streamed events and collect request_info events
|
||||
request_events: list[WorkflowEvent] = []
|
||||
async for event in results:
|
||||
event: WorkflowEvent
|
||||
if event.type == "request_info":
|
||||
request_events.append(event)
|
||||
elif event.type == "output" and isinstance(event.data, AgentResponseUpdate):
|
||||
print(event.data.text, end="", flush=True)
|
||||
|
||||
print("\n" + "=" * 60)
|
||||
print("DEMO COMPLETE")
|
||||
|
||||
Reference in New Issue
Block a user