Fix more workflow samples

This commit is contained in:
Tao Chen
2026-03-30 17:15:57 -07:00
Unverified
parent bfd2f671d5
commit 565933a829
6 changed files with 27 additions and 22 deletions
@@ -184,7 +184,9 @@ def create_writer_agent() -> Agent:
"produce a 3-sentence draft."
),
tools=[fetch_product_brief, get_brand_voice_profile],
tool_choice="required",
default_options={
"tool_choice": "required",
},
)
@@ -72,7 +72,7 @@ async def main() -> None:
print(f"Input: {task}\n")
try:
workflow_agent = Agent(client=workflow, name="GroupChatWorkflowAgent")
workflow_agent = workflow.as_agent()
agent_result = await workflow_agent.run(task)
if agent_result.messages:
@@ -174,21 +174,20 @@ async def main() -> None:
# Without this, the default behavior continues requesting user input until max_turns
# is reached. Here we use a custom condition that checks if the conversation has ended
# naturally (when one of the agents says something like "you're welcome").
agent = Agent(
client=(
HandoffBuilder(
name="customer_support_handoff",
participants=[triage, refund, order, support],
# Custom termination: Check if one of the agents has provided a closing message.
# This looks for the last message containing "welcome", which indicates the
# conversation has concluded naturally.
termination_condition=lambda conversation: (
len(conversation) > 0 and "welcome" in conversation[-1].text.lower()
),
)
.with_start_agent(triage)
.build()
),
agent = (
HandoffBuilder(
name="customer_support_handoff",
participants=[triage, refund, order, support],
# Custom termination: Check if one of the agents has provided a closing message.
# This looks for the last message containing "welcome", which indicates the
# conversation has concluded naturally.
termination_condition=lambda conversation: (
len(conversation) > 0 and "welcome" in conversation[-1].text.lower()
),
)
.with_start_agent(triage)
.build()
.as_agent()
)
# Scripted user responses for reproducible demo
@@ -226,7 +225,7 @@ async def main() -> None:
responses = {req_id: HandoffAgentUserRequest.create_response(user_response) for req_id in pending_requests}
function_results = [
Content.from_function_result(call_id=req_id, result=response) for req_id, response in responses.items()
Content("function_result", call_id=req_id, result=response) for req_id, response in responses.items()
]
response = await agent.run(Message("tool", function_results))
pending_requests = handle_response_and_requests(response)
@@ -164,7 +164,8 @@ async def main() -> None:
human_response = ReviewResponse(request_id=request_id, feedback="", approved=True)
# Create the function call result object to send back to the agent.
human_review_function_result = Content.from_function_result(
human_review_function_result = Content(
"function_result",
call_id=human_review_function_call.call_id, # type: ignore
result=human_response,
)
@@ -29,10 +29,11 @@ from agent_framework import Agent
from agent_framework.declarative import WorkflowFactory
from agent_framework.foundry import FoundryChatClient
from azure.identity import AzureCliCredential
from dotenv import load_dotenv
from pydantic import BaseModel, Field
# Copyright (c) Microsoft. All rights reserved.
# Load environment variables from .env file
load_dotenv()
# Agent Instructions
RESEARCH_INSTRUCTIONS = """In order to help begin addressing the user request, please answer the following pre-survey to the best of your ability.
@@ -27,8 +27,10 @@ from agent_framework import Agent
from agent_framework.declarative import WorkflowFactory
from agent_framework.foundry import FoundryChatClient
from azure.identity import AzureCliCredential
from dotenv.main import load_dotenv
# Copyright (c) Microsoft. All rights reserved.
# Load environment variables from .env file
load_dotenv()
STUDENT_INSTRUCTIONS = """You are a curious math student working on understanding mathematical concepts.