AI workflows are becoming more structured.
A production agent may need to perform several steps:
User Request
|
v
Triage Agent
|
v
Specialist Agent
|
v
Business Rule
|
v
Human Approval
|
v
Final Action
Traditionally, developers implement this orchestration directly in application code.
Microsoft Agent Framework now provides another approach: Declarative Workflows, where workflow orchestration is described using YAML instead of being constructed entirely through programmatic APIs. Declarative Workflows reached version 1.0 across the Microsoft Agent Framework SDKs in July 2026, with the .NET declarative workflow package already stable.
This raises an important engineering question:
Does moving workflow definitions from C# code into YAML affect runtime performance?
The answer requires some nuance.
Declarative and code-first workflows ultimately execute through the same Workflow abstraction. Microsoft explicitly states that a declarative definition loads into a standard workflow that can be run, streamed, and composed like a code-first workflow.
Therefore, the most useful comparison is not simply:
YAML = slower
C# = faster
Instead, teams should measure several distinct costs:
Definition Loading
+
Workflow Construction
+
Execution Overhead
+
Agent/API Latency
+
Maintenance Cost
+
Deployment Flexibility
What Is a Declarative AI Workflow?
A declarative workflow describes what the workflow should do rather than implementing the orchestration entirely through application code.
A simplified C# declarative workflow definition looks like:
kind: Workflow
trigger:
kind: OnConversationStart
id: support_router
actions:
- kind: InvokeAzureAgent
id: triage
displayName: Triage request
- kind: InvokeAzureAgent
id: specialist
displayName: Handle request
The YAML describes the workflow structure.
The framework loads that definition and converts it into an executable workflow.
Microsoft describes this approach as defining workflow logic through YAML configuration rather than programmatic code.
What Is a Code-First Workflow?
A code-first workflow defines the workflow topology directly in application code.
For example:
using Microsoft.Agents.AI.Workflows;
var processor = new DataProcessor();
var validator = new Validator();
var formatter = new Formatter();
WorkflowBuilder builder =
new(processor);
builder.AddEdge(processor, validator);
builder.AddEdge(validator, formatter);
Workflow workflow =
builder.Build();
This approach gives the developer direct control over workflow construction.
Microsoft's WorkflowBuilder API is designed for constructing workflows from executors and edges.
The two approaches can therefore be represented as:
Declarative
YAML
|
v
Declarative Builder
|
v
Workflow
|
v
Execution
and:
Code-First
C#
|
v
WorkflowBuilder
|
v
Workflow
|
v
Execution
The important observation is that both ultimately produce a Workflow.
YAML vs Code: The Architectural Difference
The biggest difference is not necessarily runtime execution.
It is where the workflow definition lives.
| Area | Declarative YAML | Code-First C# |
|---|---|---|
| Workflow definition | YAML | C# |
| Type safety | More limited | Strong |
| Runtime flexibility | Structured | High |
| Custom logic | Limited by supported actions | Very flexible |
| Version control | Excellent | Excellent |
| Non-developer readability | Higher | Lower |
| Compile-time validation | More limited | Stronger |
| Standard orchestration | Excellent | Excellent |
| Complex custom logic | Less suitable | Better |
| Dynamic programmatic behavior | Limited | Strong |
| Runtime model | Standard Workflow | Standard Workflow |
Microsoft's documentation recommends declarative workflows for standard orchestration patterns and frequently changing workflows, while programmatic workflows are more appropriate when complex custom logic or maximum control is required.
Does YAML Add Runtime Overhead?
There are actually two different operations to consider.
Workflow Construction
The application must parse and build the YAML definition.
Conceptually:
YAML
|
v
Parse
|
v
Validate
|
v
Build Workflow
Code-first workflows instead construct the workflow directly from C# objects.
Therefore, there can be a cost associated with loading a declarative workflow.
But that cost should not automatically be confused with the cost of every workflow execution.
Workflow Execution
After the declarative definition has been loaded into a Workflow, the framework executes that workflow through the normal workflow runtime.
Microsoft explicitly states that declarative workflows load as standard Workflow instances and can be run, streamed, and composed like code-first workflows.
This distinction is critical.
Separate Build Time From Runtime
A useful benchmark should measure:
Phase 1
YAML Loading
|
v
Workflow Construction
separately from:
Phase 2
Workflow Execution
Otherwise, a one-time workflow construction cost can be incorrectly reported as an execution penalty.
For example:
Application Startup
|
+-- Load YAML
+-- Build Workflow
|
v
Workflow Ready
|
+-- Request 1
+-- Request 2
+-- Request 3
+-- ...
If the workflow is built once and reused, the YAML parsing cost is amortized across requests.
The Most Important Benchmark Question
Instead of asking:
"Is YAML faster than C#?"
ask:
"What percentage of total application latency is attributable to workflow definition loading and orchestration overhead?"
This is a much more useful production question.
An AI workflow may contain:
YAML Loading
2 ms
|
v
Workflow Execution
20 ms
|
v
LLM Request
900 ms
|
v
External API
200 ms
In this hypothetical architecture, optimizing YAML parsing would have a very different impact than optimizing the model or external API calls.
The actual values must be measured rather than assumed.
LLM Latency Changes the Equation
AI workflows frequently call external model APIs.
For example:
Workflow
|
v
Agent
|
v
Network
|
v
Model
|
v
Response
The model request can dominate end-to-end latency.
A workflow-level microbenchmark might therefore show a difference that is practically insignificant in a real application.
This is why performance testing should have at least two layers:
Microbenchmark
|
v
Workflow Engine Cost
End-to-End Benchmark
|
v
Workflow + Model + Tools + Network
Both answer different questions.
Build a Minimal Benchmark
Start with a workflow that does not call an external model.
For example, create a simple executor:
public sealed class Processor
{
public string Process(string input)
{
return input.ToUpperInvariant();
}
}
Then create an equivalent code-first workflow.
For the declarative version, define the corresponding action in YAML.
The objective is to isolate:
Workflow Construction
+
Workflow Execution
from:
LLM
+
Network
+
Database
Benchmark Workflow Construction
A benchmark should separately measure how long it takes to create the workflow.
Conceptually:
[Benchmark]
public Workflow BuildWorkflow()
{
return DeclarativeWorkflowBuilder.Build<string>(
_workflowPath,
_options);
}
The code-first equivalent can measure:
[Benchmark]
public Workflow BuildCodeWorkflow()
{
var processor = new Processor();
var validator = new Validator();
var builder =
new WorkflowBuilder(processor);
builder.AddEdge(processor, validator);
return builder.Build();
}
The exact generic types and executor implementation depend on the workflow being tested.
The important principle is to benchmark equivalent workflow graphs.
Benchmark Execution Separately
Once the workflow has been built:
Build
|
v
Workflow Instance
|
+---- Execution 1
+---- Execution 2
+---- Execution 3
Benchmark execution without rebuilding the workflow every time.
Otherwise, the benchmark answers:
Build + Execute
instead of:
Execute
This distinction is particularly important for declarative workflows.
Avoid This Benchmark
Do not benchmark:
[Benchmark]
public async Task Execute()
{
var workflow =
DeclarativeWorkflowBuilder.Build<string>(
"workflow.yaml",
_options);
await workflow.RunAsync(...);
}
if the production application actually builds the workflow only once.
That test repeatedly includes workflow construction.
Instead:
private Workflow _workflow;
[GlobalSetup]
public void Setup()
{
_workflow =
DeclarativeWorkflowBuilder.Build<string>(
"workflow.yaml",
_options);
}
[Benchmark]
public async Task Execute()
{
await _workflow.RunAsync(...);
}
The exact execution API depends on the workflow and framework version.
The benchmark design is the important part.
Benchmark the Same Workflow Graph
The YAML and C# implementations should represent the same logical graph.
For example:
+----------+
| Triage |
+----+-----+
|
+----v-----+
| Validate |
+----+-----+
|
+----v-----+
| Respond |
+----------+
Do not compare:
YAML
3 actions
against:
C#
10 actions
and then attribute the difference to the authoring model.
Control the workflow topology.
Benchmark Sequential Workflows
Start with a sequential workflow:
A
|
v
B
|
v
C
Measure:
Construction
Execution
Memory
Allocations
Then expand the experiment.
Benchmark Parallel Workflows
Agent Framework workflows can model parallel execution.
Conceptually:
+--> Agent A --+
| |
Input -+ +--> Merge
| |
+--> Agent B --+
The framework supports graph-based workflow execution with parallel processing and other control-flow patterns.
For a parallel benchmark, measure:
Total Execution Time
CPU Utilization
Task Scheduling
Memory
Synchronization
Do not assume YAML or C# changes the performance of the underlying parallel operations simply because the workflow was authored differently.
Benchmark Conditional Routing
A conditional workflow might look like:
Input
|
v
Classifier
|
+---- Billing ---> Billing Agent
|
+---- Sales -----> Sales Agent
|
+---- Support ---> Support Agent
Declarative workflows support conditional routing and other control-flow actions.
Benchmark:
Routing Time
+
Selected Branch Execution
The routing decision may involve an LLM.
If so, separate model latency from workflow-engine overhead.
Benchmark Human-in-the-Loop Workflows
Declarative workflows also support human-in-the-loop scenarios.
For example:
Agent
|
v
Risk Check
|
v
Approval
|
+---- Reject
|
+---- Approve
|
v
Action
Human waiting time should not be treated as workflow execution latency.
Instead, measure:
Workflow Processing Time
and separately:
Human Wait Time
This is especially important when analyzing production SLAs.
YAML Expression Evaluation
Declarative workflows use an expression language for dynamic values.
For example:
- kind: SetVariable
variable: Local.message
value: =Concat(
"Hello, ",
System.LastMessage.Text
)
Microsoft documents Power Fx-based expressions for declarative workflows.
This creates another potential benchmark dimension:
Expression Parsing
Expression Evaluation
Variable Resolution
For most workflows, these operations should be measured independently from external model and network calls.
Code Has Different Performance Characteristics
Code-first workflows can execute arbitrary C# logic directly.
For example:
if (customer.IsPremium)
{
await premiumProcessor.ProcessAsync(customer);
}
else
{
await standardProcessor.ProcessAsync(customer);
}
This provides direct access to:
Native C# control flow
Strong typing
Existing libraries
Custom algorithms
Custom data structures
Specialized concurrency patterns
If a workflow requires substantial custom computation, code-first orchestration can be a better fit.
YAML Has Different Operational Characteristics
Declarative YAML is particularly attractive when the workflow structure changes independently from application implementation.
For example:
Product Owner
|
v
Workflow Definition
|
v
YAML Review
|
v
Version Control
|
v
Deployment
A change to a routing rule or agent handoff can often be expressed as a workflow-definition change instead of modifying the orchestration code.
Microsoft highlights reviewability, versioning, and the ability to change orchestration separately from application logic as key benefits of declarative workflows.
Compare Startup Behavior
Declarative workflows may need to load their YAML definition.
Therefore, if an application creates workflows during startup:
Application Start
|
v
Load YAML
|
v
Build Workflow
|
v
Application Ready
measure startup impact.
For a long-running service, this may be a small one-time cost.
For a short-lived process:
Start
|
v
Load Workflow
|
v
Execute Once
|
v
Exit
the cost may become more relevant.
The workload determines the significance.
Cache or Reuse Workflows
If the workflow definition does not change per request, avoid rebuilding it unnecessarily.
Prefer:
Application Startup
|
v
Build Workflow
|
v
Reuse
|
+--> Request 1
+--> Request 2
+--> Request 3
rather than:
Request 1
|
v
Build Workflow
|
v
Execute
Request 2
|
v
Build Workflow
|
v
Execute
The exact lifecycle should follow the framework's threading and state-management requirements.
Do not share mutable workflow state across concurrent requests unless the API guarantees that it is safe.
Version Control Is a Major Advantage of YAML
A declarative workflow can be reviewed like a configuration artifact:
Join the conversation! Your thoughts help the community grow.