Files
agent-framework/dotnet/samples/GettingStarted/Workflows
T
Tao Chen e3b4b6662b .NET: Workflow telemetry opt in (#3467)
* feat(workflows): Make telemetry opt-in via WithOpenTelemetry()

- Add WorkflowTelemetryOptions class with EnableSensitiveData property
- Add WorkflowTelemetryContext to manage ActivitySource lifecycle
- Add WithOpenTelemetry() extension method on WorkflowBuilder
- Update all workflow components to use telemetry context:
  - WorkflowBuilder, Workflow, Executor
  - InProcessRunnerContext, InProcessRunner
  - LockstepRunEventStream, StreamingRunEventStream
  - All edge runners (Direct, FanIn, FanOut, Response)
- Telemetry is now disabled by default
- Users must call WithOpenTelemetry() to enable spans/activities

BREAKING CHANGE: Workflow telemetry is now opt-in. Users who relied on
automatic telemetry must add .WithOpenTelemetry() to their workflow builder.

* refactor: Pass telemetry context as parameter instead of via interface

- Remove IWorkflowContextWithTelemetry interface
- Add internal ExecuteAsync overload that accepts WorkflowTelemetryContext
- Public ExecuteAsync delegates with WorkflowTelemetryContext.Disabled
- InProcessRunner passes TelemetryContext when calling ExecuteAsync
- BoundContext now implements IWorkflowContext (not the removed interface)

* Add optional ActivitySource parameter to WithOpenTelemetry

Allow users to provide their own ActivitySource when enabling telemetry,
giving them better control over the ActivitySource lifecycle. When not
provided, the framework creates one internally (existing behavior).

Changes:
- Add optional activitySource parameter to WithOpenTelemetry() extension
- Update WorkflowTelemetryContext to accept external ActivitySource
- Add unit test for user-provided ActivitySource scenario

* Add component-level telemetry control with disable flags

Allow users to selectively disable specific activity types via
WorkflowTelemetryOptions. All activities are enabled by default.

New disable flags:
- DisableWorkflowBuild: Disables workflow.build activities
- DisableWorkflowRun: Disables workflow_invoke activities
- DisableExecutorProcess: Disables executor.process activities
- DisableEdgeGroupProcess: Disables edge_group.process activities
- DisableMessageSend: Disables message.send activities

Added helper methods to WorkflowTelemetryContext for each activity type
and updated all activity creation sites to use them.

* Implement EnableSensitiveData to log executor input/output

When EnableSensitiveData is true in WorkflowTelemetryOptions, executor
input and output are logged as JSON-serialized attributes in the
executor.process activity.

New activity tags:
- executor.input: JSON serialized input message
- executor.output: JSON serialized output result (non-void only)

Added suppression attributes for AOT/trimming warnings since this is
an opt-in feature for debugging/diagnostics.

* Refactor activity start methods to centralize tagging logic

Move tagging logic into WorkflowTelemetryContext methods:
- StartExecutorProcessActivity now accepts executorId, executorType,
  messageType, and message; sets all tags including executor.input
  when EnableSensitiveData is true
- Added SetExecutorOutput method to set executor.output after execution
- StartMessageSendActivity now accepts sourceId, targetId, and message;
  sets all tags including message.content when EnableSensitiveData is true

Simplified Executor.cs and InProcessRunnerContext.cs by removing
inline tagging code. Added message.content tag constant.

* Revert Python changes

* Update samples and code cleanup

* Fix file formatting

* Add comment

* Add telemetry configuration to declarative workflow

* Remove delays in tests

* Address comments
e3b4b6662b ยท 2026-02-09 23:10:50 +00:00
History
..
2025-12-08 21:30:21 +00:00
2025-11-22 04:14:15 +00:00

Workflow Getting Started Samples

The getting started with workflow samples demonstrate the fundamental concepts and functionalities of workflows in Agent Framework.

Samples Overview

Foundational Concepts - Start Here

Please begin with the Foundational samples in order. These three samples introduce the core concepts of executors, edges, agents in workflows, streaming, and workflow construction.

The folder name starts with an underscore (_Foundational) to ensure it appears first in the explorer view.

Sample Concepts
Executors and Edges Minimal workflow with basic executors and edges
Streaming Extends workflows with event streaming
Agents Use agents in workflows
Agentic Workflow Patterns Demonstrates common agentic workflow patterns
Multi-Service Workflows Shows using multiple AI services in the same workflow
Sub-Workflows Demonstrates composing workflows hierarchically by embedding workflows as executors
Mixed Workflow with Agents and Executors Shows how to mix agents and executors with adapter pattern for type conversion and protocol handling
Writer-Critic Workflow Demonstrates iterative refinement with quality gates, max iteration safety, multiple message handlers, and conditional routing for feedback loops

Once completed, please proceed to other samples listed below.

Note that you don't need to follow a strict order after the foundational samples. However, some samples build upon concepts from previous ones, so it's beneficial to be aware of the dependencies.

Agents

Sample Concepts
Foundry Agents in Workflows Demonstrates using Azure Foundry Agents within a workflow
Custom Agent Executors Shows how to create a custom agent executor for more complex scenarios
Workflow as an Agent Illustrates how to encapsulate a workflow as an agent
Group Chat with Tool Approval Shows multi-agent group chat with tool approval requests and human-in-the-loop interaction

Concurrent Execution

Sample Concepts
Fan-Out and Fan-In Introduces parallel processing with fan-out and fan-in patterns

Loop

Sample Concepts
Looping Shows how to create a loop within a workflow

Workflow Shared States

Sample Concepts
Shared States Demonstrates shared states between executors for data sharing and coordination

Conditional Edges

Sample Concepts
Edge Conditions Introduces conditional edges for dynamic routing based on executor outputs
Switch-Case Routing Extends conditional edges with switch-case routing for multiple paths
Multi-Selection Routing Demonstrates multi-selection routing where one executor can trigger multiple downstream executors

These 3 samples build upon each other. It's recommended to explore them in sequence to fully grasp the concepts.

Declarative Workflows

Sample Concepts
Declarative Demonstrates execution of declartive workflows.

Checkpointing

Sample Concepts
Checkpoint and Resume Introduces checkpoints for saving and restoring workflow state for time travel purposes
Checkpoint and Rehydrate Demonstrates hydrating a new workflow instance from a saved checkpoint
Checkpoint with Human-in-the-Loop Combines checkpointing with human-in-the-loop interactions

Human-in-the-Loop

Sample Concepts
Basic Human-in-the-Loop Introduces human-in-the-loop interaction using input ports and external requests