# RunRecordingAgent

> Tracon documentation. Tracon is a .NET package family that adds a control
> plane on Microsoft Agent Framework, published as NuGet packages that run
> inside your own ASP.NET Core application.
>
> Page: https://tracon.dev/api/tracon.runrecordingagent/
> Summary: RunRecordingAgent: Run completion: usage/cost merging, error mapping, and the terminal store write. RunRecordingAgent.CompleteAsync fans out to the root-only notifications in.

<div class="api-provenance">Namespace Tracon · Assembly <code>Tracon.Core.dll</code></div>

Run completion: usage/cost merging, error mapping, and the terminal store
write. [RunRecordingAgent.CompleteAsync](/api/tracon.runrecordingagent/) fans out to the root-only notifications
in `RunRecordingAgent.Notifications.cs`, but owns the outcome itself.

```csharp
public sealed class RunRecordingAgent : DelegatingAIAgent
```

<dl class="api-relations"><dt>Inheritance</dt><dd><a href="https://learn.microsoft.com/dotnet/api/system.object">object</a> ← AIAgent ← DelegatingAIAgent ← <a href="/api/tracon.runrecordingagent/">RunRecordingAgent</a></dd><dt>Inherited Members</dt><dd>DelegatingAIAgent.GetService(Type, object?), DelegatingAIAgent.Name, DelegatingAIAgent.Description, AIAgent.GetService(Type, object?), AIAgent.GetService&lt;TService&gt;(object?), AIAgent.CreateSessionAsync(CancellationToken), AIAgent.SerializeSessionAsync(AgentSession, JsonSerializerOptions?, CancellationToken), AIAgent.DeserializeSessionAsync(JsonElement, JsonSerializerOptions?, CancellationToken), AIAgent.RunAsync(AgentSession?, AgentRunOptions?, CancellationToken), AIAgent.RunAsync(string, AgentSession?, AgentRunOptions?, CancellationToken), AIAgent.RunAsync(ChatMessage, AgentSession?, AgentRunOptions?, CancellationToken), AIAgent.RunAsync(IEnumerable&lt;ChatMessage&gt;, AgentSession?, AgentRunOptions?, CancellationToken), AIAgent.RunStreamingAsync(AgentSession?, AgentRunOptions?, CancellationToken), AIAgent.RunStreamingAsync(string, AgentSession?, AgentRunOptions?, CancellationToken), AIAgent.RunStreamingAsync(ChatMessage, AgentSession?, AgentRunOptions?, CancellationToken), AIAgent.RunStreamingAsync(IEnumerable&lt;ChatMessage&gt;, AgentSession?, AgentRunOptions?, CancellationToken), AIAgent.RunAsync&lt;T&gt;(AgentSession?, JsonSerializerOptions?, AgentRunOptions?, CancellationToken), AIAgent.RunAsync&lt;T&gt;(string, AgentSession?, JsonSerializerOptions?, AgentRunOptions?, CancellationToken), AIAgent.RunAsync&lt;T&gt;(ChatMessage, AgentSession?, JsonSerializerOptions?, AgentRunOptions?, CancellationToken), AIAgent.RunAsync&lt;T&gt;(IEnumerable&lt;ChatMessage&gt;, AgentSession?, JsonSerializerOptions?, AgentRunOptions?, CancellationToken), AIAgent.Id, AIAgent.Name, AIAgent.Description, AIAgent.CurrentRunContext, <a href="https://learn.microsoft.com/dotnet/api/system.object.gettype">object.GetType()</a>, <a href="https://learn.microsoft.com/dotnet/api/system.object.tostring">object.ToString()</a>, <a href="https://learn.microsoft.com/dotnet/api/system.object.equals#system-object-equals(system-object)">object.Equals(object?)</a>, <a href="https://learn.microsoft.com/dotnet/api/system.object.equals#system-object-equals(system-object-system-object)">object.Equals(object?, object?)</a>, <a href="https://learn.microsoft.com/dotnet/api/system.object.referenceequals">object.ReferenceEquals(object?, object?)</a>, <a href="https://learn.microsoft.com/dotnet/api/system.object.gethashcode">object.GetHashCode()</a></dd></dl>

## Remarks

This is *not* a Microsoft Agent Framework middleware but a
`AI.DelegatingAIAgent` wrapper. The reason: the MAF middleware chain is
specific to one agent, and `HarnessAgent` adds its own inner decorators.
The outer wrapper works the same way on **every** agent type, the harness included.

Tool calls are read from the `AI.FunctionCallContent` and
`AI.FunctionResultContent` contents that MAF produces; no separate hook is necessary.

**The root span starts here.** The wrapper is the outermost decorator
(`Order = 0`), therefore the `tracon.run` span that it opens collects the
spans of the inner wrappers and of the model calls as children. This is the only way
to link the run identifier and the trace identifier to each other.

