microsoft / microsoft/aspire

Add ability for AsHostedAgent() to use a deployed agent instead of running locally

Open
#17,643 3 comments 0 reactions 0 assignees View on GitHub
area-integrations foundry triage:bot-seen
Dominant language
C#
Stars
6.3k
Forks
991
Avg merge
2d 15h
Merged PRs (30d)
196

Description

### Is there an existing issue for this?

- [x] I have searched the existing issues

### Is your feature request related to a problem? Please describe the problem.

_No response_

### Describe the solution you'd like

## Problem

`AsHostedAgent(...)` currently provides strong local-dev behavior by default, but there is no clean first-class mode for “use an already deployed hosted agent” without local run/provision behavior.

## Why this is a valid use case

- Teams could have pre-provisioned/shared Foundry agents.
- Local app development sometimes needs to target an existing deployed agent for parity.

## Important design requirement

For existing-agent mode, binding should be based on:

- **Agent name**
- **Existing Foundry project reference**

OR Raw endpoint URL.

The project reference should be the preferred source of endpoint/context, while agent identity is the agent name.

## Desired behavior

Allow `AsHostedAgent` to explicitly use an existing deployed agent in the referenced project, treating it as external and avoiding local run for that agent.

## Some API shape options

1. `AsHostedAgent(project).RunAsExisting(existingIdentifier)`
- **Pros:** aligns with existing `RunAs*` family.
- **Cons:** broad/ambiguous semantics for this scenario; RunAsExisting currently only exists for resources that are provisioned by default at dev time (and to run locally require something like RunAsEmulator or RunAsContaianer).

2. `AsHostedAgent(project).RunAsExistingHostedAgent(agentName)`
- **Pros:** explicit intent, clear semantics, best readability for this resource type.
- **Cons:** introduces a resource-specific API surface.

3. `AsHostedAgent(project, existingEndpoint: endpoint)`
- **Pros:** concise.
- **Cons:** not preferred; bypasses project context and encourages endpoint-centric configuration.

4. `AsHostedAgent(project, options => options.ExistingAgentName = "agent-name")`
- **Pros:** extensible for future knobs while staying project+name based.
- **Cons:** heavier syntax.

### Additional context

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.