Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion samples/dotnet/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@
|Proactive|Demonstrates the basics of a proactive conversation using in-code and Http triggers.|[Proactive](proactive/README.md)|
|OpenTelemetry Agent|Configures OTel tracing, metrics, and logging with OTLP export|[otel](otel/README.md)|
|Agent Framework|Weather agent built with Microsoft Agent Framework SDK|[Agent Framework](Agent%20Framework/README.md)|
|Copilot SDK|Dungeon Scribe RPG agent powered by the GitHub Copilot SDK|[copilot-sdk](copilot-sdk/README.md)|
|Copilot SDK|Dungeon Scribe RPG agent powered by the GitHub Copilot SDK|[copilot-sdk](copilot-sdk/README.md)|
|Named Pipe Agent|Pipe-only echo agent for the DirectLine App Service extension (DirectLineFlex)|[named-pipe-agent](named-pipe-agent/README.md)|
6 changes: 6 additions & 0 deletions samples/dotnet/Samples.sln
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CopilotSdk", "copilot-sdk\C
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SlackAgent", "slackagent\SlackAgent.csproj", "{74277777-C4F9-2F3E-162A-02D8A8E4B702}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NamedPipeAgent", "named-pipe-agent\NamedPipeAgent.csproj", "{C26BC6C8-72FF-435F-82B3-1782CA505EDF}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -103,6 +105,10 @@ Global
{74277777-C4F9-2F3E-162A-02D8A8E4B702}.Debug|Any CPU.Build.0 = Debug|Any CPU
{74277777-C4F9-2F3E-162A-02D8A8E4B702}.Release|Any CPU.ActiveCfg = Release|Any CPU
{74277777-C4F9-2F3E-162A-02D8A8E4B702}.Release|Any CPU.Build.0 = Release|Any CPU
{C26BC6C8-72FF-435F-82B3-1782CA505EDF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C26BC6C8-72FF-435F-82B3-1782CA505EDF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C26BC6C8-72FF-435F-82B3-1782CA505EDF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C26BC6C8-72FF-435F-82B3-1782CA505EDF}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
39 changes: 39 additions & 0 deletions samples/dotnet/named-pipe-agent/MyAgent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using Microsoft.Agents.Builder;
using Microsoft.Agents.Builder.App;
using Microsoft.Agents.Builder.State;
using Microsoft.Agents.Core.Models;
using System.Threading;
using System.Threading.Tasks;

namespace NamedPipeAgent;

public class MyAgent : AgentApplication
{
public MyAgent(AgentApplicationOptions options) : base(options)
{
OnConversationUpdate(ConversationUpdateEvents.MembersAdded, WelcomeMessageAsync);
OnActivity(ActivityTypes.Message, OnMessageAsync, rank: RouteRank.Last);
}

private async Task WelcomeMessageAsync(ITurnContext turnContext, ITurnState turnState, CancellationToken cancellationToken)
{
foreach (ChannelAccount member in turnContext.Activity.MembersAdded)
{
if (member.Id != turnContext.Activity.Recipient.Id)
{
await turnContext.SendActivityAsync(MessageFactory.Text("Hello and Welcome! I am a named-pipe agent."), cancellationToken);
}
}
}

private async Task OnMessageAsync(ITurnContext turnContext, ITurnState turnState, CancellationToken cancellationToken)
{
int count = turnState.Conversation.GetValue("conversation.counter", () => 0) + 1;
turnState.Conversation.SetValue("conversation.counter", count);

await turnContext.SendActivityAsync($"[{count}] You said: {turnContext.Activity.Text}", cancellationToken: cancellationToken);
}
}
23 changes: 23 additions & 0 deletions samples/dotnet/named-pipe-agent/NamedPipeAgent.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<LangVersion>latest</LangVersion>
<ImplicitUsings>disable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<Compile Remove="wwwroot\**" />
<Content Remove="wwwroot\**" />
<EmbeddedResource Remove="wwwroot\**" />
<None Remove="wwwroot\**" />
</ItemGroup>

<ItemGroup>
<!-- Named-pipe transport currently ships as a 1.6 prerelease (beta) package. -->
<PackageReference Include="Microsoft.Agents.Hosting.AspNetCore" Version="1.6.109-beta" />
<PackageReference Include="Microsoft.Agents.Hosting.DirectLine.NamedPipes" Version="1.6.109-beta" />
</ItemGroup>

