e-naxosMAF COURSE / COURS
Français

MICROSOFT AGENT FRAMEWORK · 0.16.0-rc.1

Code, workflow and agent

Decide where a rule is sufficient and where interpretation becomes useful, using Demo010.

Objectives

Choose before calling a model

A screen receives a support request. Should the application apply a rule, follow a procedure or ask for an interpretation? Natural language alone does not settle the choice. The decision depends on the required outcome and how much uncertainty the application can accept.

EP002 raises this architecture question before introducing an API. We retain that progression: characterize the need, choose a responsibility boundary, then inspect the program. The J1 course introductions add a second reference point: a model response belongs to a software system that manages configuration, state, tools and effects.

Three needs and three choices to justify

Compare architecture decisions
NeedInitial choiceEvidence and limit
Calculate a fixed discountC# functionCheck the formula and boundary cases. A model adds variable output to an already known rule.
Qualify then route an incidentExplicit procedure or workflowCheck transitions, refusals and traces. Multiple steps alone do not justify an agent.
Clarify an ambiguous failureAgent within a controlled branchEvaluate whether the questions are useful. Convincing wording does not prove resolution.

A workflow describes known steps and transitions. It can include a model call while keeping authorization under host control. An agent becomes useful when interpretation or dialogue adds measurable value. These components can coexist in the same application.

Decision path: complete textual alternative
  1. Describe the outcome and its acceptance criteria.
  2. If the rule is computable, express it directly in code.
  3. If the transitions are known, make the procedure explicit.
  4. If interpretation is still needed, bound the model call and check its output.

The architecture router in EP002 illustrated this judgement. Current Demo010 has no general three-way router: it contains a calculation, a branch on Login and an --agent option. Architecture remains the designer’s responsibility; this program cannot select an architecture for an arbitrary request.

Read Demo010 line by line

Console.WriteLine("Deterministic C#: a fixed discount rule returns " + (100m * 0.9m));
var request = "Login fails for a known account";
var component = request.Contains("Login", StringComparison.OrdinalIgnoreCase) ? "Auth" : "Other";
Console.WriteLine($"Explicit C# orchestration: classify -> route -> display. Component: {component}. This is not a MAF workflow graph.");
if (!args.Contains("--agent")) return;

demos/Demo010_CodeOrAgent/Program.cs · L15–L19 · 9a895c94534c

Source code · Demo010 · Folder

The calculation 100m × 0.9m applies a fixed ten percent discount and keeps a decimal result. The amount, rate and lack of a rounding rule are assumptions of this example. The filmed scenario used a 1,200-euro order and a Gold customer; that is no longer the behaviour of the current file.

Contains looks for Login without case sensitivity. An occurrence yields Auth; every other string yields Other. This is substring classification rather than incident understanding. A sentence negating Login also gets Auth; an authentication failure worded without that token gets Other.

The classify → route → display message describes ordinary C# orchestration. It creates no MAF graph, durable suspension, resumption or human approval. Demo230 will provide a typed-workflow comparison; its page has not yet been authored in this preview.

The return statement stops execution before DemoSettings is loaded when --agent is absent. With the flag, DemoConnection creates the client, AsAIAgent supplies the runtime and RunAsync receives a request for two clarification questions. No business tool or write access is exposed to this agent.

Four responsibilities in the optional branch
  1. Host application: arguments, two-minute deadline and cancellation.
  2. MAF runtime: agent instructions and RunAsync execution.
  3. Microsoft.Extensions.AI IChatClient abstraction: communication with the client.
  4. Provider configured by DemoConnection: local or remote inference according to the profile.

Experiment and explain the observation

Open a complete BaseTechnique distribution: the demo folder alone is insufficient. From its root, use the SDK pinned in global.json. After a Release build, run the model-free command on the demo page. Check both messages and process completion before trying an optional variant.

Decision exercise: classify a fixed contractual discount, a known support procedure and an incomplete diagnostic request. For each, write the verifiable outcome, the host responsibility and any reason for a model call. Expected answer: direct calculation for the discount; explicit transitions for the procedure; proposed and evaluated questions for diagnosis.

In a working copy, replace the request with “Authentication fails” and then “Login is not the problem”. Predict Other and Auth respectively before running it. Classification still follows Contains, yet may fail the business need. This counterexample separates testing program behaviour from qualifying its usefulness.

Cost, control and limits of the comparison

A local model may avoid per-request billing; it still consumes compute, memory and time. Latency and quality depend on the machine and model. The old “zero cost” wording and general granite4:3b reliability claims are therefore not retained as guarantees. A default configuration is not an independent qualification.

An application can keep calculations in C#, orchestrate a known procedure and call an agent at one specific point. Define deadlines, cancellation, traces and output controls. Demo010 demonstrates a minimal boundary with a global deadline and no tools; it does not demonstrate persistence, idempotency or production authorization.

Before choosing an agent, define representative cases, acceptable errors and a comparison with the explicit solution. Observe cost, latency and response usefulness. Site build tests do not execute the model and provide no measurements of these qualities.

Source revision and what to read next

Adapted from EP002: introduction and three needs (body:4–11), deterministic case and procedure (body:12–21), controlled agent and decision (body:22–34). Audience addresses, RUN 1–3, timings and the filming menu were removed. The J1 introductions (body:18–32) were corrected to distinguish application, runtime, client and provider. Detailed mappings remain in the private editorial register.

Read Demo010 for commands and observable results, then continue with Connections and capabilities. The Actionability exercise compares valid analysis with an action that remains blocked.

To locate configuration in a .NET host, here is the Demo020 console startup. AddDemoConfiguration loads options and AddDemoConnection registers services; Build creates the host without producing a model response. This demo also contains a backend: both projects are linked below. The foundations chapter will cover it in full.

var builder = Host.CreateApplicationBuilder();
builder.Configuration.AddDemoConfiguration(args);
var settings = ConnectionOptions.FromConfiguration(builder.Configuration);
builder.Services.AddDemoConnection(settings);
using var host = builder.Build();

demos/Demo020_ConnectionProfiles/Console/Program.cs · L7–L11 · 9a895c94534c

Source code · Demo020 · Folder

Prerequisites

Continue reading

Previous

Next

lot007-foundations-1 · 2026-10-24 · 9a895c94534cd5fc6f3da883e37e5f7856e588c1