| title | Agents in Workflows |
|---|---|
| description | Learn how to integrate agents into workflows. |
| zone_pivot_groups | programming-languages |
| author | TaoChenOSU |
| ms.topic | tutorial |
| ms.author | taochen |
| ms.date | 03/09/2026 |
| ms.service | agent-framework |
This tutorial demonstrates how to integrate AI agents into workflows using Agent Framework. You'll learn to create workflows that leverage the power of specialized AI agents for content creation, review, and other collaborative tasks.
::: zone pivot="programming-language-csharp"
You'll create a workflow that:
- Uses Azure Foundry Agent Service to create intelligent agents
- Implements a French translation agent that translates input to French
- Implements a Spanish translation agent that translates French to Spanish
- Implements an English translation agent that translates Spanish back to English
- Connects agents in a sequential workflow pipeline
- Streams real-time updates as agents process requests
- Demonstrates proper resource cleanup for Azure Foundry agents
- .NET 8.0 SDK or later
- An Azure Foundry project endpoint and model configured
- Azure CLI installed and authenticated (for Azure credential authentication)
- A new console application
First, install the required packages for your .NET project:
dotnet add package Azure.AI.Projects --prerelease
dotnet add package Azure.Identity
dotnet add package Microsoft.Agents.AI.Foundry --prerelease
dotnet add package Microsoft.Agents.AI.Workflows --prerelease
Configure the Azure Foundry client with environment variables and authentication:
using Azure.AI.Projects;
using Azure.AI.Projects.Agents;
using Azure.Identity;
using Microsoft.Agents.AI;
using Microsoft.Agents.AI.Foundry;
using Microsoft.Agents.AI.Workflows;
using Microsoft.Extensions.AI;
public static class Program
{
private static async Task Main()
{
// Set up the Azure AI Project client
var endpoint = Environment.GetEnvironmentVariable("AZURE_AI_PROJECT_ENDPOINT")
?? throw new InvalidOperationException("AZURE_AI_PROJECT_ENDPOINT is not set.");
var deploymentName = Environment.GetEnvironmentVariable("AZURE_AI_MODEL_DEPLOYMENT_NAME") ?? "gpt-4o-mini";
var aiProjectClient = new AIProjectClient(new Uri(endpoint), new AzureCliCredential());Implement a helper method to create Azure Foundry agents with specific instructions:
/// <summary>
/// Creates a translation agent for the specified target language.
/// </summary>
/// <param name="targetLanguage">The target language for translation</param>
/// <param name="aiProjectClient">The AIProjectClient to create the agent</param>
/// <param name="model">The model to use for the agent</param>
/// <returns>A ChatClientAgent configured for the specified language</returns>
private static async Task<ChatClientAgent> GetTranslationAgentAsync(
string targetLanguage,
AIProjectClient aiProjectClient,
string model)
{
string agentName = $"{targetLanguage} Translator";
var version = await aiProjectClient.AgentAdministrationClient.CreateAgentVersionAsync(
agentName,
new ProjectsAgentVersionCreationOptions(
new DeclarativeAgentDefinition(model)
{
Instructions = $"You are a translation assistant that translates the provided text to {targetLanguage}."
}));
return aiProjectClient.AsAIAgent(version);
}
}Create three translation agents using the helper method:
// Create agents
AIAgent frenchAgent = await GetTranslationAgentAsync("French", aiProjectClient, deploymentName);
AIAgent spanishAgent = await GetTranslationAgentAsync("Spanish", aiProjectClient, deploymentName);
AIAgent englishAgent = await GetTranslationAgentAsync("English", aiProjectClient, deploymentName);Connect the agents in a sequential workflow using the WorkflowBuilder:
// Build the workflow by adding executors and connecting them
var workflow = new WorkflowBuilder(frenchAgent)
.AddEdge(frenchAgent, spanishAgent)
.AddEdge(spanishAgent, englishAgent)
.Build();Run the workflow with streaming to observe real-time updates from all agents:
// Execute the workflow
await using StreamingRun run = await InProcessExecution.RunStreamingAsync(workflow, new ChatMessage(ChatRole.User, "Hello World!"));
// Must send the turn token to trigger the agents.
// The agents are wrapped as executors. When they receive messages,
// they will cache the messages and only start processing when they receive a TurnToken.
await run.TrySendMessageAsync(new TurnToken(emitEvents: true));
await foreach (WorkflowEvent evt in run.WatchStreamAsync())
{
if (evt is AgentResponseUpdateEvent executorComplete)
{
Console.WriteLine($"{executorComplete.ExecutorId}: {executorComplete.Data}");
}
}Properly clean up the Azure Foundry agents after use:
// Cleanup the agents created for the sample.
await aiProjectClient.AgentAdministrationClient.DeleteAgentAsync(frenchAgent.Id);
await aiProjectClient.AgentAdministrationClient.DeleteAgentAsync(spanishAgent.Id);
await aiProjectClient.AgentAdministrationClient.DeleteAgentAsync(englishAgent.Id);
}- Azure Foundry Client Setup: Uses
AIProjectClientwith Azure CLI credentials for authentication - Agent Creation: Creates versioned agents on Azure Foundry with specific instructions for translation
- Sequential Processing: French agent translates input first, then Spanish agent, then English agent
- Turn Token Pattern: Agents cache messages and only process when they receive a
TurnToken - Streaming Updates:
AgentResponseUpdateEventprovides real-time token updates as agents generate responses - Resource Management: Proper cleanup of Azure Foundry agents using the Administration API
- Azure Foundry Agent Service: Cloud-based AI agents with advanced reasoning capabilities
- AIProjectClient: Client for creating and managing agents on Azure Foundry
- WorkflowEvent: Output events (
type="output") contain agent output data (AgentResponseUpdatefor streaming,AgentResponsefor non-streaming) - TurnToken: Signal that triggers agent processing after message caching
- Sequential Workflow: Agents connected in a pipeline where output flows from one to the next
For the complete working implementation of this Azure Foundry agents workflow, see the FoundryAgent Program.cs sample in the Agent Framework repository.
::: zone-end
::: zone pivot="programming-language-python"
You'll create a workflow that:
- Uses
FoundryChatClientto create intelligent agents - Implements a Writer agent that creates content based on prompts
- Implements a Reviewer agent that provides feedback on the content
- Connects agents in a sequential workflow pipeline
- Streams real-time updates as agents process requests
- Python 3.10 or later
- Agent Framework installed:
pip install agent-framework - Azure OpenAI Responses configured with proper environment variables
- Azure CLI authentication:
az login
Start by importing the necessary components for workflows and Azure OpenAI Responses agents:
import asyncio
import os
from agent_framework import AgentResponseUpdate, WorkflowBuilder
from agent_framework.foundry import FoundryChatClient
from azure.identity import AzureCliCredentialCreate one shared client that you can use to construct multiple agents:
async def main() -> None:
client = FoundryChatClient(
project_endpoint=os.environ["FOUNDRY_PROJECT_ENDPOINT"],
model=os.environ["FOUNDRY_MODEL"],
credential=AzureCliCredential(),
)Create two specialized agents for content creation and review:
# Create a Writer agent that generates content
writer_agent = client.as_agent(
name="Writer",
instructions=(
"You are an excellent content writer. You create new content and edit contents based on the feedback."
),
)
# Create a Reviewer agent that provides feedback
reviewer_agent = client.as_agent(
name="Reviewer",
instructions=(
"You are an excellent content reviewer. "
"Provide actionable feedback to the writer about the provided content. "
"Provide the feedback in the most concise manner possible."
),
)Connect the agents in a sequential workflow using the builder:
# Build the workflow with agents as executors
workflow = WorkflowBuilder(start_executor=writer_agent).add_edge(writer_agent, reviewer_agent).build()Run the workflow with streaming to observe real-time updates from both agents:
last_author: str | None = None
events = workflow.run("Create a slogan for a new electric SUV that is affordable and fun to drive.", stream=True)
async for event in events:
if event.type == "output" and isinstance(event.data, AgentResponseUpdate):
update = event.data
author = update.author_name
if author != last_author:
if last_author is not None:
print()
print(f"{author}: {update.text}", end="", flush=True)
last_author = author
else:
print(update.text, end="", flush=True)Wrap everything in the main function with proper async execution:
if __name__ == "__main__":
asyncio.run(main())- Client Setup: Uses one
FoundryChatClientwith Azure CLI credentials for authentication. - Agent Creation: Creates Writer and Reviewer agents from the same client configuration.
- Sequential Processing: Writer agent generates content first, then passes it to the Reviewer agent.
- Streaming Updates: Output events (
type="output") withAgentResponseUpdatedata provide real-time token updates as agents generate responses.
- FoundryChatClient: Shared client used to create workflow agents with consistent configuration.
- WorkflowEvent: Output events (
type="output") contain agent output data (AgentResponseUpdatefor streaming,AgentResponsefor non-streaming). - Sequential Workflow: Agents connected in a pipeline where output flows from one to the next.
For the complete working implementation, see azure_ai_agents_streaming.py in the Agent Framework repository.
::: zone-end
[!div class="nextstepaction"] Human-in-the-Loop