</Project>
39 changes: 39 additions & 0 deletions samples/dotnet/named-pipe-agent/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using Microsoft.Agents.Hosting.AspNetCore;
using Microsoft.Agents.Hosting.DirectLine.NamedPipes;
using Microsoft.Agents.Storage;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
using NamedPipeAgent;

WebApplicationBuilder builder = WebApplication.CreateBuilder(args);

builder.Services.AddHttpClient();

// Add the AgentApplication, which contains the logic for responding to
// user messages.
builder.AddAgent<MyAgent>();

Comment thread
matthewmeyer marked this conversation as resolved.
// Register IStorage. For development, MemoryStorage is suitable.
// For production Agents, persisted storage should be used so
// that state survives Agent restarts, and operates correctly
// in a cluster of Agent instances.
builder.Services.AddSingleton<IStorage, MemoryStorage>();

// Add the named-pipe transport for the DirectLine App Service extension (DirectLineFlex).
// The pipe is a trusted channel — the sidecar handles external authentication, so this
// pipe-only agent does NOT need JWT token validation or any HTTP endpoint mapping.
//
// These calls (used by the HTTP-based quickstart sample) are intentionally omitted:
// builder.Services.AddAgentAspNetAuthentication(builder.Configuration);
// app.UseAuthentication();
// app.UseAuthorization();
// app.MapAgentRootEndpoint();
// app.MapAgentApplicationEndpoints();
builder.AddAgentNamedPipeTransport();

WebApplication app = builder.Build();

app.Run();
12 changes: 12 additions & 0 deletions samples/dotnet/named-pipe-agent/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"profiles": {
"NamedPipeAgent": {
"commandName": "Project",
"launchBrowser": false,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"applicationUrl": "https://localhost:3979;http://localhost:3978"
}
}
}
80 changes: 80 additions & 0 deletions samples/dotnet/named-pipe-agent/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# Named Pipe Agent Sample (.NET)

This sample demonstrates a **pipe-only** agent — it accepts activities exclusively over named pipes via the `Microsoft.Agents.Hosting.DirectLine.NamedPipes` library. It is the canonical shape used when deploying behind the **DirectLine App Service extension** (a.k.a. DirectLineFlex), where the sidecar relays traffic to the agent over a named pipe instead of HTTP.

The agent echoes the text of each request back to the caller, prefixed with a per-conversation counter.

> **Note:** The named-pipe transport currently is only designed to work with DirectLine App Service extension (DirectLineFlex). The DirectLine App Service extension (DirectLineFlex) that pairs with this agent over the pipe is only available on **Windows** App Service, so this sample is intended for Windows deployment targets.

## What's different from the QuickStart sample

Compared to [quickstart](../quickstart/README.md), this sample:

- **Adds** the `Microsoft.Agents.Hosting.DirectLine.NamedPipes` package and calls `builder.AddAgentNamedPipeTransport();`.
- **Omits** HTTP endpoint mapping (`MapAgentRootEndpoint`, `MapAgentApplicationEndpoints`).
- **Omits** ASP.NET authentication wiring (`AddAgentAspNetAuthentication`, `UseAuthentication`, `UseAuthorization`).

`AddAgentNamedPipeTransport()` adds:

- A hosted service that listens on the named-pipe server pair (`bfv4.pipes.incoming` / `bfv4.pipes.outgoing`).
- A delegating handler that routes outbound HTTP calls to `urn:botframework:namedpipe:*` back through the pipe.

> Because no HTTP endpoint is mapped, this sample is not directly reachable from the Bot Framework Emulator or Agents Playground. If you need an HTTP endpoint as well (for health checks or local Emulator testing), start from [quickstart](../quickstart/README.md) and add `builder.AddAgentNamedPipeTransport()` to that project.

## Prerequisites

