* Bump HostedAgents samples to AgentFramework beta.11 and pass credential to UseFoundryTools Update all 8 HostedAgents samples: - Azure.AI.AgentServer.AgentFramework -> 1.0.0-beta.11 - Microsoft.Agents.AI.OpenAI -> 1.0.0-rc4 - Microsoft.Agents.AI/AzureAI/Workflows -> 1.0.0-rc4 - Azure.AI.Projects -> 2.0.0-beta.1 - Fix Workflow.AsAgent() -> AsAIAgent() in FoundryMultiAgent - Pass credential to UseFoundryTools in AgentWithTools (resolves #56802) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Remove AgentWithTools sample (UseFoundryTools no longer supported) Remove the AgentWithTools hosted agent sample as the UseFoundryTools backend is no longer supported. Updated HostedAgents README and solution file to remove all references. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Fix AgentWithHostedMCP: downgrade Azure.AI.OpenAI to 2.8.0-beta.1 for rc4 compatibility Azure.AI.OpenAI 2.9.0-beta.1 has breaking changes (GetResponsesClient no longer accepts deployment name, ResponsesClient.Model removed) that are incompatible with Microsoft.Agents.AI.OpenAI rc4. Pin to 2.8.0-beta.1 and use GetResponsesClient(deploymentName).AsAIAgent() pattern. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
What this sample demonstrates
This sample demonstrates Human-in-the-Loop (HITL) capabilities with thread persistence. The agent wraps function tools with ApprovalRequiredAIFunction so that every tool invocation requires explicit user approval before execution. Thread state is maintained across requests using InMemoryAgentThreadRepository.
Key features:
- Requiring human approval before executing function calls
- Persisting conversation threads across multiple requests
- Approving or rejecting tool invocations at runtime
For common prerequisites and setup instructions, see the Hosted Agent Samples README.
Prerequisites
Before running this sample, ensure you have:
- .NET 10 SDK installed
- An Azure OpenAI endpoint configured
- A deployment of a chat model (e.g., gpt-4o-mini)
- Azure CLI installed and authenticated (
az login)
Environment Variables
Set the following environment variables:
# Replace with your Azure OpenAI endpoint
$env:AZURE_OPENAI_ENDPOINT="https://your-openai-resource.openai.azure.com/"
# Optional, defaults to gpt-4o-mini
$env:AZURE_OPENAI_DEPLOYMENT_NAME="gpt-4o-mini"
How It Works
The sample uses ApprovalRequiredAIFunction to wrap standard AI function tools. When the model decides to call a tool, the wrapper intercepts the invocation and returns a HITL approval request to the caller instead of executing the function immediately.
- The user sends a message (e.g., "What is the weather in Vancouver?")
- The model determines a function call is needed and selects the
GetWeathertool ApprovalRequiredAIFunctionintercepts the call and returns an approval request containing the function name and arguments- The user responds with
approveorreject - If approved, the function executes and the model generates a response using the result
- If rejected, the model generates a response without the function result
Thread persistence is handled by InMemoryAgentThreadRepository, which stores conversation history keyed by conversation.id. This means the HITL flow works across multiple HTTP requests as long as each request includes the same conversation.id.
Note: HITL requires a stable
conversation.idin every request so the agent can correlate the approval response with the original function call. Use therun-requests.httpfile in this directory to test the full approval flow.