An instrumented Agent Framework agent hosted using the Responses protocol.
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.
See main.py for the full implementation.
The agent is hosted using the Agent Framework with the ResponsesHostServer, which provisions a REST API endpoint compatible with the OpenAI Responses protocol.
Agent Framework is natively instrumented to capture diagnostics and telemetry for agent execution. Instrumentation is enabled by default. To also capture sensitive event payloads (prompts, tool arguments, etc.) set ENABLE_SENSITIVE_DATA=true. This sample demonstrates how to manage these settings via environment variables in agent.manifest.yaml and agent.yaml.
Foundry Hosted Agent has built-in observability thus you don't need to set up exporters manually to capture telemetry from your code. The traces, metrics, and logs generated by the agent are automatically collected and made available through Foundry's observability stack via Azure Monitor/Application Insights. The APPLICATIONINSIGHTS_CONNECTION_STRING environment variable is injected when the agent is deployed to Foundry, however it is still required to be set in your environment if you want to run the agent host locally and have telemetry sent to Application Insights from your local environment.
Follow the instructions in the Running the Agent Host Locally section of the README in the parent directory to run the agent host.
Because the observability exporters are managed by Foundry, this sample must be run using
azd ai agent run. Run this sample usingpython main.pywill not send telemetry to Application Insights.
azd ai agent run --local "What is the current weather?"A couple of spans will be created for this request from Agent Framework's instrumentation, representing the generation of the response by the agent:
invoke_agent: This span represents the invocation of the agent itself, capturing the start and end of the agent's processing for this request.chat: This span represents the call to the underlying model.execute_tool: This span represents the execution of any tools invoked by the agent as part of generating the response.
For more information on the spans, refer to the OpenTelemetry GenAI Semantic Conventions
To host the agent on Foundry, follow the instructions in the Deploying the Agent to Foundry section of the README in the parent directory.
Once the agent is deployed to Foundry, the telemetry generated by the agent (traces, metrics, and logs) will be automatically collected and sent to Azure Monitor/Application Insights. You can view this telemetry by navigating to the Application Insights resource associated with your Foundry project or directly from the Foundry UI.
In the Foundry UI, next to the Playground tab is the Traces tab, where you can find the conversations and their corresponding trace IDs. Clicking on a trace ID will allow you to drill into the detailed trace information for that particular conversation.