Files
agent-framework/dotnet
T
Jacob Alber 32711cfa95 .Net: WIP: feat: Define Workflow and Executor APIs (#261)
* feat: Define Workflow and Executor APIs

* feat: Define IExecutionContext and Events

* feat: Simple Workflow Demos

* refactor: Move Workflows classes to separate assembly

* feat: Move FanOut/In to LowLevel API with new semantics

* feat: Implement Local Execution

* refactor: Assembly name .Workflow => .Workflows

* feat: Enable Default Message Handling

* also lifts Bind in MessageHandlerInfo to better be able to direclty invoke handlers (for AOT, later)

* feat: Implement StreamingHandle APIs

This allows the user to respond to WorkflowEvents with external messages, enabling HIL.

* feat: Add checks for duplicate edges and chain cycles

* feat: Add built-in WorkflowEvents

* refactor: Pull classes into own files

* refactor: Simplify Disposal pattern in Executor

* refactor: Break EdgeRunner file into per-type files

* refactor: Use Throw.IfNull()

* refactor: Remove AddLoop()

Per https://github.com/microsoft/agent-framework/pull/272#discussion_r2241739079 we decided this was not very useful.

* refactor: Normalize use of ValueTask

* fix: Build Break from removing .AddLoop

* refactor: Explicit routing and RouteBuilder

Split out reflection from MessageRouter implemention into build phase, enabling AOT compilation to drive RouteBuilding without reflection.

* test: Add Reflection/Invocation tests

* fix: Terminate on Completion event

* refactor: Update public API surface

* feat: Add support for external requests

* feat: Support hosting AIAgent instances in Workflows

* fix: Fix routing to go through Executor.ExecuteAsync

* test: Update samples for "must SendMessage" semantics

* Add invoking samples to unit tests to avoid future breaks

* fix: ExternalRequest should block Workflow completion

* feat: Normalize API surface against Python

* Also adds xmldoc to all public APIs

* refactor: Normalize UnitTest and Sample namespaces

* fix: Formatting

* refactor: Normalize project/folder names

* feat: Remove DynamicCodeExecution from ValueTaskTypeErasure

* fix: Fix ILTrim warnings

* docs: Add missing docs and fix typos

* feat: Hosted Agents should report Run events

* fix: Fix type propagation for ILTrim changes

* refactor: Simplify DynamicallyAccessedMembers annotations

* sample: Use static-Type construction of InputPort

* feat: Support non-Streaming Run Mode

* test: Add test for non-streaming execution

* refactor: Remove unused types

* refactor: Simplify Event and EdgeData type hierarchies

* feat: Add Switch (=Conditional Edge Group) control flow

* feat: Make .NET AutoSend the MessageHandler result

* feat: Implement State APIs

* refactor: Simplify public namespaces and code organization

* refactor: Reconcile .NET and Python names

---------

Co-authored-by: Chris <66376200+crickman@users.noreply.github.com>
32711cfa95 · 2025-08-13 22:34:39 +00:00
History
..

Get Started with Microsoft Agent Framework for C# Developers

Run the Minimal Console demo

The Minimal Console demo is a simple console application which shows how to create and run an agent.

Supported Platforms:

  • .Net: net9.0, net8.0, netstandard2.0, net472
  • OS: Windows, macOS, Linux

If you want to use the latest published packages following the instructions here.

1. Configure required environment variables

This samples uses Azure OpenAI by default so you need to set the following environment variable

$env:AZURE_OPENAI_ENDPOINT = "https://<your deployment>.openai.azure.com/"

If you want to use OpenAI

  1. Edit Program.cs and change the following lines:
    AIAgent agent = new AzureOpenAIClient(
      new Uri(Environment.GetEnvironmentVariable("AZURE_OPENAI_ENDPOINT")!),
      new AzureCliCredential())
       .GetChatClient("gpt-4o-mini")
       .CreateAIAgent(
         instructions: "You are a helpful assistant, you can help the user with weather information.",
         tools: [AIFunctionFactory.Create(GetWeather)]);
    
    To this:
    AIAgent agent = new OpenAIClient(Environment.GetEnvironmentVariable("OPENAI_API_KEY")!)
      .GetChatClient("gpt-4o-mini")
      .CreateAIAgent(
        instructions: "You are a helpful assistant, you can help the user with weather information.",
        tools: [AIFunctionFactory.Create(GetWeather)]);
    
  2. Create an environment variable with your OpenAI key
    $env:OPENAI_API_KEY = "sk-..."
    

2. Build the project

cd demos\MinimalConsole
dotnet build

3. Run the demonstration

dotnet run --framework net9.0 --no-build

Sample output:

The weather in Amsterdam is currently cloudy, with a high temperature of 15°C.