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
4 changes: 2 additions & 2 deletions dotnet/samples/04-hosting/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ The .NET hosting packages expose agents through several protocols. Authenticatio
| Hosting surface | Endpoint access | Caller-scoped resources |
| --- | --- | --- |
| AG-UI | Protect the endpoints returned by `MapAGUIServer`. | Persisted agent sessions, including continuation and approval state. Without a session store, sessions are ephemeral. |
| A2A | Protect both HTTP+JSON and JSON-RPC endpoints when both are exposed. | Sessions and tasks. The built-in task store retains tasks even when session persistence is disabled. |
| A2A | Protect both HTTP+JSON and JSON-RPC endpoints when both are exposed. | Agent sessions by default. Tasks are only supported with a custom A2A handler. |
| OpenAI Responses / Conversations | Protect every mapped Responses and Conversations route group. | Responses, conversations, conversation listings, and configured agent sessions. Response/conversation storage does not depend on explicitly registering an `AgentSessionStore`. The mapping does not wrap a configured agent session store; register it with an isolation-enabled helper or wrap it explicitly. |
| OpenAI Chat Completions | Protect the endpoints returned by `MapOpenAIChatCompletions`. | This adapter does not itself persist conversations across requests. Any additional application-owned state needs its own isolation. |
| Core Hosting / AzureStorage | These libraries do not expose HTTP endpoints. The host owns access control. | Session-store helpers can wrap stores with caller isolation; storage credentials alone do not identify the caller. |
Expand Down Expand Up @@ -74,7 +74,7 @@ Custom providers can resolve trusted identity without ASP.NET Core claims or `IH

### Understand store defaults

The built-in AG-UI and A2A wiring adds isolation decorators where absent. With a provider registered, the added decorators require an isolation key. Without a provider, they allow unscoped access; that shared mode is not appropriate for retained data belonging to different callers. A2A also wraps its task store, independently of session persistence.
The built-in AG-UI and A2A handlers add session store isolation decorators where absent. With a provider registered, the added decorators require an isolation key. Without a provider, they allow unscoped access; that shared mode is not appropriate for retained data belonging to different callers. For a custom A2A handler, the server applies the same isolation to the task store; the handler is responsible for any other state it manages.

OpenAI Responses/Conversations use the registered provider to scope their own storage and lookup operations. This protection is needed even if no agent session store is configured. Unlike the AG-UI and A2A wiring, the Responses mapping does not add an isolation decorator to a configured agent session store. Register that store with one of the isolation-enabled helpers below, or wrap it in `IsolationKeyScopedAgentSessionStore`, so session and approval state is also scoped to the caller; a store registered directly as a keyed `AgentSessionStore` is used as-is.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,14 @@ original invoice and the credit memo number. Use the 'Formal Credit Notification
// Create the agent card published at the well-known discovery endpoint.
AgentCard policyAgentCard = PolicyAgentCard.Create(agentUrl);

// IMPORTANT: In production, register an AgentIsolationKeyProvider to isolate sessions and tasks by authenticated caller.
// Without this, contextId/taskId alone are the lookup keys — any caller who knows them can access another caller's data.
// IMPORTANT: In production, register an AgentIsolationKeyProvider to isolate sessions by authenticated caller.
// Without this, contextId alone is the lookup key - any caller who knows it can access another caller's data.
// Example using claims-based identity:
// builder.Services.UseClaimsBasedAgentIsolation(new() { ClaimType = ClaimTypes.NameIdentifier });
//
// This sample does not authenticate A2A callers. Configure authentication and enforce authorization
// on both enabled protocol bindings, for example with RequireAuthorization() on each mapping.
// For claims-based isolation, also call AddHttpContextAccessor() and use a unique caller claim.
// Task isolation is needed even without session persistence. See the sample README and shared hosting guide.

// By default, NoopAgentSessionStore is used — sessions are not persisted across requests.
// To enable multi-turn conversations, register a session store explicitly, e.g.:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@ card with the same policy, replace its mapping with:
app.MapWellKnownAgentCard(policyAgentCard).RequireAuthorization("InvokeAgent");
```

