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
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
.WithReference(project)
.WithReference(deployment)
.WaitFor(deployment)
.PublishAsHostedAgent(project, (opts) =>
.WithComputeEnvironment(project, (opts) =>
{
opts.Description = "Foundry Agent Basic Example";
opts.Metadata["managed-by"] = "aspire-foundry";
Expand Down
8 changes: 4 additions & 4 deletions playground/FoundryAgents/FoundryAgents.AppHost/AppHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,16 @@
builder.AddPythonApp("weather-hosted-agent", "../app", "main.py")
.WithUv()
.WithReference(project).WithReference(chat).WaitFor(chat)
.PublishAsHostedAgent(project);
.WithComputeEnvironment(project);

builder.AddProject<Projects.DotNetHostedAgent>("proj-dotnet-hosted-agent")
.WithHttpEndpoint(targetPort: 9000)
.WithReference(project).WithReference(chat).WaitFor(chat)
.PublishAsHostedAgent(project);
.WithComputeEnvironment(project);

// --- Prompt Agents ---

var researchAgent = project.AddPromptAgent(chat, "research-agent",
var researchAgent = project.AddPromptAgent("research-agent", chat,
instructions: """
You are a research assistant. When asked a question:
1. Use Bing grounding to search the web for current information
Expand All @@ -63,7 +63,7 @@ Always cite your sources and be thorough in your analysis.
.WithTool(aiSearchTool)
.WithTool(codeInterpreter);

var jokerAgent = project.AddPromptAgent(chat, "joker-agent",
var jokerAgent = project.AddPromptAgent("joker-agent", chat,
instructions: """
You are a hilarious comedian. Tell jokes, be witty, and make people laugh.
If someone asks you to analyze something, use the code interpreter to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,82 +15,41 @@ namespace Aspire.Hosting;
/// </summary>
public static class HostedAgentResourceBuilderExtensions
{
/// <summary>
/// In both run and publish modes, build, deploy, and run the containerized agent as a hosted agent in Microsoft Foundry.
/// </summary>
/// <remarks>This overload is not available in polyglot app hosts because run-mode hosted agents are not yet implemented.</remarks>
[AspireExportIgnore(Reason = "RunAsHostedAgent is not yet implemented, so AsHostedAgent is not available in polyglot hosts.")]
public static IResourceBuilder<T> AsHostedAgent<T>(
this IResourceBuilder<T> builder, Action<HostedAgentConfiguration>? configure = null)
where T : ExecutableResource
{
return builder.AsHostedAgent(project: null, configure: configure);
}

/// <summary>
/// In both run and publish modes, build, deploy, and run the containerized agent as a hosted agent in Microsoft Foundry.
/// </summary>
/// <remarks>This overload is not available in polyglot app hosts because run-mode hosted agents are not yet implemented.</remarks>
[AspireExportIgnore(Reason = "RunAsHostedAgent is not yet implemented, so AsHostedAgent is not available in polyglot hosts.")]
public static IResourceBuilder<T> AsHostedAgent<T>(
this IResourceBuilder<T> builder, IResourceBuilder<AzureCognitiveServicesProjectResource>? project = null, Action<HostedAgentConfiguration>? configure = null)
where T : ExecutableResource
{
return builder.RunAsHostedAgent(project: project, configure: configure).PublishAsHostedAgent(project: project, configure: configure);
}

/// <summary>
/// In run mode, build, deploy, and run the containerized agent as a hosted agent in Microsoft Foundry.
/// </summary>
/// <remarks>This overload is not available in polyglot app hosts because run-mode hosted agents are not yet implemented.</remarks>
[AspireExportIgnore(Reason = "RunAsHostedAgent is not yet implemented.")]
public static IResourceBuilder<T> RunAsHostedAgent<T>(
this IResourceBuilder<T> builder, Action<HostedAgentConfiguration> configure)
where T : ExecutableResource
{
return builder.RunAsHostedAgent(project: null, configure: configure);
}

/// <summary>
/// In run mode, build, deploy, and run the containerized agent as a hosted agent in Microsoft Foundry.
/// </summary>
/// <remarks>This overload is not available in polyglot app hosts because run-mode hosted agents are not yet implemented.</remarks>
[AspireExportIgnore(Reason = "RunAsHostedAgent is not yet implemented.")]
public static IResourceBuilder<T> RunAsHostedAgent<T>(
this IResourceBuilder<T> builder, IResourceBuilder<AzureCognitiveServicesProjectResource>? project = null, Action<HostedAgentConfiguration>? configure = null)
where T : ExecutableResource
{
// TODO: Implement this. This will require
// 1. Ensuring that ACR is provisioned
// 2. Building and pushing the container image
// 3. Creating an agent version and returning the name/version of the agent for later use.
throw new NotImplementedException("RunAsHostedAgent is not yet implemented.");
}

/// <summary>
/// Publish the containerized agent as a hosted agent in Microsoft Foundry.
/// Configures the resource to run as a hosted agent in Microsoft Foundry.
///
/// If a project resource is not provided, the method will attempt to find an existing
/// Microsoft Foundry project resource in the application model. If none exists,
/// a new project resource (and its parent account resource) will be created automatically.
/// </summary>
Comment thread
tommasodotNET marked this conversation as resolved.
[AspireExportIgnore(Reason = "Subset of the full PublishAsHostedAgent overload which is exported.")]
public static IResourceBuilder<T> PublishAsHostedAgent<T>(
/// <remarks>
/// In run mode, this configures the resource with hosted agent endpoints, health checks,
/// and OpenTelemetry settings. In publish mode, the resource is deployed as a hosted agent
/// in Microsoft Foundry.
/// </remarks>
[AspireExportIgnore(Reason = "Subset of the full WithComputeEnvironment overload which is exported.")]
public static IResourceBuilder<T> WithComputeEnvironment<T>(
this IResourceBuilder<T> builder, Action<HostedAgentConfiguration> configure)
where T : IResourceWithEndpoints, IResourceWithEnvironment, IComputeResource
{
return PublishAsHostedAgent(builder, project: null, configure: configure);
return WithComputeEnvironment(builder, project: null, configure: configure);
}

/// <summary>
/// Publish the containerized agent as a hosted agent in Microsoft Foundry.
/// Configures the resource to run as a hosted agent in Microsoft Foundry.
///
/// If a project resource is not provided, the method will attempt to find an existing
/// Microsoft Foundry project resource in the application model. If none exists,
/// a new project resource (and its parent account resource) will be created automatically.
/// </summary>
[AspireExport("publishAsHostedAgentExecutable", MethodName = "publishAsHostedAgent")]
public static IResourceBuilder<T> PublishAsHostedAgent<T>(
/// <remarks>
/// In run mode, this configures the resource with hosted agent endpoints, health checks,
/// and OpenTelemetry settings. In publish mode, the resource is deployed as a hosted agent
/// in Microsoft Foundry.
/// </remarks>
[AspireExport("withComputeEnvironmentExecutable", MethodName = "withComputeEnvironment")]
public static IResourceBuilder<T> WithComputeEnvironment<T>(
this IResourceBuilder<T> builder, IResourceBuilder<AzureCognitiveServicesProjectResource>? project = null, Action<HostedAgentConfiguration>? configure = null)
where T : IResourceWithEndpoints, IResourceWithEnvironment, IComputeResource
{
Comment thread
tommasodotNET marked this conversation as resolved.
Expand Down Expand Up @@ -262,7 +221,7 @@ await interactionService.PromptMessageBoxAsync(
}
}

builder.WithComputeEnvironment(project);
ResourceBuilderExtensions.WithComputeEnvironment(builder, project!);

// Hosted Agent resource name
var agentName = $"{resource.Name}-ha";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public static class AzureCognitiveServicesProjectConnectionsBuilderExtensions
[AspireExportIgnore(Reason = "The configureProperties callback returns Azure provisioning types that are not ATS-compatible.")]
public static IResourceBuilder<AzureCognitiveServicesProjectConnectionResource> AddConnection(
this IResourceBuilder<AzureCognitiveServicesProjectResource> builder,
string name,
[ResourceName] string name,
Func<AzureResourceInfrastructure, CognitiveServicesConnectionProperties> configureProperties)
{
ArgumentNullException.ThrowIfNull(builder);
Expand Down Expand Up @@ -332,7 +332,7 @@ internal static IResourceBuilder<AzureCognitiveServicesProjectConnectionResource
[AspireExport]
public static IResourceBuilder<BingGroundingConnectionResource> AddBingGroundingConnection(
this IResourceBuilder<AzureCognitiveServicesProjectResource> builder,
string name,
[ResourceName] string name,
string bingResourceId)
{
ArgumentNullException.ThrowIfNull(builder);
Expand Down Expand Up @@ -386,7 +386,7 @@ public static IResourceBuilder<BingGroundingConnectionResource> AddBingGrounding
[AspireExport("addBingGroundingConnectionFromParameter")]
public static IResourceBuilder<BingGroundingConnectionResource> AddBingGroundingConnection(
this IResourceBuilder<AzureCognitiveServicesProjectResource> builder,
string name,
[ResourceName] string name,
IResourceBuilder<ParameterResource> bingResourceId)
{
ArgumentNullException.ThrowIfNull(builder);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public static class AzureCognitiveServicesProjectExtensions
[AspireExport]
public static IResourceBuilder<AzureCognitiveServicesProjectResource> AddProject(
this IResourceBuilder<FoundryResource> builder,
string name)
[ResourceName] string name)
{
ArgumentNullException.ThrowIfNull(builder);
ArgumentException.ThrowIfNullOrEmpty(name);
Expand Down Expand Up @@ -138,7 +138,7 @@ public static IResourceBuilder<AzureCognitiveServicesProjectResource> WithAppIns
[AspireExportIgnore(Reason = "CapabilityHostBuilder is not ATS-compatible.")]
public static CapabilityHostBuilder AddCapabilityHost(
this IResourceBuilder<AzureCognitiveServicesProjectResource> builder,
string name)
[ResourceName] string name)
{
ArgumentNullException.ThrowIfNull(builder);
ArgumentException.ThrowIfNullOrEmpty(name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ public static class PromptAgentBuilderExtensions
/// </remarks>
/// <param name="project">The <see cref="IResourceBuilder{T}"/> for the parent Microsoft Foundry project resource.</param>
/// <ats-param name="project">The Microsoft Foundry project resource builder.</ats-param>
/// <param name="model">The model deployment to use for this agent.</param>
/// <param name="name">The name of the prompt agent. This will be the agent name in Foundry.</param>
/// <param name="model">The model deployment to use for this agent.</param>
/// <param name="instructions">Optional system instructions for the agent.</param>
/// <returns>A reference to the <see cref="IResourceBuilder{T}"/> for the prompt agent resource.</returns>
/// <ats-returns>The resource builder.</ats-returns>
Expand All @@ -49,7 +49,7 @@ public static class PromptAgentBuilderExtensions
/// var aiSearch = project.AddAISearchTool("search").WithReference(searchResource);
/// var codeInterp = project.AddCodeInterpreterTool("code-interp");
///
/// project.AddPromptAgent(chat, "joker-agent",
/// project.AddPromptAgent("joker-agent", chat,
/// instructions: "You are good at telling jokes.")
/// .WithTool(bing)
/// .WithTool(aiSearch)
Expand All @@ -59,8 +59,8 @@ public static class PromptAgentBuilderExtensions
[AspireExport]
public static IResourceBuilder<AzurePromptAgentResource> AddPromptAgent(
this IResourceBuilder<AzureCognitiveServicesProjectResource> project,
[ResourceName] string name,
IResourceBuilder<FoundryDeploymentResource> model,
string name,
string? instructions = null)
{
ArgumentNullException.ThrowIfNull(project);
Expand Down Expand Up @@ -164,7 +164,7 @@ public static IResourceBuilder<AzurePromptAgentResource> WithTool(
[AspireExport]
public static IResourceBuilder<CodeInterpreterToolResource> AddCodeInterpreterTool(
this IResourceBuilder<AzureCognitiveServicesProjectResource> project,
string name)
[ResourceName] string name)
{
ArgumentNullException.ThrowIfNull(project);
ArgumentException.ThrowIfNullOrEmpty(name);
Expand All @@ -187,7 +187,7 @@ public static IResourceBuilder<CodeInterpreterToolResource> AddCodeInterpreterTo
[AspireExport]
public static IResourceBuilder<FileSearchToolResource> AddFileSearchTool(
this IResourceBuilder<AzureCognitiveServicesProjectResource> project,
string name,
[ResourceName] string name,
params string[] vectorStoreIds)
{
ArgumentNullException.ThrowIfNull(project);
Expand All @@ -213,7 +213,7 @@ public static IResourceBuilder<FileSearchToolResource> AddFileSearchTool(
[AspireExport]
public static IResourceBuilder<WebSearchToolResource> AddWebSearchTool(
this IResourceBuilder<AzureCognitiveServicesProjectResource> project,
string name)
[ResourceName] string name)
{
ArgumentNullException.ThrowIfNull(project);
ArgumentException.ThrowIfNullOrEmpty(name);
Expand All @@ -235,7 +235,7 @@ public static IResourceBuilder<WebSearchToolResource> AddWebSearchTool(
[AspireExport]
public static IResourceBuilder<ImageGenerationToolResource> AddImageGenerationTool(
this IResourceBuilder<AzureCognitiveServicesProjectResource> project,
string name)
[ResourceName] string name)
{
ArgumentNullException.ThrowIfNull(project);
ArgumentException.ThrowIfNullOrEmpty(name);
Expand All @@ -260,7 +260,7 @@ public static IResourceBuilder<ImageGenerationToolResource> AddImageGenerationTo
[AspireExport]
public static IResourceBuilder<ComputerToolResource> AddComputerUseTool(
this IResourceBuilder<AzureCognitiveServicesProjectResource> project,
string name,
[ResourceName] string name,
int displayWidth = 1024,
int displayHeight = 768,
string environment = "browser")
Expand Down Expand Up @@ -295,7 +295,7 @@ public static IResourceBuilder<ComputerToolResource> AddComputerUseTool(
[AspireExport]
public static IResourceBuilder<AzureAISearchToolResource> AddAISearchTool(
this IResourceBuilder<AzureCognitiveServicesProjectResource> project,
string name,
[ResourceName] string name,
string? indexName = null)
{
ArgumentNullException.ThrowIfNull(project);
Expand Down Expand Up @@ -359,7 +359,7 @@ public static IResourceBuilder<AzureAISearchToolResource> WithReference(
[AspireExport]
public static IResourceBuilder<BingGroundingToolResource> AddBingGroundingTool(
this IResourceBuilder<AzureCognitiveServicesProjectResource> project,
string name)
[ResourceName] string name)
{
ArgumentNullException.ThrowIfNull(project);
ArgumentException.ThrowIfNullOrEmpty(name);
Expand Down Expand Up @@ -489,7 +489,7 @@ internal static IResourceBuilder<BingGroundingToolResource> WithReference(
[AspireExport]
public static IResourceBuilder<SharePointToolResource> AddSharePointTool(
this IResourceBuilder<AzureCognitiveServicesProjectResource> project,
string name,
[ResourceName] string name,
params string[] projectConnectionIds)
{
ArgumentNullException.ThrowIfNull(project);
Expand All @@ -513,7 +513,7 @@ public static IResourceBuilder<SharePointToolResource> AddSharePointTool(
[AspireExport]
public static IResourceBuilder<FabricToolResource> AddFabricTool(
this IResourceBuilder<AzureCognitiveServicesProjectResource> project,
string name,
[ResourceName] string name,
params string[] projectConnectionIds)
{
ArgumentNullException.ThrowIfNull(project);
Expand Down Expand Up @@ -545,7 +545,7 @@ public static IResourceBuilder<FabricToolResource> AddFabricTool(
[AspireExportIgnore(Reason = "BinaryData parameter is not ATS-compatible. Use the string overload instead.")]
public static IResourceBuilder<AzureFunctionToolResource> AddAzureFunctionTool(
this IResourceBuilder<AzureCognitiveServicesProjectResource> project,
string name,
[ResourceName] string name,
string functionName,
string description,
BinaryData parameters,
Expand Down Expand Up @@ -583,7 +583,7 @@ public static IResourceBuilder<AzureFunctionToolResource> AddAzureFunctionTool(
[AspireExport]
public static IResourceBuilder<AzureFunctionToolResource> AddAzureFunctionTool(
this IResourceBuilder<AzureCognitiveServicesProjectResource> project,
string name,
[ResourceName] string name,
string functionName,
string description,
string parametersJson,
Expand Down Expand Up @@ -611,7 +611,7 @@ public static IResourceBuilder<AzureFunctionToolResource> AddAzureFunctionTool(
[AspireExportIgnore(Reason = "BinaryData parameter is not ATS-compatible. Use the string overload instead.")]
public static IResourceBuilder<FunctionToolResource> AddFunctionTool(
this IResourceBuilder<AzureCognitiveServicesProjectResource> project,
string name,
[ResourceName] string name,
string functionName,
BinaryData parameters,
string? description = null,
Expand Down Expand Up @@ -642,7 +642,7 @@ public static IResourceBuilder<FunctionToolResource> AddFunctionTool(
[AspireExport]
internal static IResourceBuilder<FunctionToolResource> AddFunctionTool(
this IResourceBuilder<AzureCognitiveServicesProjectResource> project,
string name,
[ResourceName] string name,
string functionName,
string parametersJson,
string? description = null,
Expand Down
2 changes: 1 addition & 1 deletion src/Aspire.Hosting.Foundry/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ var foundry = builder.AddFoundry("foundry");
var project = foundry.AddProject("my-project");

builder.AddPythonApp("agent", "./app", "main:app")
.PublishAsHostedAgent(project);
.WithComputeEnvironment(project);
```

In run mode, the agent runs locally with health check endpoints and OpenTelemetry instrumentation. In publish mode, the agent is deployed as a hosted agent in Microsoft Foundry.
Expand Down
Loading
Loading