FoundryAgent Class
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Provides an AIAgent that uses Microsoft Foundry for AI agent capabilities.
public sealed class FoundryAgent : Microsoft.Agents.AI.DelegatingAIAgent
type FoundryAgent = class
inherit DelegatingAIAgent
Public NotInheritable Class FoundryAgent
Inherits DelegatingAIAgent
- Inheritance
Remarks
FoundryAgent connects to a pre-configured server-side agent in Microsoft Foundry, wrapping it as an AIAgent for use with Agent Framework. Unlike the direct AIProjectClient.AsAIAgent(model, instructions) approach (which creates a local agent backed by the Responses API without any server-side agent definition), FoundryAgent works with agents that are managed and versioned in the Foundry service.
This class provides convenient access to Foundry-specific features such as server-side conversation management via CreateConversationSessionAsync(CancellationToken).
Instances can be created directly via public constructors or through AsAIAgent extension methods on AIProjectClient.
Constructors
| Name | Description |
|---|---|
| FoundryAgent(Uri, AuthenticationTokenProvider, AIProjectClientOptions, IList<AITool>, Func<IChatClient,IChatClient>, IServiceProvider) |
Initializes a new instance of the FoundryAgent class from an agent-specific endpoint. |
| FoundryAgent(Uri, AuthenticationTokenProvider, String, String, AIProjectClientOptions, String, String, IList<AITool>, Func<IChatClient, IChatClient>, ILoggerFactory, IServiceProvider) |
Initializes a new instance of the FoundryAgent class using the direct Responses API path. |
Properties
| Name | Description |
|---|---|
| Description |
Gets a description of the agent's purpose, capabilities, or behavior. (Inherited from DelegatingAIAgent) |
| Id |
Gets the unique identifier for this agent instance. (Inherited from AIAgent) |
| IdCore |
Gets a custom identifier for the agent, which can be overridden by derived classes. (Inherited from DelegatingAIAgent) |
| InnerAgent |
Gets the inner agent instance that receives delegated operations. (Inherited from DelegatingAIAgent) |
| Name |
Gets the human-readable name of the agent. (Inherited from DelegatingAIAgent) |
Methods
| Name | Description |
|---|---|
| CreateConversationSessionAsync(CancellationToken) |
Creates a server-side conversation session that appears in the Foundry Project UI. |
| CreateSessionAsync(CancellationToken) |
Creates a new conversation session that is compatible with this agent. (Inherited from AIAgent) |
| CreateSessionCoreAsync(CancellationToken) |
Core implementation of session creation logic. (Inherited from DelegatingAIAgent) |
| DeserializeSessionAsync(JsonElement, JsonSerializerOptions, CancellationToken) |
Deserializes an agent session from its JSON serialized representation. (Inherited from AIAgent) |
| DeserializeSessionCoreAsync(JsonElement, JsonSerializerOptions, CancellationToken) |
Core implementation of session deserialization logic. (Inherited from DelegatingAIAgent) |
| GetService(Type, Object) |
Asks the AIAgent for an object of the specified type |
| GetService<TService>(Object) |
Asks the AIAgent for an object of type |
| RunAsync(AgentSession, AgentRunOptions, CancellationToken) |
Run the agent with no message assuming that all required instructions are already provided to the agent or on the session. (Inherited from AIAgent) |
| RunAsync(ChatMessage, AgentSession, AgentRunOptions, CancellationToken) |
Runs the agent with a single chat message. (Inherited from AIAgent) |
| RunAsync(IEnumerable<ChatMessage>, AgentSession, AgentRunOptions, CancellationToken) |
Runs the agent with a collection of chat messages, providing the core invocation logic that all other overloads delegate to. (Inherited from AIAgent) |
| RunAsync(String, AgentSession, AgentRunOptions, CancellationToken) |
Runs the agent with a text message from the user. (Inherited from AIAgent) |
| RunAsync<T>(AgentSession, JsonSerializerOptions, AgentRunOptions, CancellationToken) |
Run the agent with no message assuming that all required instructions are already provided to the agent or on the session, and requesting a response of the specified type |
| RunAsync<T>(ChatMessage, AgentSession, JsonSerializerOptions, AgentRunOptions, CancellationToken) |
Runs the agent with a single chat message, requesting a response of the specified type |
| RunAsync<T>(IEnumerable<ChatMessage>, AgentSession, JsonSerializerOptions, AgentRunOptions, CancellationToken) |
Runs the agent with a collection of chat messages, requesting a response of the specified type |
| RunAsync<T>(String, AgentSession, JsonSerializerOptions, AgentRunOptions, CancellationToken) |
Runs the agent with a text message from the user, requesting a response of the specified type |
| RunCoreAsync(IEnumerable<ChatMessage>, AgentSession, AgentRunOptions, CancellationToken) |
Core implementation of the agent invocation logic with a collection of chat messages. (Inherited from DelegatingAIAgent) |
| RunCoreStreamingAsync(IEnumerable<ChatMessage>, AgentSession, AgentRunOptions, CancellationToken) |
Core implementation of the agent streaming invocation logic with a collection of chat messages. (Inherited from DelegatingAIAgent) |
| RunStreamingAsync(AgentSession, AgentRunOptions, CancellationToken) |
Runs the agent in streaming mode without providing new input messages, relying on existing context and instructions. (Inherited from AIAgent) |
| RunStreamingAsync(ChatMessage, AgentSession, AgentRunOptions, CancellationToken) |
Runs the agent in streaming mode with a single chat message. (Inherited from AIAgent) |
| RunStreamingAsync(IEnumerable<ChatMessage>, AgentSession, AgentRunOptions, CancellationToken) |
Runs the agent in streaming mode with a collection of chat messages, providing the core streaming invocation logic. (Inherited from AIAgent) |
| RunStreamingAsync(String, AgentSession, AgentRunOptions, CancellationToken) |
Runs the agent in streaming mode with a text message from the user. (Inherited from AIAgent) |
| SerializeSessionAsync(AgentSession, JsonSerializerOptions, CancellationToken) |
Serializes an agent session to its JSON representation. (Inherited from AIAgent) |
| SerializeSessionCoreAsync(AgentSession, JsonSerializerOptions, CancellationToken) |
Core implementation of session serialization logic. (Inherited from DelegatingAIAgent) |