HostedAgentResourceBuilderExtensions Methods
ClassMethods6 members
Extension methods for adding hosted agent applications to the distributed application model.
AsHostedAgent(IResourceBuilder<T>, HostedAgentProtocol, string)Section titled AsHostedAgent(IResourceBuilder<T>, HostedAgentProtocol, string)extensionIResourceBuilder<T> Configures the resource to run and publish as a Microsoft Foundry hosted agent.
public static class HostedAgentResourceBuilderExtensions{ public static IResourceBuilder<T> AsHostedAgent<T>( this IResourceBuilder<T> builder, HostedAgentProtocol protocol, string protocolVersion) { // ... }}Parameters
builderIResourceBuilder<T>The resource builder for the compute resource.protocolHostedAgentProtocolThe protocol exposed by the hosted agent container.protocolVersionstringThe version of the protocol exposed by the hosted agent container.Returns
IResourceBuilder<T>A reference to the ApplicationModel.IResourceBuilder`1 for chaining.Remarks
In run mode, this method configures the resource with the hosted agent protocol endpoint, a dashboard command for sending messages to the agent, and OpenTelemetry environment variables expected by the Microsoft Foundry agent server SDK. In publish mode, it resolves or creates a Microsoft Foundry project and configures the resource to deploy as a hosted agent using the selected protocol version.
Examples
var agent = builder.AddProject<Projects.AgentService>("agent") .AsHostedAgent(HostedAgentProtocol.Responses, "2.0.0");AsHostedAgent(IResourceBuilder<T>)Section titled AsHostedAgent(IResourceBuilder<T>)extensionIResourceBuilder<T> Configures the resource to run and publish as a Microsoft Foundry hosted agent using the Responses protocol version 2.0.0.
public static class HostedAgentResourceBuilderExtensions{ public static IResourceBuilder<T> AsHostedAgent<T>( this IResourceBuilder<T> builder) { // ... }}Parameters
builderIResourceBuilder<T>The resource builder for the compute resource.Returns
IResourceBuilder<T>A reference to the ApplicationModel.IResourceBuilder`1 for chaining.Remarks
This overload is retained for source compatibility. Prefer overloads that pass the Microsoft Foundry project and hosted agent protocol explicitly.
AsHostedAgent(IResourceBuilder<T>, IResourceBuilder<AzureCognitiveServicesProjectResource>, Action<HostedAgentConfiguration>)Section titled AsHostedAgent(IResourceBuilder<T>, IResourceBuilder<AzureCognitiveServicesProjectResource>, Action<HostedAgentConfiguration>)extensionIResourceBuilder<T> Configures the resource to run and publish as a Microsoft Foundry hosted agent using the Responses protocol version 2.0.0.
public static class HostedAgentResourceBuilderExtensions{ public static IResourceBuilder<T> AsHostedAgent<T>( this IResourceBuilder<T> builder, IResourceBuilder<AzureCognitiveServicesProjectResource>? project, Action<HostedAgentConfiguration>? configure = null) { // ... }}Parameters
builderIResourceBuilder<T>The resource builder for the compute resource.projectIResourceBuilder<AzureCognitiveServicesProjectResource>Optional Microsoft Foundry project resource used for both run and publish mode configuration. When null, an existing Foundry project in the model is reused or a new project is created in publish mode.configureAction<HostedAgentConfiguration>optionalA callback to configure hosted agent deployment options.Returns
IResourceBuilder<T>A reference to the ApplicationModel.IResourceBuilder`1 for chaining.Remarks
This C# convenience overload defaults to the Responses protocol version 2.0.0, mirroring the exported
asHostedAgent entry point used by polyglot AppHosts. Polyglot hosts that need a different protocol or version should use the exported asHostedAgentWithProtocol entry point instead. The configuration callback is applied in publish mode. AsHostedAgent(IResourceBuilder<T>, Action<HostedAgentConfiguration>)Section titled AsHostedAgent(IResourceBuilder<T>, Action<HostedAgentConfiguration>)extensionIResourceBuilder<T> Configures the resource to run and publish as a Microsoft Foundry hosted agent using the Responses protocol version 2.0.0.
public static class HostedAgentResourceBuilderExtensions{ public static IResourceBuilder<T> AsHostedAgent<T>( this IResourceBuilder<T> builder, Action<HostedAgentConfiguration> configure) { // ... }}Parameters
builderIResourceBuilder<T>The resource builder for the compute resource.configureAction<HostedAgentConfiguration>A callback to configure hosted agent deployment options.Returns
IResourceBuilder<T>A reference to the ApplicationModel.IResourceBuilder`1 for chaining.Remarks
This overload is retained for source compatibility. Prefer overloads that pass the Microsoft Foundry project and hosted agent protocol explicitly.
AsHostedAgent(IResourceBuilder<T>, IResourceBuilder<AzureCognitiveServicesProjectResource>, HostedAgentProtocol, string, Action<HostedAgentConfiguration>)Section titled AsHostedAgent(IResourceBuilder<T>, IResourceBuilder<AzureCognitiveServicesProjectResource>, HostedAgentProtocol, string, Action<HostedAgentConfiguration>)extensionIResourceBuilder<T> Configures the resource to run and publish as a hosted agent in Microsoft Foundry, with full programmatic access to the underlying
HostedAgentConfiguration (including Azure SDK-specific options such as tools and content filters). public static class HostedAgentResourceBuilderExtensions{ public static IResourceBuilder<T> AsHostedAgent<T>( this IResourceBuilder<T> builder, IResourceBuilder<AzureCognitiveServicesProjectResource>? project, HostedAgentProtocol protocol, string protocolVersion, Action<HostedAgentConfiguration>? configure = null) { // ... }}Parameters
builderIResourceBuilder<T>The resource builder for the compute resource.projectIResourceBuilder<AzureCognitiveServicesProjectResource>Optional Microsoft Foundry project resource used for both run and publish mode configuration. When null, an existing Foundry project in the model is reused or a new project is created in publish mode.protocolHostedAgentProtocolThe protocol exposed by the hosted agent container.protocolVersionstringThe version of the protocol exposed by the hosted agent container.configureAction<HostedAgentConfiguration>optionalA callback to configure hosted agent deployment options.Returns
IResourceBuilder<T>A reference to the ApplicationModel.IResourceBuilder`1 for chaining.Remarks
The
protocol parameter affects both run and publish mode. The protocolVersion parameter is emitted in publish mode. The configuration callback is applied in publish mode. AsHostedAgent(IResourceBuilder<T>, HostedAgentProtocol, string, Action<HostedAgentConfiguration>)Section titled AsHostedAgent(IResourceBuilder<T>, HostedAgentProtocol, string, Action<HostedAgentConfiguration>)extensionIResourceBuilder<T> Configures the resource to run and publish as a hosted agent in Microsoft Foundry, with full programmatic access to the underlying
HostedAgentConfiguration. The Foundry project is resolved automatically in publish mode. public static class HostedAgentResourceBuilderExtensions{ public static IResourceBuilder<T> AsHostedAgent<T>( this IResourceBuilder<T> builder, HostedAgentProtocol protocol, string protocolVersion, Action<HostedAgentConfiguration> configure) { // ... }}Parameters
builderIResourceBuilder<T>The resource builder for the compute resource.protocolHostedAgentProtocolThe protocol exposed by the hosted agent container.protocolVersionstringThe version of the protocol exposed by the hosted agent container.configureAction<HostedAgentConfiguration>A callback to configure hosted agent deployment options.Returns
IResourceBuilder<T>A reference to the ApplicationModel.IResourceBuilder`1 for chaining.