Skip to content

Commit

Permalink
Make prompt template factory a required parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
markwallace-microsoft committed Feb 20, 2025
1 parent c3d54dd commit 7a8ea73
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 9 deletions.
3 changes: 2 additions & 1 deletion dotnet/samples/GettingStartedWithAgents/Step01_Agent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,11 @@ public async Task UseTemplateForChatCompletionAgentAsync()
// Define the agent
string generateStoryYaml = EmbeddedResource.Read("GenerateStory.yaml");
PromptTemplateConfig templateConfig = KernelFunctionYaml.ToPromptTemplateConfig(generateStoryYaml);
KernelPromptTemplateFactory templateFactory = new();

// Instructions, Name and Description properties defined via the config.
ChatCompletionAgent agent =
new(templateConfig)
new(templateConfig, templateFactory)
{
Kernel = this.CreateKernelWithChatCompletion(),
Arguments =
Expand Down
3 changes: 2 additions & 1 deletion dotnet/samples/GettingStartedWithAgents/Step02_Plugins.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,12 @@ public async Task UseChatCompletionWithTemplateExecutionSettingsAsync()
// Read the template resource
string autoInvokeYaml = EmbeddedResource.Read("AutoInvokeTools.yaml");
PromptTemplateConfig templateConfig = KernelFunctionYaml.ToPromptTemplateConfig(autoInvokeYaml);
KernelPromptTemplateFactory templateFactory = new();

// Define the agent:
// Execution-settings with auto-invocation of plubins defined via the config.
ChatCompletionAgent agent =
new(templateConfig)
new(templateConfig, templateFactory)
{
Kernel = this.CreateKernelWithChatCompletion()
};
Expand Down
2 changes: 1 addition & 1 deletion dotnet/src/Agents/Core/ChatCompletionAgent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public ChatCompletionAgent() { }
/// a <see cref="PromptTemplateConfig"/>.
/// </summary>
/// <param name="templateConfig">The prompt template configuration.</param>
/// <param name="templateFactory">An optional factory to produce the <see cref="IPromptTemplate"/> for the agent.</param>
/// <param name="templateFactory">The prompt template factory used to produce the <see cref="IPromptTemplate"/> for the agent.</param>
public ChatCompletionAgent(
PromptTemplateConfig templateConfig,
IPromptTemplateFactory templateFactory)
Expand Down
13 changes: 7 additions & 6 deletions dotnet/src/Agents/UnitTests/Core/ChatCompletionAgentTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public void VerifyChatCompletionAgentDefinition()
[Fact]
public void VerifyChatCompletionAgentTemplate()
{
PromptTemplateConfig config =
PromptTemplateConfig promptConfig =
new()
{
Name = "TestName",
Expand All @@ -73,16 +73,17 @@ public void VerifyChatCompletionAgentTemplate()
},
}
};
KernelPromptTemplateFactory templateFactory = new();

// Arrange
ChatCompletionAgent agent = new(config);
ChatCompletionAgent agent = new(promptConfig, templateFactory);

// Assert
Assert.NotNull(agent.Id);
Assert.Equal(config.Template, agent.Instructions);
Assert.Equal(config.Description, agent.Description);
Assert.Equal(config.Name, agent.Name);
Assert.Equal(config.ExecutionSettings, agent.Arguments.ExecutionSettings);
Assert.Equal(promptConfig.Template, agent.Instructions);
Assert.Equal(promptConfig.Description, agent.Description);
Assert.Equal(promptConfig.Name, agent.Name);
Assert.Equal(promptConfig.ExecutionSettings, agent.Arguments.ExecutionSettings);
}

/// <summary>
Expand Down

0 comments on commit 7a8ea73

Please sign in to comment.