- [.NET 8.0 SDK](https://dotnet.microsoft.com/en-us/download/dotnet/8.0)
- **Windows** deployment target — the DirectLine App Service extension (DirectLineFlex) that connects to this agent is only available on Windows App Service.

## Running locally

```bash
dotnet run
```

When the process starts, the agent:

- **Does not** expose `/api/messages` (no HTTP handlers are mapped).
- **Does not** require external authentication configuration.
- Creates the named-pipe server pair (`bfv4.pipes.incoming` / `bfv4.pipes.outgoing`) and waits for a client to connect.

To exercise the agent locally over the named pipe, you need a process on the same machine that connects as the named-pipe client (the role normally played by the DirectLine App Service extension sidecar). For a no-pipe local interactive loop, use the [quickstart](../quickstart/README.md) sample instead.

### Custom pipe name

The DirectLine App Service extension uses the pipe name `{WEBSITE_SITE_NAME}.directline`. To use a different pipe name, pass it to the extension:

```csharp
builder.AddAgentNamedPipeTransport("my-custom-pipe");
```

## Architecture

```
┌──────────────────────┐ ┌─────────────────────┐
│ DirectLineFlex │──named pipe──│ NamedPipeAgent │
│ Sidecar (client) │ │ (this sample) │
└──────────────────────┘ └─────────────────────┘
Handles: Handles:
- External auth (JWT) - Activity processing
- TLS termination - Echo responses
- WebSocket ↔ Pipe relay - State management
```

The pipe is a trusted channel — the sidecar handles external authentication, so no JWT token validation is performed on the agent side.

## Deployment to Azure App Service

When deployed to Azure App Service with the DirectLine App Service extension enabled:

1. The App Service sidecar connects to your agent over the named pipe pair.
2. External traffic, authentication, and TLS are handled by the sidecar.
3. The pipe connection is treated as trusted; no JWT validation is performed on the pipe.

## Further reading

- [Microsoft 365 Agents SDK](https://learn.microsoft.com/en-us/microsoft-365/agents-sdk/)
- [`Microsoft.Agents.Hosting.DirectLine.NamedPipes` package](https://www.nuget.org/packages/Microsoft.Agents.Hosting.DirectLine.NamedPipes)
- [Configure .NET bot for extension](https://learn.microsoft.com/en-us/azure/bot-service/bot-service-channel-directline-extension-net-bot)
- [QuickStart sample](../quickstart/README.md) — HTTP-based base sample
- [Node.js Named Pipe Agent sample](../../nodejs/named-pipe-agent/README.md) — equivalent sample in JavaScript
22 changes: 22 additions & 0 deletions samples/dotnet/named-pipe-agent/appsettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"AgentApplication": {
"StartTypingTimer": false,
"RemoveRecipientMention": false,
"NormalizeMentions": false
},

"Logging": {
"Debug": {
"IncludeScopes": true
},
"Console": {
"IncludeScopes": true
},
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning",
"Microsoft.Agents": "Debug",
"Microsoft.Hosting.Lifetime": "Information"
}
}
}
1 change: 1 addition & 0 deletions samples/nodejs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@
|Copilot Studio Skill|Call the echo bot from a Copilot Studio skill |[copilotstudio-skill](copilotstudio-skill/README.md)|
|Copilot SDK|Dungeon Scribe RPG agent powered by the GitHub Copilot SDK|[copilot-sdk](copilot-sdk/README.md)|
|OTel Agent|Agent with OTel instrumentation |[otel](otel/README.md)|
|Named Pipe Agent|Pipe-only echo agent for the DirectLine App Service extension (DirectLineFlex)|[named-pipe-agent](named-pipe-agent/README.md)|
98 changes: 98 additions & 0 deletions samples/nodejs/named-pipe-agent/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
# Named Pipe Agent Sample (Node.js)

This sample demonstrates a **pipe-only** agent — it accepts activities exclusively over named pipes via the `@microsoft/agents-hosting-directline-namedpipes` package. It is the canonical shape used when deploying behind the **DirectLine App Service extension** (a.k.a. DirectLineFlex), where the sidecar relays traffic to the agent over a named pipe instead of HTTP.

The agent echoes the text of each request back to the caller, prefixed with a per-conversation counter.

> **Note:** The named-pipe transport currently is only designed to work with DirectLine App Service extension (DirectLineFlex). The DirectLine App Service extension (DirectLineFlex) that pairs with this agent over the pipe is only available on **Windows** App Service, so this sample is intended for Windows deployment targets.

## What's different from the QuickStart sample

Compared to [quickstart](../quickstart/README.md), this sample:

- **Uses** `createLocalAdapter()` instead of `CloudAdapter` — no credentials needed.
- **Uses** `startNamedPipeServer()` instead of `startServer()` — no HTTP endpoint.
- **Omits** Express, `.env` auth config, and JWT middleware entirely.

## Prerequisites

- [Node.js](https://nodejs.org) version 20 or higher

```bash
node --version
```

- **Windows** — this sample is intended for Windows deployment targets (the DirectLine App Service extension / DirectLineFlex that connects to it is Windows-only).

## Running locally

1. Open this folder from your IDE or terminal of preference.
1. Build the sample (this also installs dependencies via the `prebuild` script):

```sh
npm run build
```
Comment thread
Copilot marked this conversation as resolved.

1. Copy the environment template and start the agent:

```powershell
Copy-Item env.TEMPLATE .env # edit if needed
npm start
```

When the process starts, the agent:

- **Does not** expose an HTTP endpoint (no Express, no `/api/messages`).
- **Does not** require Azure/Entra authentication configuration.
- Creates the named-pipe server pair (`bfv4.pipes.incoming` / `bfv4.pipes.outgoing`) and waits for a client to connect.

To exercise the agent locally over the named pipe, you need a process on the same machine that connects as the named-pipe client (the role normally played by the DirectLine App Service extension sidecar). For a no-pipe local interactive loop, use the [quickstart](../quickstart/README.md) sample instead.

### Custom pipe name

The DirectLine App Service extension uses the pipe name `{WEBSITE_SITE_NAME}.directline`. Set the pipe name via the `PIPE_NAME` environment variable (defaults to `bfv4.pipes`):

```powershell
$env:PIPE_NAME='{WEBSITE_SITE_NAME}.directline'; npm start
```
Comment thread
matthewmeyer marked this conversation as resolved.

## Architecture

```
┌──────────────────────┐ ┌─────────────────────┐
│ DirectLineFlex │──named pipe──│ NamedPipeAgent │
│ Sidecar (client) │ │ (this sample) │
└──────────────────────┘ └─────────────────────┘
Handles: Handles:
- External auth (JWT) - Activity processing
- TLS termination - Echo responses
- WebSocket ↔ Pipe relay - State management
```

The pipe is a trusted channel — the sidecar handles external authentication, so no JWT token validation is needed on the agent side.

## Key APIs used

| API | Purpose |
|-----|---------|
| `createLocalAdapter()` | Creates a `CloudAdapter` configured for pipe-only use (no credentials) |
| `startNamedPipeServer(adapter, logic, options)` | Starts the pipe server with auto-reconnect |
| `service.ready` | Promise that resolves when the first connection is established |
| `service.stop()` | Graceful shutdown |

## Deployment to Azure App Service

When deployed to Azure App Service with the DirectLine App Service extension enabled:

1. The App Service sidecar connects to your agent over the named pipe pair.
2. External traffic, authentication, and TLS are handled by the sidecar.
3. The pipe connection is treated as trusted; no JWT validation is performed on the pipe.
4. Set the pipe name via the `PIPE_NAME` env var to match the platform expectation.

## Further reading

- [Microsoft 365 Agents SDK](https://learn.microsoft.com/en-us/microsoft-365/agents-sdk/)
- [`@microsoft/agents-hosting-directline-namedpipes` package](https://www.npmjs.com/package/@microsoft/agents-hosting-directline-namedpipes)
- [Configure Node.js bot for extension](https://learn.microsoft.com/en-us/azure/bot-service/bot-service-channel-directline-extension-node-bot)
- [QuickStart sample](../quickstart/README.md) — HTTP-based base sample
- [.NET Named Pipe Agent sample](../../dotnet/named-pipe-agent/README.md) — equivalent sample in .NET
7 changes: 7 additions & 0 deletions samples/nodejs/named-pipe-agent/env.TEMPLATE
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# rename to .env

# Named pipe name. The DirectLine App Service extension uses "{WEBSITE_SITE_NAME}.directline".
# Defaults to "bfv4.pipes" when unset.
PIPE_NAME=bfv4.pipes

DEBUG=agents:*:error
Loading
Loading