FoundryAgentProvider
NexusLabs.Foundry.MicrosoftAgentFramework.Workflows.Declarative¶
FoundryAgentProvider Class¶
Resolves the agents a declarative workflow names against Foundry's declared agents, and holds the conversation state the runtime records against.
public sealed class FoundryAgentProvider : Microsoft.Agents.AI.Workflows.Declarative.ResponseAgentProvider
Inheritance System.Object 🡒 Microsoft.Agents.AI.Workflows.Declarative.ResponseAgentProvider 🡒 FoundryAgentProvider
Remarks¶
Upstream's provider resolves agent names against a remote Azure AI Foundry project and requires
agents to be deployed there. A declarative InvokeAzureAgent action actually resolves
through Microsoft.Agents.AI.Workflows.Declarative.ResponseAgentProvider.InvokeAgentAsync(System.String,System.String,System.String,System.Collections.Generic.IEnumerable{Microsoft.Extensions.AI.ChatMessage},System.Collections.Generic.IDictionary{System.String,System.Object},System.Threading.CancellationToken) regardless of where the agent lives,
so this provider resolves names through NexusLabs.Foundry.MicrosoftAgentFramework.IAgentFactory instead — the same
[FoundryAgent] declarations and source-generated registration the rest of Foundry uses.
A workflow document therefore names an agent by its published name, exactly as
NexusLabs.Foundry.MicrosoftAgentFramework.IAgentFactory.CreateAgent(System.String) already expects.
Conversation storage exists because the runtime writes to it, not because this provider reads it: the runtime records both the user and the assistant turn through CreateMessageAsync(string, ChatMessage, CancellationToken) and invokes agents with the messages the document's input expression resolved to. Message identity and chronological order still have to be correct, because the runtime addresses stored messages by id and pages over them.
State is held in memory for the lifetime of this instance. A host needing conversations to outlive the process should derive from Microsoft.Agents.AI.Workflows.Declarative.ResponseAgentProvider directly rather than layering persistence onto this type.
Constructors¶
FoundryAgentProvider(IAgentFactory) Constructor¶
Parameters¶
agentFactory NexusLabs.Foundry.MicrosoftAgentFramework.IAgentFactory
Exceptions¶
System.ArgumentNullException
agentFactory is null.
Properties¶
FoundryAgentProvider.ConversationIds Property¶
Gets the identifiers of every conversation this provider has created.
Property Value¶
System.Collections.Generic.IReadOnlyCollection<System.String>
Methods¶
FoundryAgentProvider.CreateConversationAsync(CancellationToken) Method¶
Asynchronously creates a new conversation and returns its unique identifier.
public override System.Threading.Tasks.Task<string> CreateConversationAsync(System.Threading.CancellationToken cancellationToken);
Parameters¶
cancellationToken System.Threading.CancellationToken
The System.Threading.CancellationToken to monitor for cancellation requests. The default is System.Threading.CancellationToken.None.
Returns¶
System.Threading.Tasks.Task<System.String>
The conversation identifier
FoundryAgentProvider.CreateMessageAsync(string, ChatMessage, CancellationToken) Method¶
Creates a new message in the specified conversation.
public override System.Threading.Tasks.Task<Microsoft.Extensions.AI.ChatMessage> CreateMessageAsync(string conversationId, Microsoft.Extensions.AI.ChatMessage message, System.Threading.CancellationToken cancellationToken);
Parameters¶
conversationId System.String
The identifier of the target conversation.
message Microsoft.Extensions.AI.ChatMessage
cancellationToken System.Threading.CancellationToken
The System.Threading.CancellationToken to monitor for cancellation requests. The default is System.Threading.CancellationToken.None.
Returns¶
System.Threading.Tasks.Task<Microsoft.Extensions.AI.ChatMessage>
FoundryAgentProvider.GetMessageAsync(string, string, CancellationToken) Method¶
Retrieves a specific message from a conversation.
public override System.Threading.Tasks.Task<Microsoft.Extensions.AI.ChatMessage> GetMessageAsync(string conversationId, string messageId, System.Threading.CancellationToken cancellationToken);
Parameters¶
conversationId System.String
The identifier of the target conversation.
messageId System.String
The identifier of the target message.
cancellationToken System.Threading.CancellationToken
The System.Threading.CancellationToken to monitor for cancellation requests. The default is System.Threading.CancellationToken.None.
Returns¶
System.Threading.Tasks.Task<Microsoft.Extensions.AI.ChatMessage>
The requested message
FoundryAgentProvider.GetMessagesAsync(string, Nullable<int>, string, string, bool, CancellationToken) Method¶
Retrieves a set of messages from a conversation.
public override System.Collections.Generic.IAsyncEnumerable<Microsoft.Extensions.AI.ChatMessage> GetMessagesAsync(string conversationId, System.Nullable<int> limit, string? after, string? before, bool newestFirst, System.Threading.CancellationToken cancellationToken);
Parameters¶
conversationId System.String
The identifier of the target conversation.
limit System.Nullable<System.Int32>
A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20.
after System.String
A cursor for use in pagination. after is an object ID that defines your place in the list.
before System.String
A cursor for use in pagination. before is an object ID that defines your place in the list.
newestFirst System.Boolean
Provide records in descending order when true.
cancellationToken System.Threading.CancellationToken
The System.Threading.CancellationToken to monitor for cancellation requests. The default is System.Threading.CancellationToken.None.
Returns¶
System.Collections.Generic.IAsyncEnumerable<Microsoft.Extensions.AI.ChatMessage>
The requested messages
FoundryAgentProvider.InvokeAgentAsync(string, string, string, IEnumerable<ChatMessage>, IDictionary<string,object>, CancellationToken) Method¶
Asynchronously retrieves an AI agent by its unique identifier.
public override System.Collections.Generic.IAsyncEnumerable<Microsoft.Agents.AI.AgentResponseUpdate> InvokeAgentAsync(string agentName, string? conversationId, string? additionalInstructions, System.Collections.Generic.IEnumerable<Microsoft.Extensions.AI.ChatMessage>? messages, System.Collections.Generic.IDictionary<string,object?>? arguments, System.Threading.CancellationToken cancellationToken);
Parameters¶
agentName System.String
conversationId System.String
Optional identifier of the target conversation.
additionalInstructions System.String
messages System.Collections.Generic.IEnumerable<Microsoft.Extensions.AI.ChatMessage>
The messages to include in the invocation.
arguments System.Collections.Generic.IDictionary<System.String,System.Object>
cancellationToken System.Threading.CancellationToken
A token that propagates notification when operation should be canceled.
Returns¶
System.Collections.Generic.IAsyncEnumerable<Microsoft.Agents.AI.AgentResponseUpdate>
Asynchronous set of Microsoft.Agents.AI.AgentResponseUpdate.