Skip to content

Add Microsoft Agent Framework plugin samples - #250

Open
DABH wants to merge 42 commits into
mainfrom
dabh/microsoft-agent-framework
Open

DABH wants to merge 42 commits into
mainfrom
dabh/microsoft-agent-framework

Conversation

@DABH

@DABH DABH commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

What was changed

This PR adds samples for the new Temporal .NET plugin for Microsoft Agent Framework that was just released in pre-release on NuGet. This is the first AI integration for .NET, but relative to the other integrations we've shipped and made samples for, the usual suspects are included here: hello world, tools, MCP, human in the loop, middleware, structured output, streaming and continue-as-new.

Each sample is its own project with System.CommandLine worker and workflow commands, a README and xUnit tests on the package's scripted chat client and MCP servers (in memory and over stdio), with no API key. The worker exits with a message when OPENAI_API_KEY is missing; the MCP sample hosts its own stdio server through an mcp-server command. The samples build with this repository's .NET 10 SDK; the plugin itself targets net8.0.

Why?

The plugin and its docs page need runnable, tested samples to quote.

Checklist

  1. No linked issue.

  2. How was this tested: dotnet build, dotnet format --verify-no-changes and the ten new tests pass locally on two dev servers, with the package restored from nuget.org. Directory.Packages.props pins Temporalio.Extensions.MicrosoftAgentFramework 0.0.1, the plugin's first release. The docs link in the READMEs resolves once temporalio/documentation has the page.

