@polymorphism-tech/morph-spec 7.2.0 → 7.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CLAUDE.md +1 -1
- package/README.md +2 -2
- package/bin/morph-spec.js +4 -2
- package/claude-plugin.json +1 -1
- package/docs/CHEATSHEET.md +1 -1
- package/docs/QUICKSTART.md +1 -1
- package/framework/CLAUDE.md +2 -2
- package/framework/MORPH.md +29 -12
- package/framework/agents.json +132 -132
- package/framework/commands/morph-apply.md +1 -1
- package/framework/commands/morph-proposal.md +1 -1
- package/framework/evals/rubrics/README.md +9 -8
- package/framework/hooks/README.md +3 -1
- package/framework/hooks/claude-code/core/gate-guard.js +160 -0
- package/framework/hooks/claude-code/core/state-sync.js +15 -3
- package/framework/hooks/claude-code/core/validate-completion.js +241 -136
- package/framework/hooks/shared/state-reader.js +236 -221
- package/framework/phases.json +1 -1
- package/framework/skills/README.md +2 -2
- package/framework/skills/core/morph-apply/SKILL.md +63 -21
- package/framework/skills/core/morph-brainstorming/SKILL.md +5 -1
- package/framework/skills/core/morph-eval/SKILL.md +4 -5
- package/framework/skills/core/morph-implement/SKILL.md +47 -19
- package/framework/skills/core/morph-plan/SKILL.md +8 -2
- package/framework/skills/core/morph-proposal/SKILL.md +1 -1
- package/framework/skills/core/morph-review/SKILL.md +13 -6
- package/framework/skills/core/morph-stack-scan/SKILL.md +1 -1
- package/framework/skills/core/morph-standards/SKILL.md +1 -1
- package/framework/standards/ai-agents/setup.md +258 -244
- package/framework/templates/README.md +708 -709
- package/framework/templates/REGISTRY.json +1 -20
- package/framework/templates/context/CONTEXT-FEATURE.md +276 -276
- package/framework/templates/docs/proposal.md +171 -171
- package/framework/templates/feature/recap.md +145 -145
- package/package.json +1 -1
- package/src/commands/project/doctor.js +941 -946
- package/src/commands/project/init.js +517 -515
- package/src/commands/project/status.js +373 -376
- package/src/commands/state/approve.js +251 -213
- package/src/commands/validation/validate-feature.js +356 -287
- package/src/core/state/state-manager.js +910 -934
- package/src/dashboard/app/App.jsx +29 -31
- package/src/dashboard/app/components/Sidebar.jsx +44 -45
- package/src/dashboard/scanner/index.js +20 -21
- package/src/lib/context/context-builder.js +3 -3
- package/src/lib/generators/context-generator.js +2 -3
- package/src/lib/generators/mandate-generator.js +48 -92
- package/src/lib/generators/metadata-extractor.js +385 -386
- package/src/lib/generators/recap-generator.js +285 -285
- package/src/lib/risk-detector.js +2 -2
- package/src/lib/validators/content/content-validator.js +89 -286
- package/src/lib/validators/content/index.js +0 -1
- package/src/utils/hooks-installer.js +527 -516
- package/framework/templates/feature/tasks.md +0 -199
- package/framework/workflows/README.md +0 -1041
- package/framework/workflows/configs/fast-track.json +0 -46
- package/framework/workflows/configs/full.json +0 -64
- package/framework/workflows/configs/quick.json +0 -32
- package/framework/workflows/configs/standard.json +0 -57
- package/framework/workflows/docs/STORY-DRIVEN-DEVELOPMENT.md +0 -392
- package/framework/workflows/docs/design-impl.md +0 -37
- package/framework/workflows/docs/enforcement-pipeline.md +0 -668
- package/framework/workflows/docs/fast-track.md +0 -29
- package/framework/workflows/docs/full-morph.md +0 -69
- package/framework/workflows/docs/standard.md +0 -49
- package/framework/workflows/docs/ui-refresh.md +0 -39
- package/src/commands/state/index.js +0 -7
- package/src/core/workflows/workflow-detector.js +0 -586
- package/src/core/workflows/workflow-router.js +0 -204
- package/src/dashboard/app/pages/Workflows.jsx +0 -346
- package/src/dashboard/scanner/workflows-scanner.js +0 -18
- package/src/lib/phase-chain/phase-validator.js +0 -359
- package/src/lib/validators/content/cross-phase-validator.js +0 -281
- package/src/lib/validators/spec-validator.js +0 -312
|
@@ -1,244 +1,258 @@
|
|
|
1
|
-
# Microsoft Agent Framework — Setup Guide (.NET 10)
|
|
2
|
-
|
|
3
|
-
> **Scope:** stacks=["dotnet"]
|
|
4
|
-
> **Layer:** 0 (always-load via persona maf-expert)
|
|
5
|
-
> **Keywords:** maf setup, microsoft agents ai, chatclient, ai agent, agent framework, agent dotnet, AsAIAgent
|
|
6
|
-
> **Read by Claude in:** plan (pra citar pacote em tasks.json) + implement (pra escrever .csproj e Program.cs)
|
|
7
|
-
|
|
8
|
-
**Verified against:** Microsoft.Agents.AI 1.0 GA (abril/2026). Last-verified: 2026-05-19.
|
|
9
|
-
|
|
10
|
-
---
|
|
11
|
-
|
|
12
|
-
## Provider philosophy — direct models always
|
|
13
|
-
|
|
14
|
-
This framework is **provider-agnostic**. There is no "primary" provider hardcoded. Every model is reached as a **direct model** (you call the model API directly) — never via a hosted agent service. Hosted services lag 6-9 months on models and remove control.
|
|
15
|
-
|
|
16
|
-
First-class providers: **OpenAI, Google (Gemini), Anthropic (Claude), Ollama** (local/on-prem).
|
|
17
|
-
Azure OpenAI is also a direct model but is **not a default** — see note in §3.4.
|
|
18
|
-
|
|
19
|
-
The concrete model choice lives in the project's Model Registry, not in this standard. See `ai-agents-providers-model-registry`.
|
|
20
|
-
|
|
21
|
-
## Decision tree (when reading this in plan phase)
|
|
22
|
-
|
|
23
|
-
```
|
|
24
|
-
Está adicionando um agente AI a um projeto .NET?
|
|
25
|
-
├─ Sim → use este standard + ai-agents-sweet-spot + ai-agents-providers-model-registry
|
|
26
|
-
│ ├─ Projeto tem >1 modelo ou >1 provider? → SEMPRE use Model Registry
|
|
27
|
-
│ ├─ Provider OpenAI? → §3.1
|
|
28
|
-
│ ├─ Provider Ollama (local)? → §3.2
|
|
29
|
-
│ ├─ Provider Google / Anthropic? → §3.3
|
|
30
|
-
│ └─ Provider Azure OpenAI (data residency)? → §3.4 (nota, não default)
|
|
31
|
-
└─ Não → este standard não se aplica
|
|
32
|
-
```
|
|
33
|
-
|
|
34
|
-
---
|
|
35
|
-
|
|
36
|
-
## 1. Packages (NuGet)
|
|
37
|
-
|
|
38
|
-
**Required for any MAF project:**
|
|
39
|
-
|
|
40
|
-
```xml
|
|
41
|
-
<PackageReference Include="Microsoft.Agents.AI" Version="1.0.*" />
|
|
42
|
-
```
|
|
43
|
-
|
|
44
|
-
**Provider-specific (escolha conforme o Model Registry do projeto):**
|
|
45
|
-
|
|
46
|
-
```xml
|
|
47
|
-
<!-- OpenAI direct -->
|
|
48
|
-
<PackageReference Include="Microsoft.Agents.AI.OpenAI" Version="1.0.*" />
|
|
49
|
-
<PackageReference Include="OpenAI" Version="2.*" />
|
|
50
|
-
|
|
51
|
-
<!-- Ollama (local / on-prem) — usa o mesmo OpenAI-compatible client -->
|
|
52
|
-
<PackageReference Include="OpenAI" Version="2.*" />
|
|
53
|
-
|
|
54
|
-
<!-- Google Gemini — SDK verificado no standard model-registry.md -->
|
|
55
|
-
<!-- Anthropic Claude — SDK verificado no standard model-registry.md -->
|
|
56
|
-
<!-- Azure OpenAI (somente se data residency exigir) — Azure.AI.OpenAI 2.* + Azure.Identity 1.* -->
|
|
57
|
-
```
|
|
58
|
-
|
|
59
|
-
> The `.AsIChatClient()` extension on `OpenAI.ChatClient` comes from `Microsoft.Agents.AI.OpenAI`. The `IChatClient` abstraction itself lives in `Microsoft.Extensions.AI` (a transitive dependency of `Microsoft.Agents.AI`) — code that uses `IChatClient` needs `using Microsoft.Extensions.AI;`.
|
|
60
|
-
|
|
61
|
-
> Os pacotes de Google e Anthropic mudam de nome/versão com frequência. O standard `ai-agents-providers-model-registry` mantém a lista verificada com data. Não trave SDK aqui.
|
|
62
|
-
|
|
63
|
-
**Optional (only when feature requires):**
|
|
64
|
-
|
|
65
|
-
```xml
|
|
66
|
-
<!-- Hosting helpers (AddAIAgent, AddSequentialWorkflow) -->
|
|
67
|
-
<PackageReference Include="Microsoft.Agents.AI.Hosting" Version="1.0.*" />
|
|
68
|
-
|
|
69
|
-
<!-- A2A protocol -->
|
|
70
|
-
<PackageReference Include="Microsoft.Agents.AI.A2A" Version="1.0.*" />
|
|
71
|
-
```
|
|
72
|
-
|
|
73
|
-
**Forbidden in new MAF projects:**
|
|
74
|
-
|
|
75
|
-
- `Microsoft.SemanticKernel.*` — superseded by MAF, do not introduce.
|
|
76
|
-
- `Microsoft.Extensions.AI.OpenAI` 9.* — replaced by `Microsoft.Agents.AI.OpenAI` in GA.
|
|
77
|
-
- Hosted agent services (Foundry Agent Service, etc.) — use direct models.
|
|
78
|
-
|
|
79
|
-
---
|
|
80
|
-
|
|
81
|
-
## 2. Quick Start (canonical minimal agent)
|
|
82
|
-
|
|
83
|
-
```csharp
|
|
84
|
-
using Microsoft.Agents.AI;
|
|
85
|
-
using Microsoft.Extensions.AI;
|
|
86
|
-
using OpenAI;
|
|
87
|
-
using OpenAI.Chat;
|
|
88
|
-
|
|
89
|
-
AIAgent agent = new ChatClient(model: "gpt-4o-mini", apiKey: "<from-config>")
|
|
90
|
-
.AsIChatClient()
|
|
91
|
-
.AsAIAgent(instructions: "You are a helpful assistant.");
|
|
92
|
-
|
|
93
|
-
var response = await agent.RunAsync("Analyze this order.");
|
|
94
|
-
Console.WriteLine(response.Text);
|
|
95
|
-
```
|
|
96
|
-
|
|
97
|
-
This snippet is the baseline. In a real project you never hardcode the model — use the Model Registry (`ai-agents-providers-model-registry`). Anything more complex (DI, tools, structured output, RAG) layers on top via the other ai-agents standards.
|
|
98
|
-
|
|
99
|
-
---
|
|
100
|
-
|
|
101
|
-
## 3. Setup by Provider
|
|
102
|
-
|
|
103
|
-
> In any project with >1 model or >1 provider, **do not register `IChatClient` directly** — use the Model Registry (`ai-agents-providers-model-registry`). The snippets below show the raw client construction the registry wraps.
|
|
104
|
-
|
|
105
|
-
### 3.1 OpenAI direct (most common)
|
|
106
|
-
|
|
107
|
-
```csharp
|
|
108
|
-
using OpenAI;
|
|
109
|
-
using OpenAI.Chat;
|
|
110
|
-
using Microsoft.Extensions.AI;
|
|
111
|
-
|
|
112
|
-
builder.Services.AddSingleton<IChatClient>(sp =>
|
|
113
|
-
{
|
|
114
|
-
var cfg = sp.GetRequiredService<IConfiguration>();
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
```
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
>
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
```csharp
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
---
|
|
221
|
-
|
|
222
|
-
##
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
- `
|
|
239
|
-
- Microsoft.
|
|
240
|
-
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
1
|
+
# Microsoft Agent Framework — Setup Guide (.NET 10)
|
|
2
|
+
|
|
3
|
+
> **Scope:** stacks=["dotnet"]
|
|
4
|
+
> **Layer:** 0 (always-load via persona maf-expert)
|
|
5
|
+
> **Keywords:** maf setup, microsoft agents ai, chatclient, ai agent, agent framework, agent dotnet, AsAIAgent
|
|
6
|
+
> **Read by Claude in:** plan (pra citar pacote em tasks.json) + implement (pra escrever .csproj e Program.cs)
|
|
7
|
+
|
|
8
|
+
**Verified against:** Microsoft.Agents.AI 1.0 GA (abril/2026). Last-verified: 2026-05-19.
|
|
9
|
+
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
## Provider philosophy — direct models always
|
|
13
|
+
|
|
14
|
+
This framework is **provider-agnostic**. There is no "primary" provider hardcoded. Every model is reached as a **direct model** (you call the model API directly) — never via a hosted agent service. Hosted services lag 6-9 months on models and remove control.
|
|
15
|
+
|
|
16
|
+
First-class providers: **OpenAI, Google (Gemini), Anthropic (Claude), Ollama** (local/on-prem).
|
|
17
|
+
Azure OpenAI is also a direct model but is **not a default** — see note in §3.4.
|
|
18
|
+
|
|
19
|
+
The concrete model choice lives in the project's Model Registry, not in this standard. See `ai-agents-providers-model-registry`.
|
|
20
|
+
|
|
21
|
+
## Decision tree (when reading this in plan phase)
|
|
22
|
+
|
|
23
|
+
```
|
|
24
|
+
Está adicionando um agente AI a um projeto .NET?
|
|
25
|
+
├─ Sim → use este standard + ai-agents-sweet-spot + ai-agents-providers-model-registry
|
|
26
|
+
│ ├─ Projeto tem >1 modelo ou >1 provider? → SEMPRE use Model Registry
|
|
27
|
+
│ ├─ Provider OpenAI? → §3.1
|
|
28
|
+
│ ├─ Provider Ollama (local)? → §3.2
|
|
29
|
+
│ ├─ Provider Google / Anthropic? → §3.3
|
|
30
|
+
│ └─ Provider Azure OpenAI (data residency)? → §3.4 (nota, não default)
|
|
31
|
+
└─ Não → este standard não se aplica
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
---
|
|
35
|
+
|
|
36
|
+
## 1. Packages (NuGet)
|
|
37
|
+
|
|
38
|
+
**Required for any MAF project:**
|
|
39
|
+
|
|
40
|
+
```xml
|
|
41
|
+
<PackageReference Include="Microsoft.Agents.AI" Version="1.0.*" />
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
**Provider-specific (escolha conforme o Model Registry do projeto):**
|
|
45
|
+
|
|
46
|
+
```xml
|
|
47
|
+
<!-- OpenAI direct -->
|
|
48
|
+
<PackageReference Include="Microsoft.Agents.AI.OpenAI" Version="1.0.*" />
|
|
49
|
+
<PackageReference Include="OpenAI" Version="2.*" />
|
|
50
|
+
|
|
51
|
+
<!-- Ollama (local / on-prem) — usa o mesmo OpenAI-compatible client -->
|
|
52
|
+
<PackageReference Include="OpenAI" Version="2.*" />
|
|
53
|
+
|
|
54
|
+
<!-- Google Gemini — SDK verificado no standard model-registry.md -->
|
|
55
|
+
<!-- Anthropic Claude — SDK verificado no standard model-registry.md -->
|
|
56
|
+
<!-- Azure OpenAI (somente se data residency exigir) — Azure.AI.OpenAI 2.* + Azure.Identity 1.* -->
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
> The `.AsIChatClient()` extension on `OpenAI.ChatClient` comes from `Microsoft.Agents.AI.OpenAI`. The `IChatClient` abstraction itself lives in `Microsoft.Extensions.AI` (a transitive dependency of `Microsoft.Agents.AI`) — code that uses `IChatClient` needs `using Microsoft.Extensions.AI;`.
|
|
60
|
+
|
|
61
|
+
> Os pacotes de Google e Anthropic mudam de nome/versão com frequência. O standard `ai-agents-providers-model-registry` mantém a lista verificada com data. Não trave SDK aqui.
|
|
62
|
+
|
|
63
|
+
**Optional (only when feature requires):**
|
|
64
|
+
|
|
65
|
+
```xml
|
|
66
|
+
<!-- Hosting helpers (AddAIAgent, AddSequentialWorkflow) -->
|
|
67
|
+
<PackageReference Include="Microsoft.Agents.AI.Hosting" Version="1.0.*" />
|
|
68
|
+
|
|
69
|
+
<!-- A2A protocol -->
|
|
70
|
+
<PackageReference Include="Microsoft.Agents.AI.A2A" Version="1.0.*" />
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
**Forbidden in new MAF projects:**
|
|
74
|
+
|
|
75
|
+
- `Microsoft.SemanticKernel.*` — superseded by MAF, do not introduce.
|
|
76
|
+
- `Microsoft.Extensions.AI.OpenAI` 9.* — replaced by `Microsoft.Agents.AI.OpenAI` in GA.
|
|
77
|
+
- Hosted agent services (Foundry Agent Service, etc.) — use direct models.
|
|
78
|
+
|
|
79
|
+
---
|
|
80
|
+
|
|
81
|
+
## 2. Quick Start (canonical minimal agent)
|
|
82
|
+
|
|
83
|
+
```csharp
|
|
84
|
+
using Microsoft.Agents.AI;
|
|
85
|
+
using Microsoft.Extensions.AI;
|
|
86
|
+
using OpenAI;
|
|
87
|
+
using OpenAI.Chat;
|
|
88
|
+
|
|
89
|
+
AIAgent agent = new ChatClient(model: "gpt-4o-mini", apiKey: "<from-config>")
|
|
90
|
+
.AsIChatClient()
|
|
91
|
+
.AsAIAgent(instructions: "You are a helpful assistant.");
|
|
92
|
+
|
|
93
|
+
var response = await agent.RunAsync("Analyze this order.");
|
|
94
|
+
Console.WriteLine(response.Text);
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
This snippet is the baseline. In a real project you never hardcode the model — use the Model Registry (`ai-agents-providers-model-registry`). Anything more complex (DI, tools, structured output, RAG) layers on top via the other ai-agents standards.
|
|
98
|
+
|
|
99
|
+
---
|
|
100
|
+
|
|
101
|
+
## 3. Setup by Provider
|
|
102
|
+
|
|
103
|
+
> In any project with >1 model or >1 provider, **do not register `IChatClient` directly** — use the Model Registry (`ai-agents-providers-model-registry`). The snippets below show the raw client construction the registry wraps.
|
|
104
|
+
|
|
105
|
+
### 3.1 OpenAI direct (most common)
|
|
106
|
+
|
|
107
|
+
```csharp
|
|
108
|
+
using OpenAI;
|
|
109
|
+
using OpenAI.Chat;
|
|
110
|
+
using Microsoft.Extensions.AI;
|
|
111
|
+
|
|
112
|
+
builder.Services.AddSingleton<IChatClient>(sp =>
|
|
113
|
+
{
|
|
114
|
+
var cfg = sp.GetRequiredService<IConfiguration>();
|
|
115
|
+
var apiKey = cfg["OpenAI:ApiKey"];
|
|
116
|
+
if (string.IsNullOrWhiteSpace(apiKey))
|
|
117
|
+
{
|
|
118
|
+
throw new InvalidOperationException(
|
|
119
|
+
"OpenAI:ApiKey is required. Bind it from an environment variable or secret store.");
|
|
120
|
+
}
|
|
121
|
+
return new ChatClient(
|
|
122
|
+
model: cfg["OpenAI:Model"] ?? "gpt-4o-mini",
|
|
123
|
+
apiKey: apiKey)
|
|
124
|
+
.AsIChatClient();
|
|
125
|
+
});
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
> **Why explicit `string.IsNullOrWhiteSpace` instead of `?? throw` or `!`?**
|
|
129
|
+
> `IConfiguration` returns the **empty string** (not `null`) for keys that
|
|
130
|
+
> exist with blank values — which is the common shape of a checked-in
|
|
131
|
+
> `appsettings.json` placeholder (`"OpenAI": { "ApiKey": "" }`). A
|
|
132
|
+
> `?? throw` guard against `null` therefore never fires; the program
|
|
133
|
+
> proceeds to `new ChatClient(model, "")` and crashes much later with
|
|
134
|
+
> an opaque OpenAI SDK error. Always check whitespace.
|
|
135
|
+
|
|
136
|
+
### 3.2 Ollama (local dev / on-prem)
|
|
137
|
+
|
|
138
|
+
Ollama exposes an OpenAI-compatible endpoint — use the same `ChatClient`:
|
|
139
|
+
|
|
140
|
+
```csharp
|
|
141
|
+
using OpenAI;
|
|
142
|
+
using OpenAI.Chat;
|
|
143
|
+
using System.ClientModel;
|
|
144
|
+
using Microsoft.Extensions.AI;
|
|
145
|
+
|
|
146
|
+
builder.Services.AddSingleton<IChatClient>(sp =>
|
|
147
|
+
new ChatClient(
|
|
148
|
+
model: "llama3.2:3b",
|
|
149
|
+
credential: new ApiKeyCredential("ollama"), // any non-empty string
|
|
150
|
+
options: new OpenAIClientOptions { Endpoint = new Uri("http://localhost:11434/v1") })
|
|
151
|
+
.AsIChatClient());
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
> Models < 3B params often fail tool calling. Use Ollama only for non-tool agents in dev.
|
|
155
|
+
|
|
156
|
+
### 3.3 Google (Gemini) / Anthropic (Claude)
|
|
157
|
+
|
|
158
|
+
Both are first-class providers reached as direct models. The exact NuGet SDK and client construction are documented (with verification date) in `ai-agents-providers-model-registry` §providers — that standard is the single source of truth for provider SDKs, since they change names/versions often.
|
|
159
|
+
|
|
160
|
+
### 3.4 Azure OpenAI (note — not a default)
|
|
161
|
+
|
|
162
|
+
Azure OpenAI is also a direct model, but requires an Azure resource + deployment per model. It is **not a default provider** in this framework — projects deploy to VPS, not Azure. Add an Azure branch to the Model Registry only when a client explicitly requires data residency in a specific Azure region. The pattern: `new AzureOpenAIClient(endpoint, credential).GetChatClient(deployment).AsIChatClient()`.
|
|
163
|
+
|
|
164
|
+
---
|
|
165
|
+
|
|
166
|
+
## 4. DI Registration (keyed agents)
|
|
167
|
+
|
|
168
|
+
> The `builder.AddAIAgent(...)` extension requires the `Microsoft.Agents.AI.Hosting` package (see §1 Optional). For projects that register agents manually without `AddAIAgent`, the base `Microsoft.Agents.AI` package is enough.
|
|
169
|
+
|
|
170
|
+
```csharp
|
|
171
|
+
// Program.cs
|
|
172
|
+
builder.AddAIAgent("OrderAnalyzer", (sp, key) =>
|
|
173
|
+
{
|
|
174
|
+
var chatClient = sp.GetRequiredService<IChatClient>();
|
|
175
|
+
return new ChatClientAgent(
|
|
176
|
+
chatClient,
|
|
177
|
+
name: key,
|
|
178
|
+
instructions: "You are an order analysis expert.");
|
|
179
|
+
});
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
Inject by key:
|
|
183
|
+
|
|
184
|
+
```csharp
|
|
185
|
+
public class AgentController(
|
|
186
|
+
[FromKeyedServices("OrderAnalyzer")] AIAgent orderAgent) : ControllerBase { ... }
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
For agents with tools and structured output, see `ai-agents-multi-agent-patterns` and `ai-agents-structured-output` (Onda 2).
|
|
190
|
+
|
|
191
|
+
---
|
|
192
|
+
|
|
193
|
+
## 5. OpenTelemetry
|
|
194
|
+
|
|
195
|
+
```csharp
|
|
196
|
+
using OpenTelemetry;
|
|
197
|
+
using OpenTelemetry.Trace;
|
|
198
|
+
using Microsoft.Agents.AI;
|
|
199
|
+
|
|
200
|
+
using var tracerProvider = Sdk.CreateTracerProviderBuilder()
|
|
201
|
+
.AddSource(AgentOpenTelemetryConsts.DefaultSourceName)
|
|
202
|
+
.AddOtlpExporter()
|
|
203
|
+
.Build();
|
|
204
|
+
|
|
205
|
+
// Wrap any agent (e.g. the `agent` from §2)
|
|
206
|
+
var instrumented = agent.WithOpenTelemetry();
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
> **Note:** Source name is `AgentOpenTelemetryConsts.DefaultSourceName` from `Microsoft.Agents.AI`. **Do NOT** use the old `Experimental.Microsoft.Extensions.AI.*` source — it belongs to a previous package family.
|
|
210
|
+
|
|
211
|
+
---
|
|
212
|
+
|
|
213
|
+
## 6. Security checklist
|
|
214
|
+
|
|
215
|
+
- [ ] API keys never in source. Bind from environment variables / secret store (the VPS deploy uses env vars; Docker secrets or a vault are fine too).
|
|
216
|
+
- [ ] `appsettings.json` checked into git never contains real keys — only placeholder/empty values.
|
|
217
|
+
- [ ] Provider keys (`OpenAI:ApiKey`, `Google:ApiKey`, `Anthropic:ApiKey`) bound from environment.
|
|
218
|
+
- [ ] No agent receives raw user input without input-validation middleware (see `ai-agents-middleware-patterns` — Onda 2).
|
|
219
|
+
|
|
220
|
+
---
|
|
221
|
+
|
|
222
|
+
## 7. What NOT to do (anti-patterns)
|
|
223
|
+
|
|
224
|
+
| Wrong | Right |
|
|
225
|
+
|-------|-------|
|
|
226
|
+
| `using Microsoft.SemanticKernel` | `using Microsoft.Agents.AI` |
|
|
227
|
+
| `Kernel.InvokePromptAsync()` | `agent.RunAsync()` |
|
|
228
|
+
| `[KernelFunction]` | `[Description]` on method + parameters; register via `AIFunctionFactory.Create()` |
|
|
229
|
+
| `ChatHistory` | `IEnumerable<ChatMessage>` |
|
|
230
|
+
| Hardcoded model strings spread across codebase | Single source via Model Registry (see `ai-agents-providers-model-registry`) |
|
|
231
|
+
| `Microsoft.Extensions.AI.OpenAI` 9.* | `Microsoft.Agents.AI.OpenAI` 1.* GA |
|
|
232
|
+
| Hosted agent service "to simplify" | Direct models always |
|
|
233
|
+
|
|
234
|
+
---
|
|
235
|
+
|
|
236
|
+
## 8. Checklist (verifiable by morph-eval)
|
|
237
|
+
|
|
238
|
+
- [ ] `Microsoft.Agents.AI` package present in `.csproj`
|
|
239
|
+
- [ ] No `Microsoft.SemanticKernel.*` references
|
|
240
|
+
- [ ] `IChatClient` registered (either directly or via Model Registry)
|
|
241
|
+
- [ ] At least one `AIAgent` created via `AsAIAgent()` or `new ChatClientAgent()`
|
|
242
|
+
- [ ] OpenTelemetry source name is `AgentOpenTelemetryConsts.DefaultSourceName` (if telemetry wired)
|
|
243
|
+
- [ ] Models reference Model Registry alias when project has >1 model use case
|
|
244
|
+
|
|
245
|
+
---
|
|
246
|
+
|
|
247
|
+
## 9. References
|
|
248
|
+
|
|
249
|
+
- `ai-agents-sweet-spot` — when to use agents vs workflows
|
|
250
|
+
- `ai-agents-providers-model-registry` — provider-agnostic pattern
|
|
251
|
+
- `ai-agents-structured-output` (Onda 2) — typed responses
|
|
252
|
+
- `ai-agents-middleware-patterns` (Onda 2) — telemetry, retry, anti-hallucination, streaming agent responses
|
|
253
|
+
- Microsoft.Agents.AI docs: https://learn.microsoft.com/agent-framework/
|
|
254
|
+
- Verified packages list (context7 /microsoft/agent-framework): retrieved 2026-05-19
|
|
255
|
+
|
|
256
|
+
---
|
|
257
|
+
|
|
258
|
+
*MORPH-SPEC by Polymorphism Tech — ai-agents/setup.md v2.0 (2026-05-19)*
|