microsoft-foundry / microsoft-foundry/foundry-samples

Add a hosted-agent sample: Anthropic (Claude) via APIM with Agent Framework

Open
#947 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Bicep
Stars
445
Forks
494
Avg merge
11h 35m
Merged PRs (30d)
38

Description

Problem

samples/python/hosted-agents/agent-framework/responses/01-basic is the only Agent Framework "connect to a model" sample, and it uses FoundryChatClient, which speaks the OpenAI Responses protocol to a Foundry-deployed model. Claude models exposed through Azure API Management (or Azure AI Foundry directly) are Anthropic Messages-protocol only — there is no OpenAI-compatible route — so FoundryChatClient can never reach them. There's currently no sample in this repo showing how to wire a hosted Agent Framework agent to an Anthropic model.

Proposal

Add a new sample, e.g. samples/python/hosted-agents/agent-framework/responses/14-anthropic-apim, using AnthropicFoundryClient from the agent-framework-anthropic package (built on the anthropic SDK's AsyncAnthropicFoundry) instead of FoundryChatClient:

from agent_framework import Agent
from agent_framework_anthropic import AnthropicFoundryClient
from agent_framework_foundry_hosting import ResponsesHostServer

client = AnthropicFoundryClient(
    model=os.environ["ANTHROPIC_MODEL_NAME"],       # e.g. claude-sonnet-5
    base_url=os.environ["APIM_ANTHROPIC_BASE_URL"],  # https://<apim>.azure-api.net/anthropic
    api_key=os.environ["APIM_SUBSCRIPTION_KEY"],
)
agent = Agent(client=client, instructions="...")
ResponsesHostServer(agent).run()

api_key is sent as the standard Anthropic SDK x-api-key header, matching what an APIM Anthropic-passthrough policy typically expects. azure.yaml needs no ai-project.deployments block (no Foundry-deployed model is used) — the ai-project service stays for hosting/identity, and ANTHROPIC_MODEL_NAME/APIM_ANTHROPIC_BASE_URL/APIM_SUBSCRIPTION_KEY are declared as agent env vars instead.

Foundry's hosted-agent session/conversation/history management is unaffected by the chat-client swap — ResponsesHostServer owns that, not the chat client — so multi-turn conversations work exactly as in 01-basic.

Try it now

I published a standalone, runnable version of this sample (same file layout as 01-basic) at https://github.com/lordlinus/foundry-agent-anthropic-apim — it works with the exact same azd ai agent init -m <url> flow used for the official samples:

mkdir my-anthropic-apim-agent && cd my-anthropic-apim-agent
azd ai agent init -m https://github.com/lordlinus/foundry-agent-anthropic-apim/blob/main/azure.yaml

Verified end-to-end: azd ai agent run/invoke --local and a full azd provision/azd deploy/azd ai agent invoke deployment against a live Foundry project, including multi-turn session continuity.

About a pull request

I have the full sample ready to submit (matching 01-basic's file layout: azure.yaml, README.md, AGENTS.md, CLAUDE.md, src/agent-framework-agent-anthropic-apim/{Dockerfile,main.py,requirements.txt,.env.example,.azdignore,.dockerignore}, identical to the repo linked above), but I could not open a working pull request:

  • I don't have branch-creation permission on microsoft-foundry/foundry-samples, so per CONTRIBUTING.md a same-repo-branch PR isn't possible for me.
  • My existing fork (lordlinus/foundry-samples) predates a history change upstream, so GitHub reports "no history in common" and refuses to open a PR from it at all — re-forking would be needed first.

I'm happy to push the sample to a same-repo branch if a maintainer can grant branch-creation access, or to send the file contents directly if that's easier to land.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Compare samples/python/hosted-agents/agent-framework/responses/01-basic with the proposed azure.yaml and src/agent-framework-agent-anthropic-apim files, especially main.py and requirements.txt. Start by checking the AnthropicFoundryClient and ResponsesHostServer entry points, then run azd ai agent run and invoke --local. Done means the sample provisions and deploys with the three documented environment variables and preserves multi-turn hosted-agent sessions.

Written by the indexing model from the issue text.

Assessment

Tech stack
azure, python
Domain
ai, cloud
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
74/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.