DABH added 19 commits November 13, 2026 01:48
Temporalio.MicrosoftAgentFramework is pinned to the local-feed build 0.0.1-local.2 while the package is unpublished. Microsoft.Agents.AI 1.26.0 and Microsoft.Extensions.AI.OpenAI 10.10.0 are the versions the plugin's lock file resolves; ModelContextProtocol.Core 2.2.0 is the plugin's MCP dependency.
Eight console projects under src/MicrosoftAgentFramework, one per scenario: HelloWorld, Tools, Mcp, HumanInTheLoop, Middleware, StructuredOutput, Streaming and ContinueAsNew. Each builds the plugin with a worker-side OpenAI factory, runs model calls as the MicrosoftAgentFramework.InvokeModel Activity and carries snipsync markers for the docs page.
One test class per scenario against the plugin's FakeChatClient and a local dev server, with no credentials. Each test asserts the scheduled Activity types by name; the Mcp test serves the sample's tool through InMemoryMcpServer, and the ContinueAsNew test lowers limit.historyCount.suggestContinueAsNew to 5 and takes a turn on the new run.
Index and per-scenario READMEs, the root README row, and CODEOWNERS rows shared by the SDK and AI SDK teams.
The chat client factory runs inside the first model Activity, so a missing key used to fail every attempt under the default retry policy while the starter waited. Each worker now checks the key before it connects and exits with a one-line message, and the factory's own check throws a non-retryable ApplicationFailureException with the plugin's configuration error type.
MaxCachedWorkflows = 0 on the test worker evicts the Workflow after every Workflow Task, so each task replays the sample's Workflow Definition from history and a non-deterministic sample fails in CI.
The tools-worker region is now the worker construction with AddActivity, and the mcp-worker region is the MCP transport registration, so the docs page does not repeat the OpenAI factory shown by hello-world-worker. The context provider's marker is middleware-provider.
A retried model Activity publishes its attempt from the start under a new ResponseId; the subscriber now prints a note and starts the line over instead of appending the repeated text. The default verb also accepts the word workflow, like the other samples.
The approval request id is ficc_ plus the function call id, and an unanswered approval request travels inside the serialized session across continue-as-new, so the next turn fails until it is answered or carried.
The continue-as-new test drives each turn through Update-With-Start with UseExisting as the send-message verb does; the approval test covers the validator; the streaming test reads the subscription to its end; the middleware test asserts the whole instruction string; the Mcp test says the stdio verb is covered by hand.
The plugin now fails a throwing chat client factory with a non-retryable MicrosoftAgentFrameworkConfigurationError, so the factories throw a plain InvalidOperationException again and the READMEs describe the plugin's behavior.
A wrong verb needed a reachable Temporal Service before the usage line
appeared, because every starter connected first. Each program now checks
the verb before the key check and the connection, prints the usage line
to stderr and exits with code 1.
The starter polled the pending-approval Query for 60 seconds after the
Workflow had failed or completed, then blamed the agent. The starter now
races the result against the poll: when the agent answers without asking
it prints the result, and a failed run surfaces its cause at once. The
README says what to do about a run left waiting on the fixed id.
typeof(EchoMcpServer).Assembly.Location tied the worker to a DLL on disk
and failed a single-file publish with IL3000. The worker now runs
Environment.ProcessPath with the mcp-server verb, and falls back to the
DLL in AppContext.BaseDirectory only when the process is the dotnet
muxer.
send-message without a prompt exits with code 1 instead of 0, and
end-chat without a running chat prints one line and exits with code 1
instead of dying on the RpcException.
The continue-as-new test checks one model Activity in each run that took
a turn and none in the closing run; the structured output test checks
that the model Activity is the only one.
The restart heuristic in the streaming starter holds because the sample
makes one model call; an agent with tools gets a new ResponseId on every
round.
A missing prompt was caught only after the client had connected, so
against an unreachable Temporal Service the starter died on the
connection instead of printing the usage line. The check now sits with
the verb check, and SendMessageAsync takes the prompt it was given.
The #pragma pair for IDE0052 sat inside the streaming-workflow marker
region and would have been spliced into the docs page; the build and
the format check pass without it, so it is gone. The index README now
says ChatOptions comes from Microsoft.Extensions.AI, not Agent
Framework.
DABH added 9 commits November 13, 2026 11:50
The final plugin build names each model Activity after the model and
each tool Activity after the tool, without the old
microsoft-agent-framework prefix, so the two READMEs that quote a
summary now show `gpt-4o-mini` and `GetWeather`. No test asserts a
summary and no README quotes the retry rule, so nothing else moves.
The plugin retries a throwing chat client factory under the model
Activity's retry policy instead of failing the run once, so the factory
comments and the two READMEs that said "fails in one attempt" now say
that, with the worker's start-up key check as the first line of
defense. The Mcp README also notes that Agent Framework's MCP name rule
leaves the `echo` tool name unchanged.
The plugin now gives the model the text FunctionInvokingChatClient uses
for a rejected approval, "Tool call invocation rejected." plus the
reason, so the HumanInTheLoop test and README quote that text. The
package reference accepts Microsoft.Agents.AI below 2.0.0; the central
pin of 1.26.0 satisfies it, so nothing else moves.
The plugin now fails the run before the first model call when an agent
names a streaming topic and the Workflow hosts no WorkflowStream; the
Streaming README states that next to the field the sample constructs
in its WorkflowInit constructor.
The SDK team's review renamed the package and its root namespace; the
class names, Activity names and error types are the same. The central
pin moves to 0.0.1-local.7 in the package's new alphabetical slot, the
eight project references and every using follow, and the two Streaming
files keep their directives in order. The package now targets net8.0;
the samples keep this repository's net10.0 target.
The release-stage line names Temporalio.Extensions.MicrosoftAgentFramework,
and the prerequisites say the .NET 10 SDK is this repository's build
requirement while the plugin itself targets net8.0.
The package is packed from ai-integrations commit 4ad54eba, the approved
state of temporalio/ai-integrations#523, with the same net8.0 target
and dependency floors as local.7, so only the version moves.
The plugin delivers results the way the MCP C# SDK's McpClientTool
does: plain text as a TextContent and an isError result whole, with no
failed Activity. The Mcp README now states that next to the Activity
table.
DABH added 11 commits November 16, 2026 23:32
The eight programs now use System.CommandLine like the other samples in
this repository: worker and workflow subcommands, --help, a cancellation
token wired to ctrl+c, and unknown verbs rejected with usage. The
Streaming prompt is an optional argument of the workflow command and
HumanInTheLoop takes an explicit --reject option, so a typo can no
longer approve. The plugin is built inside the worker command, so the
starter's client carries no OpenAI client.
The Workflow loops while the agent keeps asking for approval, but the
starter answered one batch and then blocked on the result, so a second
round hung. The starter now loops while the result is not complete:
delay, skip the Query once the Workflow has closed, and answer each new
request once.
A blank prompt reached TurnAsync and failed the Workflow Task on every
retry, and a turn sent after end-chat was still accepted while the run
waited for its handlers. A validator on TurnAsync now rejects both, so
the Update fails without touching Event History.
end-chat queried the transcript before signalling, so a turn still in
flight was missing, and an already closed chat printed its old
transcript and then "No chat is running". The starter now signals
first, waits for the result and queries the transcript after the
Workflow has closed.
/tmp/../etc/passwd passed the StartsWith check. The wrapper now resolves
. and .. segments on / in memory before the check; Path.GetFullPath
would read the host's rules and working directory, which differ between
workers. The Middleware test adds that call.
Microsoft.Agents.AI has no name rule and McpClientTool keeps the
server's name; the plugin applies the rule of the Python Agent
Framework's MCPTool so one rule serves both plugins. The Mcp README
says so.
ListToolsAsync returns IReadOnlyList<AIFunction> and AIFunction derives
from AITool, so new List<AITool>(tools) replaces the runtime Cast in
the docs snippet.
Seven test classes started a dev server per test, up to seven at once
on the two-core runners. They now inherit WorkflowEnvironmentTestBase
and the Environment collection like WorkflowStreamsTests.
ContinueAsNewWorkflowTests keeps its own server for the lowered
continue-as-new threshold.
A second test registers a StdioClientTransport that runs
dotnet <dll> mcp-server, the worker's own launch shape, so CI covers
EchoMcpServer.RunAsync and the mcp-server command without an API key.
The DLL runs from the sample's own output directory, passed in as
assembly metadata: the test output lacks the assemblies the ASP.NET
shared framework provides to the test host, and the child has only
Microsoft.NETCore.App.
The fake now streams with a 100-millisecond delay per update, and the
test checks that no ActivityTaskCompleted event exists when the first
update arrives, so a publisher that only flushed at the end of the
Activity would fail it.
The package is on nuget.org now, so the local-feed pin goes and CI can restore the branch.
@DABH
DABH marked this pull request as ready for review November 17, 2026 19:17
@DABH
DABH requested review from a team as code owners November 17, 2026 19:17
DABH added 3 commits November 17, 2026 21:40
With the low Continue-As-New threshold, the Workflow Task for the rejected Update could carry the
continue-as-new suggestion, so the run moved on before the second turn and had no model Activity.
The check now runs on the shared dev server next to the end-chat case.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants