Improve samples

This commit is contained in:
Tao Chen
2026-04-20 16:29:53 -07:00
parent 0fcd71dbeb
commit 3fb7a03e05
27 changed files with 392 additions and 113 deletions
@@ -2,6 +2,18 @@
This agent only contains an instruction (personal). It's the most basic agent with an LLM and no tools.
## Running the server locally
### Environment setup
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.
Run the following command to start the server:
```bash
python main.py
```
## Interacting with the agent
Send a POST request to the server with a JSON body containing a "message" field to interact with the agent. For example:
@@ -10,12 +22,6 @@ Send a POST request to the server with a JSON body containing a "message" field
curl -X POST http://localhost:8088/responses -H "Content-Type: application/json" -d '{"input": "Hi"}'
```
### Invoke with `azd`
```bash
azd ai agent invoke --local "Hi"
```
## Multi-turn conversation
To have a multi-turn conversation with the agent, include the previous response id in the request body. For example:
@@ -23,11 +29,3 @@ To have a multi-turn conversation with the agent, include the previous response
```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"}'
```
Invoke with `azd`:
```bash
azd ai agent invoke --local "Hi!" --conversation-id "my_conv"
azd ai agent invoke --local "How are you?" --conversation-id "my_conv"
```
@@ -4,6 +4,18 @@ This agent is equipped with with a function tool and a local shell tool.
> We recommend deploying this sample on a local container or to Foundry Hosting because the agent has access to a local shell tool, which can run arbitrary commands on the machine.
## Running the server locally
### Environment setup
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.
Run the following command to start the server:
```bash
python main.py
```
## Interacting with the agent
Send a POST request to the server with a JSON body containing a "message" field to interact with the agent. For example:
@@ -13,11 +25,3 @@ curl -X POST http://localhost:8088/responses -H "Content-Type: application/json"
curl -X POST http://localhost:8088/responses -H "Content-Type: application/json" -d '{"input": "List the files in the current directory."}'
```
Invoke with `azd`:
```bash
azd ai agent invoke --local "What is the weather in Seattle?"
azd ai agent invoke --local "List the files in the current directory."
```
@@ -1,4 +1,4 @@
FOUNDRY_PROJECT_ENDPOINT="..."
MODEL_DEPLOYMENT_NAME="..."
FOUNDRY_AGENT_TOOLBOX_NAME="..."
TOOLBOX_NAME="..."
GITHUB_PAT="..."
@@ -4,6 +4,18 @@ This agent is equipped with a GitHub MCP server and a Foundry Toolbox, which are
> Note that there are other ways to interact with Foundry toolboxes. Using it as a MCP is just one of the options.
## Running the server locally
### Environment setup
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.
Run the following command to start the server:
```bash
python main.py
```
## Interacting with the agent
Send a POST request to the server with a JSON body containing a "message" field to interact with the agent. For example:
@@ -11,9 +23,3 @@ Send a POST request to the server with a JSON body containing a "message" field
```bash
curl -X POST http://localhost:8088/responses -H "Content-Type: application/json" -d '{"input": "List all the repositories I own on GitHub."}'
```
Invoke with `azd`:
```bash
azd ai agent invoke --local "List all the repositories I own on GitHub."
```
@@ -32,7 +32,7 @@ def main():
# Foundry Toolbox as a MCP tool
project_endpoint = os.environ["FOUNDRY_PROJECT_ENDPOINT"]
toolbox_name = os.environ["FOUNDRY_AGENT_TOOLBOX_NAME"]
toolbox_name = os.environ["TOOLBOX_NAME"]
toolbox_endpoint = f"{project_endpoint.rstrip('/')}/toolboxes/{toolbox_name}/mcp?api-version=v1"
http_client = httpx.AsyncClient(auth=ToolboxAuth(), headers={"Foundry-Features": "Toolboxes=V1Preview"})
foundry_mcp_tool = MCPStreamableHTTPTool(
@@ -2,6 +2,18 @@
This sample demonstrates how to host a workflow using the `responses` API.
## Running the server locally
### Environment setup
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.
Run the following command to start the server:
```bash
python main.py
```
## Interacting with the agent
Send a POST request to the server with a JSON body containing a "message" field to interact with the agent. For example:
@@ -9,9 +21,3 @@ Send a POST request to the server with a JSON body containing a "message" field
```bash
curl -X POST http://localhost:8088/responses -H "Content-Type: application/json" -d '{"input": "Create a slogan for a new electric SUV that is affordable and fun to drive."}'
```
Invoke with `azd`:
```bash
azd ai agent invoke --local "Create a slogan for a new electric SUV that is affordable and fun to drive."
```
@@ -4,7 +4,6 @@ import os
from agent_framework import Agent, AgentExecutor, WorkflowBuilder
from agent_framework.foundry import FoundryChatClient
from agent_framework.orchestrations import GroupChatState
from agent_framework_foundry_hosting import ResponsesHostServer
from azure.identity import AzureCliCredential
from dotenv import load_dotenv
@@ -13,13 +12,6 @@ from dotenv import load_dotenv
load_dotenv()
def round_robin_selector(state: GroupChatState) -> str:
"""A round-robin selector function that picks the next speaker based on the current round index."""
participant_names = list(state.participants.keys())
return participant_names[state.current_round % len(participant_names)]
def main():
client = FoundryChatClient(
project_endpoint=os.environ["FOUNDRY_PROJECT_ENDPOINT"],
@@ -8,58 +8,4 @@ This folder contains a list of samples that show how to host agents using the `r
| [02_local_tools](./02_local_tools) | An example of hosting an agent with the `responses` API and local tools including a function tool and a local shell tool. |
| [03_remote_mcp](./03_remote_mcp) | An example of hosting an agent with the `responses` API and remote MCPs, including a GitHub MCP server and a Foundry Toolboox. |
| [04_workflows](./04_workflows) | An example of hosting a workflow with the `responses` API. |
## Running the server locally
Navigate to the sample directory and run the following command to start the server:
```bash
python main.py
```
## Interacting with the agent
There two ways to interact with the agent: sending HTTP requests to the server or using the `azd` CLI:
### Invoke with `azd`
```bash
azd ai agent invoke --local "Hi"
```
### Sending HTTP requests
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"}'
```
> See the individual samples for more examples of interacting with the agent.
## Deploying to a Docker container
Navigate to the sample directory and build the Docker image:
```bash
docker build -t hosted-agent-sample .
```
Run the container, passing in the required environment variables:
```bash
docker run -p 8088:8088 \
-e FOUNDRY_PROJECT_ENDPOINT=<your-endpoint> \
-e FOUNDRY_MODEL=<your-model> \
hosted-agent-sample
```
The server will be available at `http://localhost:8088`. You can send requests using the same `curl` command shown above.
## Deploying to Foundry
TODO
## Using the deployed agent in Agent Framework
After deploying the agent, you can also try to use the agent in Agent Framework. Refer to the [using_deployed_agent.py](./using_deployed_agent.py) sample for an example of how to do this.
| [using_deployed_agent.py](./using_deployed_agent.py) | An example of how to use the deployed agent in Agent Framework. |