Skip to content

Commit

Permalink
.Net: Agents - Getting Started Step4 Improvement: Cross Model (#6044)
Browse files Browse the repository at this point in the history
### Motivation and Context
<!-- Thank you for your contribution to the semantic-kernel repo!
Please help reviewers and future users, providing the following
information:
  1. Why is this change required?
  2. What problem does it solve?
  3. What scenario does it contribute to?
  4. If it fixes an open issue, please link to the issue here.
-->


[Step4_KernelFunctionStrategies](https://github.com/microsoft/semantic-kernel/blob/main/dotnet/samples/GettingStartedWithAgents/Step4_KernelFunctionStrategies.cs)
was either:
1. Failing with null selection
2. Exceeding model token limit
3. Not performing the requested task

### Description
<!-- Describe your changes, the overall approach, the underlying design.
These notes will help understanding how your code works. Thanks! -->

A couple things at play here:
1. The selection prompt was copied from AutoGen. While it worked on
`GPT-4`, it wasn't generating a reliable result for `GPT-3.5-Turbo`
2. The agent instructions were never tuned outsidre of `GPT-4`
3. No sensible default / fall-through (can't trust model 100%)
4. 4k token limit may be too low for history evaluation. Tested with
`gpt-35-turbo-16k`

> Note: When formal support for history manipulation comes on line, we
should be able to optimize around last(n) messages.

### Contribution Checklist
<!-- Before submitting this PR, please make sure: -->

- [X] The code builds clean without any errors or warnings
- [X] The PR follows the [SK Contribution
Guidelines](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md)
and the [pre-submission formatting
script](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md#development-scripts)
raises no violations
- [X] All unit tests pass, and I have added new tests where possible
- [X] I didn't break anyone 😄
  • Loading branch information
crickman committed Apr 29, 2024
1 parent 7b47854 commit 80aa777
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 11 deletions.
6 changes: 4 additions & 2 deletions dotnet/samples/Concepts/Agents/MixedChat_Agents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@ public class MixedChat_Agents(ITestOutputHelper output) : BaseTest(output)
If not, provide insight on how to refine suggested copy without example.
""";

private const string CopyWriterName = "Writer";
private const string CopyWriterName = "CopyWriter";
private const string CopyWriterInstructions =
"""
You are a copywriter with ten years of experience and are known for brevity and a dry humor.
You're laser focused on the goal at hand. Don't waste time with chit chat.
The goal is to refine and decide on the single best copy as an expert in the field.
Only provide a single proposal per response.
You're laser focused on the goal at hand.
Don't waste time with chit chat.
Consider suggestions when refining an idea.
""";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@ public class Step4_KernelFunctionStrategies(ITestOutputHelper output) : BaseTest
If not, provide insight on how to refine suggested copy without examples.
""";

private const string CopyWriterName = "Writer";
private const string CopyWriterName = "CopyWriter";
private const string CopyWriterInstructions =
"""
You are a copywriter with ten years of experience and are known for brevity and a dry humor.
You're laser focused on the goal at hand. Don't waste time with chit chat.
The goal is to refine and decide on the single best copy as an expert in the field.
Only provide a single proposal per response.
You're laser focused on the goal at hand.
Don't waste time with chit chat.
Consider suggestions when refining an idea.
""";

Expand Down Expand Up @@ -61,12 +63,18 @@ public async Task RunAsync()

KernelFunction selectionFunction =
KernelFunctionFactory.CreateFromPrompt(
"""
You are in a role playing game.
Carefully read the conversation history and carry on the conversation by specifying only the name of player to take the next turn.

The available names are:
{{$agents}}
$$$"""
Your job is to determine which participant takes the next turn in a conversation according to the action of the most recent participant.
State only the name of the participant to take the next turn.

Choose only from these participants:
- {{{ReviewerName}}}
- {{{CopyWriterName}}}

Always follow these rules when selecting the next participant:
- After user input, it is {{{CopyWriterName}}}'a turn.
- After {{{CopyWriterName}}} replies, it is {{{ReviewerName}}}'s turn.
- After {{{ReviewerName}}} provides feedback, it is {{{CopyWriterName}}}'s turn.

History:
{{$history}}
Expand Down Expand Up @@ -98,7 +106,7 @@ public async Task RunAsync()
new KernelFunctionSelectionStrategy(selectionFunction, CreateKernelWithChatCompletion())
{
// Returns the entire result value as a string.
ResultParser = (result) => result.GetValue<string>() ?? string.Empty,
ResultParser = (result) => result.GetValue<string>() ?? CopyWriterName,
// The prompt variable name for the agents argument.
AgentsVariableName = "agents",
// The prompt variable name for the history argument.
Expand Down

0 comments on commit 80aa777

Please sign in to comment.