Skip to content

Commit 313575c

Browse files
authored
Merge pull request #736 from jozkee/docs_workflows
Suggestions for tutorials/workflow
2 parents 7fa2188 + ff5f0bb commit 313575c

11 files changed

Lines changed: 269 additions & 193 deletions

agent-framework/tutorials/agents/agent-as-mcp-tool.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ For prerequisites see the [Create and run a simple agent](./run-agent.md#prerequ
2424
To use Microsoft Agent Framework with Azure OpenAI, you need to install the following NuGet packages:
2525

2626
```dotnetcli
27+
dotnet add package Azure.AI.OpenAI --prerelease
2728
dotnet add package Azure.Identity
28-
dotnet add package Azure.AI.OpenAI
2929
dotnet add package Microsoft.Agents.AI.OpenAI --prerelease
3030
```
3131

agent-framework/tutorials/agents/enable-observability.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ For prerequisites, see the [Create and run a simple agent](./run-agent.md#prereq
2828
To use Microsoft Agent Framework with Azure OpenAI, you need to install the following NuGet packages:
2929

3030
```dotnetcli
31+
dotnet add package Azure.AI.OpenAI --prerelease
3132
dotnet add package Azure.Identity
32-
dotnet add package Azure.AI.OpenAI
3333
dotnet add package Microsoft.Agents.AI.OpenAI --prerelease
3434
```
3535

agent-framework/tutorials/agents/run-agent.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ Before you begin, ensure you have the following prerequisites:
3838
To use Microsoft Agent Framework with Azure OpenAI, you need to install the following NuGet packages:
3939

4040
```dotnetcli
41+
dotnet add package Azure.AI.OpenAI --prerelease
4142
dotnet add package Azure.Identity
42-
dotnet add package Azure.AI.OpenAI
4343
dotnet add package Microsoft.Agents.AI.OpenAI --prerelease
4444
```
4545

agent-framework/tutorials/agents/third-party-chat-history-storage.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ For prerequisites, see the [Create and run a simple agent](./run-agent.md) step
2828
To use Microsoft Agent Framework with Azure OpenAI, you need to install the following NuGet packages:
2929

3030
```dotnetcli
31+
dotnet add package Azure.AI.OpenAI --prerelease
3132
dotnet add package Azure.Identity
32-
dotnet add package Azure.AI.OpenAI
3333
dotnet add package Microsoft.Agents.AI.OpenAI --prerelease
3434
```
3535

agent-framework/tutorials/quick-start.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ Packages will be published to [NuGet Gallery | MicrosoftAgentFramework](https://
3939
First, add the following Microsoft Agent Framework NuGet packages into your application, using the following commands:
4040

4141
```dotnetcli
42-
dotnet add package Azure.AI.OpenAI
42+
dotnet add package Azure.AI.OpenAI --prerelease
4343
dotnet add package Azure.Identity
4444
dotnet add package Microsoft.Agents.AI.OpenAI --prerelease
4545
```

agent-framework/tutorials/workflows/agents-in-workflows.md

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,25 @@ You'll create a workflow that:
2929

3030
## Prerequisites
3131

32-
- .NET 9.0 or later
33-
- Agent Framework installed via NuGet
34-
- Azure Foundry project configured with proper environment variables
35-
- Azure CLI authentication: `az login`
32+
- [.NET 8.0 SDK or later](https://dotnet.microsoft.com/download)
33+
- Azure Foundry service endpoint and deployment configured
34+
- [Azure CLI installed](/cli/azure/install-azure-cli) and [authenticated (for Azure credential authentication)](/cli/azure/authenticate-azure-cli)
35+
- A new console application
3636

37-
## Step 1: Import Required Dependencies
37+
## Step 1: Install NuGet packages
38+
39+
First, install the required packages for your .NET project:
40+
41+
```dotnetcli
42+
dotnet add package Azure.AI.Agents.Persistent --prerelease
43+
dotnet add package Azure.Identity
44+
dotnet add package Microsoft.Agents.AI.AzureAI --prerelease
45+
dotnet add package Microsoft.Agents.AI.Workflows --prerelease
46+
```
47+
48+
## Step 2: Set Up Azure Foundry Client
3849

39-
Start by importing the necessary components for Azure Foundry agents and workflows:
50+
Configure the Azure Foundry client with environment variables and authentication:
4051

4152
```csharp
4253
using System;
@@ -46,20 +57,13 @@ using Azure.Identity;
4657
using Microsoft.Agents.AI;
4758
using Microsoft.Agents.AI.Workflows;
4859
using Microsoft.Extensions.AI;
49-
```
50-
51-
## Step 2: Set Up Azure Foundry Client
5260

53-
Configure the Azure Foundry client with environment variables and authentication:
54-
55-
```csharp
5661
public static class Program
5762
{
5863
private static async Task Main()
5964
{
6065
// Set up the Azure Foundry client
61-
var endpoint = Environment.GetEnvironmentVariable("AZURE_FOUNDRY_PROJECT_ENDPOINT")
62-
?? throw new InvalidOperationException("AZURE_FOUNDRY_PROJECT_ENDPOINT is not set.");
66+
var endpoint = Environment.GetEnvironmentVariable("AZURE_FOUNDRY_PROJECT_ENDPOINT") ?? throw new Exception("AZURE_FOUNDRY_PROJECT_ENDPOINT is not set.");
6367
var model = Environment.GetEnvironmentVariable("AZURE_FOUNDRY_PROJECT_MODEL_ID") ?? "gpt-4o-mini";
6468
var persistentAgentsClient = new PersistentAgentsClient(endpoint, new AzureCliCredential());
6569
```
@@ -116,11 +120,11 @@ Connect the agents in a sequential workflow using the WorkflowBuilder:
116120

117121
## Step 6: Execute with Streaming
118122

119-
Run the workflow with streaming to observe real-time updates from both agents:
123+
Run the workflow with streaming to observe real-time updates from all agents:
120124

121125
```csharp
122126
// Execute the workflow
123-
StreamingRun run = await InProcessExecution.StreamAsync(workflow, new ChatMessage(ChatRole.User, "Hello World!"));
127+
await using StreamingRun run = await InProcessExecution.StreamAsync(workflow, new ChatMessage(ChatRole.User, "Hello World!"));
124128

125129
// Must send the turn token to trigger the agents.
126130
// The agents are wrapped as executors. When they receive messages,

agent-framework/tutorials/workflows/checkpointing-and-resuming.md

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,21 @@ Checkpointing allows workflows to save their state at specific points and resume
1515

1616
::: zone pivot="programming-language-csharp"
1717

18+
## Prerequisites
19+
20+
- [.NET 8.0 SDK or later](https://dotnet.microsoft.com/download)
21+
- A new console application
22+
1823
## Key Components
1924

25+
## Install NuGet packages
26+
27+
First, install the required packages for your .NET project:
28+
29+
```dotnetcli
30+
dotnet add package Microsoft.Agents.AI.Workflows --prerelease
31+
```
32+
2033
### CheckpointManager
2134

2235
The `CheckpointManager` provides checkpoint storage and retrieval functionality:
@@ -43,44 +56,48 @@ var workflow = await WorkflowHelper.GetWorkflowAsync();
4356
var checkpointManager = CheckpointManager.Default;
4457

4558
// Execute with checkpointing enabled
46-
Checkpointed<StreamingRun> checkpointedRun = await InProcessExecution
59+
await using Checkpointed<StreamingRun> checkpointedRun = await InProcessExecution
4760
.StreamAsync(workflow, NumberSignal.Init, checkpointManager);
4861
```
4962

5063
## State Persistence
5164

5265
### Executor State
5366

54-
Executors can persist local state that survives checkpoints using the `ReflectingExecutor` base class:
67+
Executors can persist local state that survives checkpoints using the `Executor<T>` base class:
5568

5669
```csharp
57-
internal sealed class GuessNumberExecutor : ReflectingExecutor<GuessNumberExecutor>, IMessageHandler<NumberSignal>
70+
internal sealed class GuessNumberExecutor : Executor<NumberSignal>
5871
{
59-
private static readonly StateKey StateKey = new("GuessNumberExecutor.State");
72+
private const string StateKey = "GuessNumberExecutor.State";
6073

6174
public int LowerBound { get; private set; }
6275
public int UpperBound { get; private set; }
6376

64-
public async ValueTask HandleAsync(NumberSignal message, IWorkflowContext context)
77+
public GuessNumberExecutor() : base("GuessNumber")
78+
{
79+
}
80+
81+
public override async ValueTask HandleAsync(NumberSignal message, IWorkflowContext context, CancellationToken cancellationToken = default)
6582
{
6683
int guess = (LowerBound + UpperBound) / 2;
67-
await context.SendMessageAsync(guess);
84+
await context.SendMessageAsync(guess, cancellationToken);
6885
}
6986

7087
/// <summary>
7188
/// Checkpoint the current state of the executor.
7289
/// This must be overridden to save any state that is needed to resume the executor.
7390
/// </summary>
7491
protected override ValueTask OnCheckpointingAsync(IWorkflowContext context, CancellationToken cancellationToken = default) =>
75-
context.QueueStateUpdateAsync(StateKey, (LowerBound, UpperBound));
92+
context.QueueStateUpdateAsync(StateKey, (LowerBound, UpperBound), cancellationToken);
7693

7794
/// <summary>
7895
/// Restore the state of the executor from a checkpoint.
7996
/// This must be overridden to restore any state that was saved during checkpointing.
8097
/// </summary>
8198
protected override async ValueTask OnCheckpointRestoredAsync(IWorkflowContext context, CancellationToken cancellationToken = default)
8299
{
83-
var state = await context.ReadStateAsync<(int, int)>(StateKey);
100+
var state = await context.ReadStateAsync<(int, int)>(StateKey, cancellationToken);
84101
(LowerBound, UpperBound) = state;
85102
}
86103
}
@@ -158,7 +175,7 @@ Resume execution from a checkpoint and stream events in real-time:
158175
// Resume from a specific checkpoint with streaming
159176
CheckpointInfo savedCheckpoint = checkpoints[checkpointIndex];
160177

161-
Checkpointed<StreamingRun> resumedRun = await InProcessExecution
178+
await using Checkpointed<StreamingRun> resumedRun = await InProcessExecution
162179
.ResumeStreamAsync(workflow, savedCheckpoint, checkpointManager, runId);
163180

164181
await foreach (WorkflowEvent evt in resumedRun.Run.WatchStreamAsync())
@@ -218,7 +235,7 @@ Create a new workflow instance from a checkpoint:
218235
var newWorkflow = await WorkflowHelper.GetWorkflowAsync();
219236

220237
// Resume with the new instance from a saved checkpoint
221-
Checkpointed<StreamingRun> newCheckpointedRun = await InProcessExecution
238+
await using Checkpointed<StreamingRun> newCheckpointedRun = await InProcessExecution
222239
.ResumeStreamAsync(newWorkflow, savedCheckpoint, checkpointManager, originalRunId);
223240

224241
await foreach (WorkflowEvent evt in newCheckpointedRun.Run.WatchStreamAsync())
@@ -300,7 +317,7 @@ public static class CheckpointingExample
300317
Console.WriteLine("Starting workflow with checkpointing...");
301318

302319
// Execute workflow with checkpointing
303-
Checkpointed<StreamingRun> checkpointedRun = await InProcessExecution
320+
await using Checkpointed<StreamingRun> checkpointedRun = await InProcessExecution
304321
.StreamAsync(workflow, NumberSignal.Init, checkpointManager);
305322

306323
// Monitor execution and collect checkpoints
@@ -357,7 +374,7 @@ public static class CheckpointingExample
357374

358375
Console.WriteLine("Rehydrating from checkpoint 4 with new workflow instance...");
359376

360-
Checkpointed<StreamingRun> newRun = await InProcessExecution
377+
await using Checkpointed<StreamingRun> newRun = await InProcessExecution
361378
.ResumeStreamAsync(newWorkflow, rehydrationCheckpoint, checkpointManager, checkpointedRun.Run.RunId);
362379

363380
await foreach (WorkflowEvent evt in newRun.Run.WatchStreamAsync())

0 commit comments

Comments
 (0)