Configure caller isolation for retained sessions and tasks, including tasks kept
in memory when session persistence is disabled. Reference
Configure caller isolation for retained agent sessions. Reference
`Microsoft.Agents.AI.Hosting.AspNetCore` and register the provider before
`builder.Build()`:

Expand All @@ -78,7 +77,7 @@ With `MapInboundClaims = false`, `sub` is the token's unmapped subject claim.
This example assumes a single trusted issuer and tenant. For multiple issuers or
tenants, choose a validated identity boundary that prevents subject collisions;
see [Choose the isolation boundary](../../04-hosting/README.md#choose-the-isolation-boundary)
in the shared hosting guide. Never use a caller-supplied context or task ID as
in the shared hosting guide. Never use a caller-supplied context ID as
proof of ownership. Authentication and endpoint authorization do not replace
isolation of retained caller data.

Expand Down
2 changes: 1 addition & 1 deletion dotnet/samples/05-end-to-end/A2AClientServer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ This sample demonstrates a minimal end-to-end A2A flow:
2. `A2AClient` discovers the policy agent and sends it messages over A2A.

> [!WARNING]
> This sample does not authenticate A2A callers. Multi-user hosts must configure authentication and authorize both enabled protocol bindings, for example with `MapA2AHttpJson(...).RequireAuthorization()` and `MapA2AJsonRpc(...).RequireAuthorization()`. Configure caller isolation for tasks as well as persisted sessions; disabling session persistence does not disable task storage. See the [shared hosting guide](../../04-hosting/README.md), including the client credential requirements. Azure credentials used by the agent do not authenticate callers to this server.
> This sample does not authenticate A2A callers. Multi-user hosts must configure authentication and authorize both enabled protocol bindings, for example with `MapA2AHttpJson(...).RequireAuthorization()` and `MapA2AJsonRpc(...).RequireAuthorization()`. Configure caller isolation for persisted agent sessions. See the [shared hosting guide](../../04-hosting/README.md), including the client credential requirements. Azure credentials used by the agent do not authenticate callers to this server.

## Prerequisites

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,9 @@ public static IEndpointConventionBuilder MapA2AHttpJson(this IEndpointRouteBuild
/// <remarks>
/// This method does not require authorization automatically. Configure authentication and enforce
/// endpoint authorization, for example with <c>RequireAuthorization()</c> on the returned builder.
/// Multi-user hosts also need an <see cref="AgentIsolationKeyProvider"/> to isolate sessions and tasks;
/// task isolation remains necessary without session persistence. For claims-based isolation, register
/// The default server rejects task operations and requires no task store registration.
/// Multi-user hosts need an <see cref="AgentIsolationKeyProvider"/> to isolate retained sessions
/// and any tasks produced by a custom handler. For claims-based isolation, register
/// <c>AddHttpContextAccessor()</c> and <c>UseClaimsBasedAgentIsolation(...)</c> from
/// <c>Microsoft.Agents.AI.Hosting.AspNetCore</c>, using a claim that uniquely identifies the caller.
/// Protect each enabled protocol binding, not just one of the HTTP+JSON and JSON-RPC endpoints.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,25 +30,26 @@ public static class A2AServerServiceCollectionExtensions
/// <returns>The <paramref name="agentBuilder"/> for chaining.</returns>
/// <remarks>
/// <para>
/// <strong>Trust model.</strong> The A2A <c>contextId</c> and <c>taskId</c> arrive
/// from the wire and are treated as chain-resume identifiers — <em>not</em> as
/// authorization tokens. <see cref="AgentSessionStore"/> accepts an explicit user partition,
/// while <see cref="ITaskStore"/> has no principal or owner dimension.
/// Hosts that serve more than one user must supply both dimensions from a trusted identity,
/// typically by calling <c>UseClaimsBasedAgentIsolation(...)</c> from
/// <c>Microsoft.Agents.AI.Hosting.AspNetCore</c> (or by registering a custom
/// <see cref="AgentIsolationKeyProvider"/>). When an <see cref="AgentIsolationKeyProvider"/>
/// is registered, both the session store and the task store are automatically wrapped
/// with tenant-scoped isolation. When no isolation provider is registered, behavior
/// is unchanged — the bare identifiers are used directly, which is appropriate for
/// first-run / single-user / prototyping scenarios but unsafe for multi-user hosts.
/// The default handler returns messages, rejects task operations, and does not resolve a
/// registered <see cref="ITaskStore"/>.
/// </para>
/// <para>
/// When a custom <see cref="IAgentHandler"/> is registered under the agent name, the server uses
/// the task store registered under that name or an in-memory task store.
/// </para>
/// <para>
/// A <c>contextId</c> is a conversation lookup identifier, not proof of ownership.
/// Multi-user hosts must derive isolation keys from a trusted caller identity, for example by
/// registering <c>AddHttpContextAccessor()</c> and <c>UseClaimsBasedAgentIsolation(...)</c>
/// from <c>Microsoft.Agents.AI.Hosting.AspNetCore</c> with a claim that uniquely identifies the caller.
/// The server uses the <see cref="AgentIsolationKeyProvider"/> to scope the session store for
/// the default handler or the task store for a custom handler. Custom handlers must isolate
/// any state they manage themselves.
/// </para>
/// <para>
/// Isolation does not configure authentication or endpoint authorization. HTTP hosts must configure
/// an authentication scheme and enforce authorization on each mapped A2A binding, for example with
/// <c>RequireAuthorization()</c>. Claims-based isolation also requires <c>AddHttpContextAccessor()</c>
/// and a claim that uniquely identifies the caller. Task isolation is required for multi-user hosts
/// even when agent sessions are not persisted, because the task store retains its own state.
/// an authentication scheme and enforce authorization on each mapped A2A binding, for example
/// with <c>RequireAuthorization()</c>.
/// </para>
/// </remarks>
public static IHostedAgentBuilder AddA2AServer(this IHostedAgentBuilder agentBuilder, Action<A2AServerRegistrationOptions>? configureOptions = null)
Expand All @@ -70,11 +71,8 @@ public static IHostedAgentBuilder AddA2AServer(this IHostedAgentBuilder agentBui
/// <param name="configureOptions">An optional callback to configure <see cref="A2AServerRegistrationOptions"/>.</param>
/// <returns>The <paramref name="builder"/> for chaining.</returns>
/// <remarks>
/// See the trust-model remarks on <see cref="AddA2AServer(IHostedAgentBuilder, Action{A2AServerRegistrationOptions}?)"/>
/// for guidance on multi-user hosts (the wire <c>contextId</c> and <c>taskId</c>
/// are chain-resume identifiers, not authorization tokens; multi-user hosts must
/// supply a trusted user partition via <c>UseClaimsBasedAgentIsolation(...)</c> or
/// a custom <see cref="AgentIsolationKeyProvider"/>).
/// See <see cref="AddA2AServer(IHostedAgentBuilder, Action{A2AServerRegistrationOptions}?)"/>
/// for default message handling and guidance on multi-user hosts.
/// </remarks>
public static IHostApplicationBuilder AddA2AServer(this IHostApplicationBuilder builder, string agentName, Action<A2AServerRegistrationOptions>? configureOptions = null)
{
Expand All @@ -96,11 +94,8 @@ public static IHostApplicationBuilder AddA2AServer(this IHostApplicationBuilder
/// <param name="configureOptions">An optional callback to configure <see cref="A2AServerRegistrationOptions"/>.</param>
/// <returns>The <paramref name="builder"/> for chaining.</returns>
/// <remarks>
/// See the trust-model remarks on <see cref="AddA2AServer(IHostedAgentBuilder, Action{A2AServerRegistrationOptions}?)"/>
/// for guidance on multi-user hosts (the wire <c>contextId</c> and <c>taskId</c>
/// are chain-resume identifiers, not authorization tokens; multi-user hosts must
/// supply a trusted user partition via <c>UseClaimsBasedAgentIsolation(...)</c> or
/// a custom <see cref="AgentIsolationKeyProvider"/>).
/// See <see cref="AddA2AServer(IHostedAgentBuilder, Action{A2AServerRegistrationOptions}?)"/>
/// for default message handling and guidance on multi-user hosts.
/// </remarks>
public static IHostApplicationBuilder AddA2AServer(this IHostApplicationBuilder builder, AIAgent agent, Action<A2AServerRegistrationOptions>? configureOptions = null)
{
Expand All @@ -121,11 +116,8 @@ public static IHostApplicationBuilder AddA2AServer(this IHostApplicationBuilder
/// <param name="configureOptions">An optional callback to configure <see cref="A2AServerRegistrationOptions"/>.</param>
/// <returns>The <paramref name="services"/> for chaining.</returns>
/// <remarks>
/// See the trust-model remarks on <see cref="AddA2AServer(IHostedAgentBuilder, Action{A2AServerRegistrationOptions}?)"/>
/// for guidance on multi-user hosts (the wire <c>contextId</c> and <c>taskId</c>
/// are chain-resume identifiers, not authorization tokens; multi-user hosts must
/// supply a trusted user partition via <c>UseClaimsBasedAgentIsolation(...)</c> or
/// a custom <see cref="AgentIsolationKeyProvider"/>).
/// See <see cref="AddA2AServer(IHostedAgentBuilder, Action{A2AServerRegistrationOptions}?)"/>
/// for default message handling and guidance on multi-user hosts.
/// </remarks>
public static IServiceCollection AddA2AServer(this IServiceCollection services, string agentName, Action<A2AServerRegistrationOptions>? configureOptions = null)
{
Expand Down Expand Up @@ -159,11 +151,8 @@ public static IServiceCollection AddA2AServer(this IServiceCollection services,
/// <param name="configureOptions">An optional callback to configure <see cref="A2AServerRegistrationOptions"/>.</param>
/// <returns>The <paramref name="services"/> for chaining.</returns>
/// <remarks>
/// See the trust-model remarks on <see cref="AddA2AServer(IHostedAgentBuilder, Action{A2AServerRegistrationOptions}?)"/>
/// for guidance on multi-user hosts (the wire <c>contextId</c> and <c>taskId</c>
/// are chain-resume identifiers, not authorization tokens; multi-user hosts must
/// supply a trusted user partition via <c>UseClaimsBasedAgentIsolation(...)</c> or
/// a custom <see cref="AgentIsolationKeyProvider"/>).
/// See <see cref="AddA2AServer(IHostedAgentBuilder, Action{A2AServerRegistrationOptions}?)"/>
/// for default message handling and guidance on multi-user hosts.
/// </remarks>
public static IServiceCollection AddA2AServer(this IServiceCollection services, AIAgent agent, Action<A2AServerRegistrationOptions>? configureOptions = null)
{
Expand All @@ -186,6 +175,7 @@ public static IServiceCollection AddA2AServer(this IServiceCollection services,
private static A2AServer CreateA2AServer(IServiceProvider serviceProvider, AIAgent agent, A2AServerRegistrationOptions? options)
{
var isolationKeyProvider = serviceProvider.GetService<AgentIsolationKeyProvider>();
var logger = (serviceProvider.GetService<ILoggerFactory>() ?? NullLoggerFactory.Instance).CreateLogger<A2AServer>();

var agentHandler = serviceProvider.GetKeyedService<IAgentHandler>(agent.Name);
if (agentHandler is null)
Expand All @@ -203,13 +193,11 @@ private static A2AServer CreateA2AServer(IServiceProvider serviceProvider, AIAge
innerAgent: agent,
sessionStore: agentSessionStore);

agentHandler = new A2AAgentHandler(hostAgent, AgentRunMode.ReturnMessage);
return new MessageOnlyA2AServer(new A2AAgentHandler(hostAgent, AgentRunMode.ReturnMessage), logger, options?.ServerOptions);
}

var loggerFactory = serviceProvider.GetService<ILoggerFactory>() ?? NullLoggerFactory.Instance;
ITaskStore taskStore = serviceProvider.GetKeyedService<ITaskStore>(agent.Name) ?? new InMemoryTaskStore();

// Wrap the task store with isolation key scoping, same as the session store above.
if (taskStore is not IsolationKeyScopedTaskStore)
{
taskStore = new IsolationKeyScopedTaskStore(taskStore, isolationKeyProvider, strict: isolationKeyProvider != null);
Expand All @@ -219,7 +207,7 @@ private static A2AServer CreateA2AServer(IServiceProvider serviceProvider, AIAge
agentHandler,
taskStore,
new ChannelEventNotifier(),
loggerFactory.CreateLogger<A2AServer>(),
logger,
options?.ServerOptions);
}
}
Loading
Loading