-
Notifications
You must be signed in to change notification settings - Fork 985
.NET: Declarative Agents #2476
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
markwallace-microsoft
merged 12 commits into
microsoft:main
from
markwallace-microsoft:users/markwallace/declarative-agents-dotnet
Dec 1, 2025
Merged
.NET: Declarative Agents #2476
Changes from 4 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
781a5ae
Update the declarative agent samples
markwallace-microsoft 8bf6dab
Add the Microsoft.Agents.AI.Declarative project
markwallace-microsoft c41afd5
Merge branch 'main' into users/markwallace/declarative-agents-dotnet
markwallace-microsoft 185aca6
Make the package non packable
markwallace-microsoft cb5b2bb
Use the RecalcEngine when creating the ChatOptions
markwallace-microsoft 6579bfe
Ignore VSTHRD200
markwallace-microsoft dbb885a
Merge branch 'main' into users/markwallace/declarative-agents-dotnet
markwallace-microsoft 242586d
Add geting started samples
markwallace-microsoft 5b7848e
Address code review feedback
markwallace-microsoft c6ebe6e
Merge branch 'main' into users/markwallace/declarative-agents-dotnet
markwallace-microsoft d77263f
Merge branch 'main' into users/markwallace/declarative-agents-dotnet
markwallace-microsoft e5924e4
Merge branch 'users/markwallace/declarative-agents-dotnet' of https:/…
markwallace-microsoft File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| kind: Prompt | ||
| name: Assistant | ||
| description: Helpful assistant | ||
| instructions: You are a helpful assistant. You answer questions in the language specified by the user. You return your answers in a JSON format. You must include Chat as the type in your response. | ||
| model: | ||
| id: gpt-4o-mini | ||
| provider: AzureOpenAI | ||
| apiType: Chat | ||
| options: | ||
| temperature: 0.9 | ||
| topP: 0.95 | ||
| outputSchema: | ||
| properties: | ||
| language: | ||
| type: string | ||
| required: true | ||
| description: The language of the answer. | ||
| answer: | ||
| type: string | ||
| required: true | ||
| description: The answer text. | ||
| type: | ||
| type: string | ||
| required: true | ||
| description: The type of the response. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,28 +1,25 @@ | ||
| kind: Prompt | ||
| name: Assistant | ||
| description: Helpful assistant | ||
| instructions: You are a helpful assistant. You answer questions is the language specified by the user. You return your answers in a JSON format. You must include Responses as the type in your response. | ||
| instructions: You are a helpful assistant. You answer questions in the language specified by the user. You return your answers in a JSON format. You must include Responses as the type in your response. | ||
| model: | ||
| id: =Env.AZURE_OPENAI_DEPLOYMENT_NAME | ||
| id: gpt-4o-mini | ||
| provider: AzureOpenAI | ||
| apiType: Responses | ||
| options: | ||
| text: | ||
| verbosity: medium | ||
| connection: | ||
| kind: remote | ||
| endpoint: =Env.AZURE_OPENAI_ENDPOINT | ||
| temperature: 0.9 | ||
| topP: 0.95 | ||
| outputSchema: | ||
| properties: | ||
| language: | ||
| kind: string | ||
| type: string | ||
| required: true | ||
| description: The language of the answer. | ||
| answer: | ||
| kind: string | ||
| type: string | ||
| required: true | ||
| description: The answer text. | ||
| type: | ||
| kind: string | ||
| type: string | ||
| required: true | ||
| description: The type of the response. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,18 +1,18 @@ | ||
| kind: Prompt | ||
| name: Assistant | ||
| description: Helpful assistant | ||
| instructions: You are a helpful assistant. You answer questions is the language specified by the user. You return your answers in a JSON format. | ||
| instructions: You are a helpful assistant. You answer questions in the language specified by the user. You return your answers in a JSON format. | ||
| model: | ||
| options: | ||
| temperature: 0.9 | ||
| topP: 0.95 | ||
| outputSchema: | ||
| properties: | ||
| language: | ||
| kind: string | ||
| type: string | ||
| required: true | ||
| description: The language of the answer. | ||
| answer: | ||
| kind: string | ||
| type: string | ||
| required: true | ||
| description: The answer text. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| kind: Prompt | ||
| name: Assistant | ||
| description: Helpful assistant | ||
| instructions: You are a helpful assistant. You answer questions in the language specified by the user. You return your answers in a JSON format. | ||
| model: | ||
| id: gpt-4.1-mini | ||
| options: | ||
| temperature: 0.9 | ||
| topP: 0.95 | ||
| connection: | ||
| kind: Remote | ||
markwallace-microsoft marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| endpoint: =Env.AZURE_FOUNDRY_PROJECT_ENDPOINT | ||
| outputSchema: | ||
| properties: | ||
| language: | ||
| type: string | ||
| required: true | ||
| description: The language of the answer. | ||
| answer: | ||
| type: string | ||
| required: true | ||
| description: The answer text. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,30 +1,28 @@ | ||
| kind: Prompt | ||
| name: Assistant | ||
| description: Helpful assistant | ||
| instructions: You are a helpful assistant. You answer questions is the language specified by the user. You return your answers in a JSON format. You must include Assistants as the type in your response. | ||
| instructions: You are a helpful assistant. You answer questions in the language specified by the user. You return your answers in a JSON format. You must include Assistants as the type in your response. | ||
| model: | ||
| id: =Env.OPENAI_MODEL | ||
| id: gpt-4.1-mini | ||
| provider: OpenAI | ||
| apiType: Assistants | ||
| options: | ||
| temperature: 0.9 | ||
| topP: 0.95 | ||
| connection: | ||
| kind: key | ||
| kind: ApiKey | ||
| key: =Env.OPENAI_APIKEY | ||
| outputSchema: | ||
| name: AssistantResponse | ||
| description: The response from the assistant. | ||
| properties: | ||
| language: | ||
| kind: string | ||
| type: string | ||
| required: true | ||
| description: The language of the answer. | ||
| answer: | ||
| kind: string | ||
| type: string | ||
| required: true | ||
| description: The answer text. | ||
| type: | ||
| kind: string | ||
| type: string | ||
| required: true | ||
| description: The type of the response. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| kind: Prompt | ||
| name: Assistant | ||
| description: Helpful assistant | ||
| instructions: You are a helpful assistant. You answer questions in the language specified by the user. You return your answers in a JSON format. You must include Chat as the type in your response. | ||
| model: | ||
| id: gpt-4.1-mini | ||
| provider: OpenAI | ||
| apiType: Chat | ||
| options: | ||
| temperature: 0.9 | ||
| topP: 0.95 | ||
| connection: | ||
| kind: ApiKey | ||
| key: =Env.OPENAI_APIKEY | ||
| outputSchema: | ||
| properties: | ||
| language: | ||
| type: string | ||
| required: true | ||
| description: The language of the answer. | ||
| answer: | ||
| type: string | ||
| required: true | ||
| description: The answer text. | ||
| type: | ||
| type: string | ||
| required: true | ||
| description: The type of the response. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,28 +1,28 @@ | ||
| kind: Prompt | ||
| name: Assistant | ||
| description: Helpful assistant | ||
| instructions: You are a helpful assistant. You answer questions is the language specified by the user. You return your answers in a JSON format. You must include Responses as the type in your response. | ||
| instructions: You are a helpful assistant. You answer questions in the language specified by the user. You return your answers in a JSON format. You must include Responses as the type in your response. | ||
| model: | ||
| id: =Env.OPENAI_MODEL | ||
| id: gpt-4.1-mini | ||
| provider: OpenAI | ||
| apiType: Responses | ||
| options: | ||
| text: | ||
| verbosity: medium | ||
| temperature: 0.9 | ||
| topP: 0.95 | ||
| connection: | ||
| kind: key | ||
| kind: ApiKey | ||
| key: =Env.OPENAI_APIKEY | ||
| outputSchema: | ||
| properties: | ||
| language: | ||
| kind: string | ||
| type: string | ||
| required: true | ||
| description: The language of the answer. | ||
| answer: | ||
| kind: string | ||
| type: string | ||
| required: true | ||
| description: The answer text. | ||
| type: | ||
| kind: string | ||
| type: string | ||
| required: true | ||
| description: The type of the response. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
dotnet/src/Microsoft.Agents.AI.Declarative/AgentBotElementYaml.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| // Copyright (c) Microsoft. All rights reserved. | ||
|
|
||
| using System; | ||
| using System.Diagnostics.CodeAnalysis; | ||
| using System.IO; | ||
| using System.Linq; | ||
| using Microsoft.Bot.ObjectModel; | ||
| using Microsoft.Bot.ObjectModel.Abstractions; | ||
| using Microsoft.Bot.ObjectModel.Yaml; | ||
| using Microsoft.Extensions.Configuration; | ||
| using Microsoft.Shared.Diagnostics; | ||
|
|
||
| namespace Microsoft.Agents.AI; | ||
|
|
||
| /// <summary> | ||
| /// Helper methods for creating <see cref="BotElement"/> from YAML. | ||
| /// </summary> | ||
| internal static class AgentBotElementYaml | ||
| { | ||
| /// <summary> | ||
| /// Convert the given YAML text to a <see cref="GptComponentMetadata"/> model. | ||
| /// </summary> | ||
| /// <param name="text">YAML representation of the <see cref="BotElement"/> to use to create the prompt function.</param> | ||
| /// <param name="configuration">Optional <see cref="IConfiguration"/> instance which provides environment variables to the template.</param> | ||
| [RequiresDynamicCode("Calls YamlDotNet.Serialization.DeserializerBuilder.DeserializerBuilder()")] | ||
| public static GptComponentMetadata FromYaml(string text, IConfiguration? configuration = null) | ||
| { | ||
| Throw.IfNullOrEmpty(text); | ||
|
|
||
| using var yamlReader = new StringReader(text); | ||
| BotElement rootElement = YamlSerializer.Deserialize<BotElement>(yamlReader) ?? throw new InvalidDataException("Text does not contain a valid agent definition."); | ||
|
|
||
| if (rootElement is not GptComponentMetadata promptAgent) | ||
| { | ||
| throw new InvalidDataException($"Unsupported root element: {rootElement.GetType().Name}. Expected an {nameof(GptComponentMetadata)}."); | ||
| } | ||
|
|
||
| var botDefinition = WrapPromptAgentWithBot(promptAgent, configuration); | ||
|
|
||
| return botDefinition.Descendants().OfType<GptComponentMetadata>().First(); | ||
| } | ||
|
|
||
| #region private | ||
| private sealed class AgentFeatureConfiguration : IFeatureConfiguration | ||
| { | ||
| public long GetInt64Value(string settingName, long defaultValue) => defaultValue; | ||
|
|
||
| public string GetStringValue(string settingName, string defaultValue) => defaultValue; | ||
|
|
||
| public bool IsEnvironmentFeatureEnabled(string featureName, bool defaultValue) => true; | ||
|
|
||
| public bool IsTenantFeatureEnabled(string featureName, bool defaultValue) => defaultValue; | ||
| } | ||
|
|
||
| public static BotDefinition WrapPromptAgentWithBot(this GptComponentMetadata element, IConfiguration? configuration = null) | ||
| { | ||
| var botBuilder = | ||
| new BotDefinition.Builder | ||
| { | ||
| Components = | ||
| { | ||
| new GptComponent.Builder | ||
| { | ||
| SchemaName = "default-schema", | ||
| Metadata = element.ToBuilder(), | ||
| } | ||
| } | ||
| }; | ||
|
|
||
| if (configuration is not null) | ||
| { | ||
| foreach (var kvp in configuration.AsEnumerable().Where(kvp => kvp.Value is not null)) | ||
| { | ||
| botBuilder.EnvironmentVariables.Add(new EnvironmentVariableDefinition.Builder() | ||
| { | ||
| SchemaName = kvp.Key, | ||
| Id = Guid.NewGuid(), | ||
| DisplayName = kvp.Key, | ||
| ValueComponent = new EnvironmentVariableValue.Builder() | ||
| { | ||
| Id = Guid.NewGuid(), | ||
| Value = kvp.Value!, | ||
| }, | ||
| }); | ||
| } | ||
| } | ||
|
|
||
| return botBuilder.Build(); | ||
| } | ||
| #endregion | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.