Files
Tao Chen 88347f6494 Python: Update hosting agent samples + fixes (#5485)
* Update foundry hosting samples

* Add file data type support

* Fix file content and add more tests

* Fix README

* Address comments

* Fix int tests

* remove temp
88347f6494 · 2026-04-28 04:24:05 +00:00
History
..

What this sample demonstrates

An Agent Framework agent that uses Foundry Toolbox for tool discovery and hosted using the Responses protocol. Foundry Toolbox is a managed tool registry in Microsoft Foundry that lets you define tools centrally and share them across agents.

Creating a Foundry Toolbox

You can create a Foundry Toolbox by code. Refer to this sample for an example: Foundry Toolbox CRUD Sample.

You can also create a Foundry Toolbox in the Foundry portal. Read more about it in the Foundry toolbox documentation.

If you set up a project with this sample and provision the resources using azd provision, a Foundry Toolbox will be created with the specified tools in agent.manifest.yaml.

How It Works

Model Integration

The agent uses FoundryChatClient from the Agent Framework to create an OpenAI-compatible Responses client. It loads a named Foundry Toolbox via client.get_toolbox(name) — the toolbox is a server-side bundle of tool configurations (e.g., code_interpreter, web_search) defined in the Foundry portal or by azd provision. Omitting version resolves the toolbox's current default version at runtime.

The sample then narrows the toolbox to a subset of tool types via select_toolbox_tools(toolbox, include_types=[...]) before handing it to the agent. This demonstrates how one toolbox can be reused across agents that each expose only the tools they need — here, the agent only sees code_interpreter even though the toolbox also includes web_search.

See main.py for the full implementation.

Agent Hosting

The agent is hosted using the Agent Framework with the ResponsesHostServer, which provisions a REST API endpoint compatible with the OpenAI Responses protocol.

Running the Agent Host

Follow the instructions in the Running the Agent Host Locally section of the README in the parent directory to run the agent host.

Interacting with the agent

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 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 an "input" field to interact with the agent. For example:

curl -X POST http://localhost:8088/responses -H "Content-Type: application/json" -d '{"input": "What tools do you have?"}'

Deploying the Agent to Foundry

To host the agent on Foundry, follow the instructions in the Deploying the Agent to Foundry section of the README in the parent directory.