Skip to content

Commit 09cd903

Browse files
authored
Replace the OrchestrationMonitor in samples (#579)
1 parent c899085 commit 09cd903

4 files changed

Lines changed: 40 additions & 16 deletions

File tree

semantic-kernel/Frameworks/agent/agent-orchestration/group-chat.md

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,16 @@ ChatCompletionAgent editor = new ChatCompletionAgent {
6565

6666
### Optional: Observe Agent Responses
6767

68-
You can create a monitor to capture agent responses as the sequence progresses via the `ResponseCallback` property.
68+
You can create a callback to capture agent responses as the sequence progresses via the `ResponseCallback` property.
6969

7070
```csharp
71-
OrchestrationMonitor monitor = new();
71+
ChatHistory history = [];
72+
73+
ValueTask responseCallback(ChatMessageContent response)
74+
{
75+
history.Add(response);
76+
return ValueTask.CompletedTask;
77+
}
7278
```
7379

7480
### Set Up the Group Chat Orchestration
@@ -81,7 +87,7 @@ GroupChatOrchestration orchestration = new GroupChatOrchestration(
8187
writer,
8288
editor)
8389
{
84-
ResponseCallback = monitor.ResponseCallback,
90+
ResponseCallback = responseCallback,
8591
};
8692
```
8793

@@ -112,7 +118,7 @@ Wait for the orchestration to complete and retrieve the final output.
112118
string output = await result.GetValueAsync(TimeSpan.FromSeconds(60));
113119
Console.WriteLine($"\n# RESULT: {text}");
114120
Console.WriteLine("\n\nORCHESTRATION HISTORY");
115-
foreach (ChatMessageContent message in monitor.History)
121+
foreach (ChatMessageContent message in history)
116122
{
117123
this.WriteAgentChatMessage(message);
118124
}

semantic-kernel/Frameworks/agent/agent-orchestration/handoff.md

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,16 @@ var handoffs = OrchestrationHandoffs
112112

113113
### Observe Agent Responses
114114

115-
You can create a monitor to capture agent responses as the conversation progresses via the `ResponseCallback` property.
115+
You can create a callback to capture agent responses as the conversation progresses via the `ResponseCallback` property.
116116

117117
```csharp
118-
OrchestrationMonitor monitor = new();
118+
ChatHistory history = [];
119+
120+
ValueTask responseCallback(ChatMessageContent response)
121+
{
122+
history.Add(response);
123+
return ValueTask.CompletedTask;
124+
}
119125
```
120126

121127
### Human in the Loop
@@ -153,7 +159,7 @@ HandoffOrchestration orchestration = new HandoffOrchestration(
153159
refundAgent)
154160
{
155161
InteractiveCallback = interactiveCallback,
156-
ResponseCallback = monitor.ResponseCallback,
162+
ResponseCallback = responseCallback,
157163
};
158164
```
159165

@@ -183,7 +189,7 @@ Wait for the orchestration to complete and retrieve the final output.
183189
string output = await result.GetValueAsync(TimeSpan.FromSeconds(300));
184190
Console.WriteLine($"\n# RESULT: {output}");
185191
Console.WriteLine("\n\nORCHESTRATION HISTORY");
186-
foreach (ChatMessageContent message in monitor.History)
192+
foreach (ChatMessageContent message in history)
187193
{
188194
// Print each message
189195
Console.WriteLine($"# {message.Role} - {message.AuthorName}: {message.Content}");

semantic-kernel/Frameworks/agent/agent-orchestration/magentic.md

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,16 @@ StandardMagenticManager manager = new StandardMagenticManager(
102102

103103
### Optional: Observe Agent Responses
104104

105-
You can create a monitor to capture agent responses as the orchestration progresses via the `ResponseCallback` property.
105+
You can create a callback to capture agent responses as the orchestration progresses via the `ResponseCallback` property.
106106

107107
```csharp
108-
OrchestrationMonitor monitor = new();
108+
ChatHistory history = [];
109+
110+
ValueTask responseCallback(ChatMessageContent response)
111+
{
112+
history.Add(response);
113+
return ValueTask.CompletedTask;
114+
}
109115
```
110116

111117
### Create the Magentic Orchestration
@@ -118,7 +124,7 @@ MagenticOrchestration orchestration = new MagenticOrchestration(
118124
researchAgent,
119125
coderAgent)
120126
{
121-
ResponseCallback = monitor.ResponseCallback,
127+
ResponseCallback = responseCallback,
122128
};
123129
```
124130

@@ -148,7 +154,7 @@ Wait for the orchestration to complete and retrieve the final output.
148154
string output = await result.GetValueAsync(TimeSpan.FromSeconds(300));
149155
Console.WriteLine($"\n# RESULT: {output}");
150156
Console.WriteLine("\n\nORCHESTRATION HISTORY");
151-
foreach (ChatMessageContent message in monitor.History)
157+
foreach (ChatMessageContent message in history)
152158
{
153159
// Print each message
154160
Console.WriteLine($"# {message.Role} - {message.AuthorName}: {message.Content}");

semantic-kernel/Frameworks/agent/agent-orchestration/sequential.md

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,16 @@ ChatCompletionAgent editorAgent = new ChatCompletionAgent {
6868

6969
### Optional: Observe Agent Responses
7070

71-
You can create a monitor to capture agent responses as the sequence progresses via the `ResponseCallback` property.
71+
You can create a callback to capture agent responses as the sequence progresses via the `ResponseCallback` property.
7272

7373
```csharp
74-
OrchestrationMonitor monitor = new();
74+
ChatHistory history = [];
75+
76+
ValueTask responseCallback(ChatMessageContent response)
77+
{
78+
history.Add(response);
79+
return ValueTask.CompletedTask;
80+
}
7581
```
7682

7783
### Set Up the Sequential Orchestration
@@ -81,7 +87,7 @@ Create a `SequentialOrchestration` object, passing in the agents and the optiona
8187
```csharp
8288
SequentialOrchestration orchestration = new(analystAgent, writerAgent, editorAgent)
8389
{
84-
ResponseCallback = monitor.ResponseCallback,
90+
ResponseCallback = responseCallback,
8591
};
8692
```
8793

@@ -112,7 +118,7 @@ Wait for the orchestration to complete and retrieve the final output.
112118
string output = await result.GetValueAsync(TimeSpan.FromSeconds(20));
113119
Console.WriteLine($"\n# RESULT: {text}");
114120
Console.WriteLine("\n\nORCHESTRATION HISTORY");
115-
foreach (ChatMessageContent message in monitor.History)
121+
foreach (ChatMessageContent message in history)
116122
{
117123
this.WriteAgentChatMessage(message);
118124
}

0 commit comments

Comments
 (0)