You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The agent framework is still going through API churn as it heads to GA (see microsoft/agent-framework#2542).
Rather than delaying v1 of Devlooped.Extensions.AI (and Grok support), declouple the two and ship from independent repos. The MS.E.AI API is far more stable at this point.
Console.WriteLine($"Agent: {agent.Name} by {metadata.ProviderName}");
100
-
}
101
-
```
102
-
103
-
You can of course use any config format supported by .NET configuration, such as
104
-
TOML which is arguably more human-friendly for hand-editing:
105
-
106
-
```toml
107
-
[ai.clients.openai]
108
-
modelid = "gpt-4.1"
109
-
110
-
[ai.clients.grok]
111
-
endpoint = "https://api.x.ai/v1"
112
-
modelid = "grok-4-fast-non-reasoning"
113
-
114
-
[ai.agents.orders]
115
-
description = "Manage orders using catalogs for food or any other item."
116
-
instructions = """
117
-
You are an AI agent responsible for processing orders for food or other items.
118
-
Your primary goals are to identify user intent, extract or request provider information, manage order data using tools and friendly responses to guide users through the ordering process.
119
-
"""
120
-
121
-
# ai.clients.openai, can omit the ai.clients prefix
122
-
client = "openai"
123
-
124
-
[ai.agents.orders.options]
125
-
modelid = "gpt-4o-mini"
126
-
```
127
-
128
-
This can be used by leveraging [Tomlyn.Extensions.Configuration](https://www.nuget.org/packages/Tomlyn.Extensions.Configuration).
129
-
130
-
> [!NOTE]
131
-
> This package will automatically dedent and trim start and end newlines from
132
-
> multi-line instructions and descriptions when applying the configuration,
133
-
> avoiding unnecessary tokens being used for indentation while allowing flexible
134
-
> formatting in the config file.
135
-
136
-
You can also leverage the format pioneered by [VS Code Chat Modes](https://code.visualstudio.com/docs/copilot/customization/custom-chat-modes),
137
-
(por "custom agents") by using markdown format plus YAML front-matter for better readability:
138
-
139
-
```yaml
140
-
---
141
-
id: ai.agents.notes
142
-
description: Provides free-form memory
143
-
client: grok
144
-
model: grok-4-fast
145
-
---
146
-
You organize and keep notes for the user.
147
-
# Some header
148
-
More content
149
-
```
150
-
151
-
Visual Studio Code will ignore the additional attributes used by this project. In particular, the `model`
152
-
property is a shorthand for setting the `options.modelid`, but in our implementation, the latter takes
153
-
precedence over the former, which allows you to rely on `model` to drive the VSCode testing, and the
154
-
longer form for run-time with the Agents Framework:
155
-
156
-
```yaml
157
-
---
158
-
id: ai.agents.notes
159
-
description: Provides free-form memory
160
-
model: Grok Code Fast 1 (copilot)
161
-
client: grok
162
-
options:
163
-
modelid: grok-code-fast-1
164
-
---
165
-
// Instructions
166
-
```
167
-
168
-

169
-
170
-
Use the provided `AddAgentMarkdown` extension method to load instructions from files as follows:
The `id` field in the front-matter is required and specifies the configuration section name, and
178
-
all other fields are added as if they were specified under it in the configuration.
179
-
180
-
### Extensible AI Contexts
181
-
182
-
The Microsoft [agent framework](https://learn.microsoft.com/en-us/agent-framework/overview/agent-framework-overview) allows extending
183
-
agents with dynamic context via [AIContextProvider](https://learn.microsoft.com/en-us/dotnet/api/microsoft.agents.ai.aicontextprovider)
184
-
and `AIContext`. This package supports dynamic extension of a configured agent in the following ways (in order of priority):
185
-
186
-
1. A keyed service `AIContextProviderFactory` with the same name as the agent will be set up just as if you had
187
-
set it manually as the [ChatClientAgentOptions.AIContextProviderFactory](https://learn.microsoft.com/en-us/dotnet/api/microsoft.agents.ai.chatclientagentoptions.aicontextproviderfactory)
188
-
in code.
189
-
2. Aggregate of AI contexts from:
190
-
a. Keyed service `AIContextProvider` with the same name as the agent.
191
-
b. Keyed service `AIContext` with the same name as the agent.
192
-
c. Other services pulled in via `use` setting for an agent registered as either `AIContextProvider` or `AIContext`
193
-
with a matching key.
194
-
195
-
The first option assumes you want full control of the context, so it does not allow futher composition.
196
-
The second alternative allows more declarative scenarios involving reusable and cross-cutting
197
-
context definitions.
198
-
199
-
For example, let's say you want to provide consistent tone for all your agents. It would be tedious, repetitive and harder
200
-
to maintain if you had to set that in each agent's instructions. Instead, you can define a reusable context named `tone` such as:
201
-
202
-
```toml
203
-
[ai.context.tone]
204
-
instructions = """\
205
-
Default to using spanish language, using argentinean "voseo" in your responses \
206
-
(unless the user explicitly talks in a different language). \
207
-
This means using "vos" instead of "tú" and conjugating verbs accordingly. \
208
-
Don't use the expression "pa'" instead of "para". Don't mention the word "voseo".
209
-
"""
210
-
```
211
-
212
-
Then, you can reference that context in any agent using the `use` setting:
213
-
```toml
214
-
[ai.agents.support]
215
-
description = "An AI agent that helps with customer support."
216
-
instructions = "..."
217
-
client = "grok"
218
-
use = ["tone"]
219
-
220
-
[ai.agents.sales]
221
-
description = "An AI agent that helps with sales inquiries."
222
-
instructions = "..."
223
-
client = "openai"
224
-
use = ["tone"]
225
-
```
226
-
227
-
Configured contexts can provide all three components of an `AIContext`: instructions, messages and tools, such as:
228
-
229
-
```toml
230
-
[ai.context.timezone]
231
-
instructions = "Always assume the user's timezone is America/Argentina/Buenos_Aires unless specified otherwise."
232
-
messages = [
233
-
{ system = "You are aware of the current date and time in America/Argentina/Buenos_Aires." }
234
-
]
235
-
tools = ["get_date"]
236
-
```
237
-
238
-
If multiple contexts are specified in `use`, they are applied in order, concatenating their instructions, messages and tools.
239
-
240
-
In addition to configured sections, the `use` property can also reference exported contexts as either `AIContext`
241
-
(for static context) or `AIContextProvider` (for dynamic context) registered in DI with a matching name.
242
-
243
-
244
-
### Extensible Tools
245
-
246
-
The `tools` section allows specifying tool names registered in the DI container, such as:
0 commit comments