Update foundry hosting samples

This commit is contained in:
Tao Chen
2026-04-24 11:48:17 -07:00
parent 0b69d7fd15
commit 334ce4dfe0
55 changed files with 653 additions and 259 deletions
@@ -1,2 +1,2 @@
FOUNDRY_PROJECT_ENDPOINT="..."
MODEL_DEPLOYMENT_NAME="..."
AZURE_AI_MODEL_DEPLOYMENT_NAME="..."
@@ -1,31 +1,39 @@
# Basic example of hosting an agent with the `responses` API
# What this sample demonstrates
This agent only contains an instruction (personal). It's the most basic agent with an LLM and no tools.
An [Agent Framework](https://github.com/microsoft/agent-framework) agent hosted using the **Responses protocol**.
## Running the server locally
## How It Works
### Environment setup
### Model Integration
Follow the instructions in the [Environment setup](../../README.md#environment-setup) section of the README in the parent directory to set up your environment and install dependencies.
The agent uses `FoundryChatClient` from the Agent Framework to create a Responses client from the project endpoint and model deployment. The agent supports both streaming (SSE events) and non-streaming (JSON) response modes.
Run the following command to start the server:
See [main.py](main.py) for the full implementation.
```bash
python main.py
```
### Agent Hosting
The agent is hosted using the [Agent Framework](https://github.com/microsoft/agent-framework) with the `ResponsesHostServer`, which provisions a REST API endpoint compatible with the OpenAI Responses protocol.
## Interacting with the agent
Send a POST request to the server with a JSON body containing a "input" field to interact with the agent. For example:
> Depending on how you run the agent host, you can invoke the agent using `curl` (`Invoke-WebRequest` in PowerShell) or `azd`. Please refer to the [parent README](../../README.md) for more details. Use this README for sample queries you can send to the agent.
Send a POST request to the server with a JSON body containing a "message" field to interact with the agent. For example:
```bash
curl -X POST http://localhost:8088/responses -H "Content-Type: application/json" -d '{"input": "Hi"}'
```
## Multi-turn conversation
The server will respond with a JSON object containing the response text and a response ID. You can use this response ID to continue the conversation in subsequent requests.
### Multi-turn conversation
To have a multi-turn conversation with the agent, include the previous response id in the request body. For example:
```bash
curl -X POST http://localhost:8088/responses -H "Content-Type: application/json" -d '{"input": "How are you?", "previous_response_id": "REPLACE_WITH_PREVIOUS_RESPONSE_ID"}'
```
## Deploying the Agent to Foundry
To host the agent on Foundry, follow the instructions in the [Deploying the Agent to Foundry](../../README.md#deploying-the-agent-to-foundry) section of the README in the parent directory.
@@ -1,4 +1,4 @@
name: agent-framework-agent-basic
name: agent-framework-agent-basic-responses
description: >
A basic Agent Framework agent hosted by Foundry.
metadata:
@@ -9,15 +9,15 @@ metadata:
- Responses Protocol
- Streaming
template:
name: agent-framework-agent-basic
name: agent-framework-agent-basic-responses
kind: hosted
protocols:
- protocol: responses
version: 1.0.0
environment_variables:
- name: MODEL_DEPLOYMENT_NAME
value: "{{MODEL_DEPLOYMENT_NAME}}"
- name: AZURE_AI_MODEL_DEPLOYMENT_NAME
value: "{{AZURE_AI_MODEL_DEPLOYMENT_NAME}}"
resources:
- kind: model
id: gpt-4.1-mini
name: MODEL_DEPLOYMENT_NAME
name: AZURE_AI_MODEL_DEPLOYMENT_NAME
@@ -1,8 +1,9 @@
# yaml-language-server: $schema=https://raw.githubusercontent.com/microsoft/AgentSchema/refs/heads/main/schemas/v1.0/ContainerAgent.yaml
kind: hosted
name: agent-framework-agent-basic
name: agent-framework-agent-basic-responses
protocols:
- protocol: responses
version: 1.0.0
resources:
cpu: "0.25"
memory: 0.5Gi
cpu: '0.25'
memory: '0.5Gi'
@@ -5,7 +5,7 @@ import os
from agent_framework import Agent
from agent_framework.foundry import FoundryChatClient
from agent_framework_foundry_hosting import ResponsesHostServer
from azure.identity import AzureCliCredential
from azure.identity import DefaultAzureCredential
from dotenv import load_dotenv
# Load environment variables from .env file
@@ -15,8 +15,8 @@ load_dotenv()
def main():
client = FoundryChatClient(
project_endpoint=os.environ["FOUNDRY_PROJECT_ENDPOINT"],
model=os.environ["MODEL_DEPLOYMENT_NAME"],
credential=AzureCliCredential(),
model=os.environ["AZURE_AI_MODEL_DEPLOYMENT_NAME"],
credential=DefaultAzureCredential(),
)
agent = Agent(