Tracon builds this wrapper around every agent that [IAgentCatalog](/api/tracon.iagentcatalog/) resolves;
resolve the agent through the catalog instead of constructing the wrapper.

## Methods

### <a id="Tracon_RunRecordingAgent_RunCoreAsync_System_Collections_Generic_IEnumerable_Microsoft_Extensions_AI_ChatMessage__Microsoft_Agents_AI_AgentSession_Microsoft_Agents_AI_AgentRunOptions_System_Threading_CancellationToken_"></a> RunCoreAsync\(IEnumerable<ChatMessage\>, AgentSession?, AgentRunOptions?, CancellationToken\)

Core implementation of the agent invocation logic with a collection of chat messages.

```csharp
protected override Task<AgentResponse> RunCoreAsync(IEnumerable<ChatMessage> messages, AgentSession? session = null, AgentRunOptions? options = null, CancellationToken cancellationToken = default)
```

#### Parameters

`messages` [IEnumerable](https://learn.microsoft.com/dotnet/api/system.collections.generic.ienumerable\-1)<ChatMessage\>

The collection of messages to send to the agent for processing.

`session` AgentSession?

The conversation session to use for this invocation. If [null](https://learn.microsoft.com/dotnet/csharp/language-reference/keywords/null), a new session will be created.
The session will be updated with the input messages and any response messages generated during invocation.

`options` AgentRunOptions?

Optional configuration parameters for controlling the agent's invocation behavior.

`cancellationToken` [CancellationToken](https://learn.microsoft.com/dotnet/api/system.threading.cancellationtoken)

The [CancellationToken](https://learn.microsoft.com/dotnet/api/system.threading.cancellationtoken) to monitor for cancellation requests. The default is [CancellationToken.None](https://learn.microsoft.com/dotnet/api/system.threading.cancellationtoken).

#### Returns

 [Task](https://learn.microsoft.com/dotnet/api/system.threading.tasks.task\-1)<AgentResponse\>

A task that represents the asynchronous operation. The task result contains an `AI.AgentResponse` with the agent's output.

#### Remarks

This is the primary invocation method that implementations must override. It handles collections of messages,
allowing for complex conversational scenarios including multi-turn interactions, function calls, and
context-rich conversations.

The messages are processed in the order provided and become part of the conversation history.
The agent's response will also be added to `session` if one is provided.

### <a id="Tracon_RunRecordingAgent_RunCoreStreamingAsync_System_Collections_Generic_IEnumerable_Microsoft_Extensions_AI_ChatMessage__Microsoft_Agents_AI_AgentSession_Microsoft_Agents_AI_AgentRunOptions_System_Threading_CancellationToken_"></a> RunCoreStreamingAsync\(IEnumerable<ChatMessage\>, AgentSession?, AgentRunOptions?, CancellationToken\)

Core implementation of the agent streaming invocation logic with a collection of chat messages.

```csharp
protected override IAsyncEnumerable<AgentResponseUpdate> RunCoreStreamingAsync(IEnumerable<ChatMessage> messages, AgentSession? session = null, AgentRunOptions? options = null, CancellationToken cancellationToken = default)
```

#### Parameters

`messages` [IEnumerable](https://learn.microsoft.com/dotnet/api/system.collections.generic.ienumerable\-1)<ChatMessage\>

The collection of messages to send to the agent for processing.

`session` AgentSession?

The conversation session to use for this invocation. If [null](https://learn.microsoft.com/dotnet/csharp/language-reference/keywords/null), a new session will be created.
The session will be updated with the input messages and any response updates generated during invocation.

`options` AgentRunOptions?

Optional configuration parameters for controlling the agent's invocation behavior.

`cancellationToken` [CancellationToken](https://learn.microsoft.com/dotnet/api/system.threading.cancellationtoken)

The [CancellationToken](https://learn.microsoft.com/dotnet/api/system.threading.cancellationtoken) to monitor for cancellation requests. The default is [CancellationToken.None](https://learn.microsoft.com/dotnet/api/system.threading.cancellationtoken).

#### Returns

 [IAsyncEnumerable](https://learn.microsoft.com/dotnet/api/system.collections.generic.iasyncenumerable\-1)<AgentResponseUpdate\>

An asynchronous enumerable of `AI.AgentResponseUpdate` instances representing the streaming response.

#### Remarks

This is the primary streaming invocation method that implementations must override. It provides real-time
updates as the agent processes the input and generates its response, enabling more responsive user experiences.

Each `AI.AgentResponseUpdate` represents a portion of the complete response, allowing consumers
to display partial results, implement progressive loading, or provide immediate feedback to users.
