Lesson 5 of 39 · Getting Started
Other Agent Types: Foundry, Copilot and Claude
Use other agent types in Microsoft Agent Framework: Foundry agents, Copilot Studio, GitHub Copilot, Claude Code, remote A2A agents and your own BaseAgent.
- 11 min read
- Intermediate
- Reviewed
- Connect to an agent defined in Microsoft Foundry with FoundryAgent
- Use Copilot Studio, Claude Code and GitHub Copilot as agents, and know what each needs
- Call a remote agent over the A2A protocol with A2AAgent
- Write a custom agent by subclassing BaseAgent
- Explain the difference between Agent and RawAgent
Many kinds of agents, one way to call them
So far every agent was an Agent: a chat client plus instructions, defined in your code. Agent Framework also wraps agents that are defined somewhere else: in a cloud service, in a low-code tool, in a coding assistant, or on another company's server. They all have the same run() method and return the same AgentResponse, so the rest of your code doesn't care where an answer comes from:
# Different kinds of agents, one way of calling them. Your code only needs run():
# where the answer comes from (a cloud model, another company's service, a table) is hidden.
class CloudModelAgent:
name = "assistant"
def run(self, question): return "I'd suggest the coastal route to Foz."
class RemoteRepairAgent: # think: an A2A agent run by another team
name = "repair_desk"
def run(self, question): return "First free repair slot: Thursday 10:00."
class OpeningHoursAgent: # think: a custom agent answering from a table
name = "opening_hours"
def run(self, question): return "Saturday: 10:00 to 16:00."
def pick(question, agents):
if "repair" in question or "fix" in question: return agents["repair_desk"]
if "open" in question: return agents["opening_hours"]
return agents["assistant"]
agents = {agent.name: agent for agent in [CloudModelAgent(), RemoteRepairAgent(), OpeningHoursAgent()]}
for question in ["Can you fix my brakes?", "Are you open on Saturday?", "Where should I ride today?"]:
agent = pick(question, agents)
print(f"{question:28} -> {agent.name}: {agent.run(question)}")| Class | Where the agent is defined and runs | What you need |
|---|---|---|
Agent | In your code, using any chat client | A model provider |
FoundryAgent | In a Microsoft Foundry project | An Azure subscription (paid) |
CopilotStudioAgent | In Microsoft Copilot Studio | A Copilot Studio licence and an Entra ID app registration |
ClaudeAgent | Claude Code, on your computer | The Claude Code CLI and an Anthropic account (paid) |
GitHubCopilotAgent | GitHub Copilot, on your computer | The GitHub Copilot CLI and a GitHub account with Copilot |
A2AAgent | Any server that speaks the A2A protocol | The server's address |
your own BaseAgent subclass | Wherever your code says | Nothing extra |
Agents defined in Microsoft Foundry
Microsoft Foundry (formerly Azure AI Foundry) is Microsoft's cloud platform for models and agents. Teams can create an agent in its web portal, with instructions, tools and knowledge, and version it there. FoundryAgent connects to such an agent by name:
import asyncio
from azure.identity.aio import AzureCliCredential
from agent_framework.foundry import FoundryAgent
async def main():
async with AzureCliCredential() as credential:
agent = FoundryAgent(
project_endpoint="https://YOUR-PROJECT.services.ai.azure.com",
agent_name="velo-support", # an agent created in the Foundry portal
agent_version="1", # needed for prompt agents; leave out for hosted agents
credential=credential,
)
response = await agent.run("What is your returns policy?")
print(response.text)
asyncio.run(main())- A prompt agent is defined by instructions and tools in Foundry and has numbered versions, so you pass
agent_version. A hosted agent is your own code deployed to Foundry; it has no version. - The agent's instructions and tool definitions live in Foundry. If it declares function tools, pass matching Python functions with
tools=so they can run locally. - Settings can come from
FOUNDRY_PROJECT_ENDPOINT,FOUNDRY_AGENT_NAMEandFOUNDRY_AGENT_VERSION;FoundryAgentOptionstypes its options.
Don't confuse it with FoundryChatClient from the lesson Installation, Settings and Chat Clients: that one uses a model in Foundry for an agent defined in your code. FoundryAgent uses an agent defined in Foundry.
Copilot Studio agents
Microsoft Copilot Studio is a low-code tool in which business teams build agents, for example an HR helper that answers from company policies. CopilotStudioAgent lets your code talk to one:
import asyncio
from agent_framework.microsoft import CopilotStudioAgent
async def main():
agent = CopilotStudioAgent(name="hr_helper") # settings come from COPILOTSTUDIOAGENT__* variables
response = await agent.run("How many days of holiday do new staff get?")
print(response.text)
asyncio.run(main())It reads four settings: COPILOTSTUDIOAGENT__ENVIRONMENTID (the Power Platform environment), COPILOTSTUDIOAGENT__SCHEMANAME (the agent's schema name), and COPILOTSTUDIOAGENT__AGENTAPPID and COPILOTSTUDIOAGENT__TENANTID (an app registration in Microsoft Entra ID that's allowed to call it). Creating the agent signs you in: it uses a cached token if there is one, and otherwise opens a browser window.
Claude Code and GitHub Copilot as agents
Two coding assistants that run on your computer can also be wrapped as agents:
import asyncio
from agent_framework.anthropic import ClaudeAgent
from agent_framework.github import GitHubCopilotAgent
async def main():
# Claude Code as an agent: it can read and edit files in its working folder
async with ClaudeAgent(
instructions="You review Python code for bugs.",
tools=["Read", "Glob"], # Claude Code's own built-in tools
default_options={"cwd": "./my_project", "max_turns": 5},
) as reviewer:
print((await reviewer.run("Find likely bugs in this project.")).text)
# GitHub Copilot as an agent
async with GitHubCopilotAgent(instructions="You explain shell commands simply.") as helper:
print((await helper.run("What does `ls -la` show?")).text)
asyncio.run(main())ClaudeAgentdrives Claude Code through Anthropic's Claude Agent SDK. Claude Code brings its own tools, which you name as strings such as"Read","Write","Bash"and"Glob", and you can add Python functions as tools too.ClaudeAgentOptionsholds its options:cwd(the folder it works in),model,permission_mode,max_turns,max_budget_usd,allowed_toolsandmcp_servers, among others. It needs the Claude Code CLI installed and an Anthropic account.GitHubCopilotAgentdrives GitHub Copilot through the GitHub Copilot SDK.GitHubCopilotOptionsincludemodel,timeout,mcp_serversandon_permission_request, andGitHubCopilotSettingsreads them fromGITHUB_COPILOT_variables such asGITHUB_COPILOT_MODEL. It needs the Copilot CLI and a GitHub account with Copilot.
Remote agents over A2A
A2A (Agent2Agent) is an open protocol that lets agents built with different frameworks, by different teams, call each other over HTTP. Each A2A server publishes an agent card at /.well-known/agent-card.json describing what it can do. A2AAgent turns such a server into a normal agent:
import asyncio
from agent_framework.a2a import A2AAgent
async def main():
repairs = A2AAgent(name="repair_desk", url="https://repairs.velo.example/a2a/") # an agent run by another team
response = await repairs.run("Can you replace a broken spoke this week?")
print(response.text)
print(type(response).__name__) # the same AgentResponse as a local agent
asyncio.run(main())Yes: a spoke replacement takes about 30 minutes. The first free slot is Thursday at 10:00. AgentResponse
Here the repair desk was a separate program built with Agent Framework, but it could have been built with any framework that speaks A2A. A2AAgent supports streaming and sessions like any other agent. The lesson Hosting: A2A, AG-UI, ChatKit and Azure Functions shows how to publish your own agent over A2A.
Writing your own agent
Not every agent needs a language model. Subclass BaseAgent and write run():
import asyncio
from agent_framework import (AgentResponse, AgentResponseUpdate, BaseAgent, Content, Message,
ResponseStream, SupportsAgentRun, normalize_messages)
HOURS = {"monday": "9:00 to 18:00", "tuesday": "9:00 to 18:00", "wednesday": "9:00 to 18:00",
"thursday": "9:00 to 20:00", "friday": "9:00 to 20:00", "saturday": "10:00 to 16:00", "sunday": None}
class OpeningHoursAgent(BaseAgent):
"""Answers opening-hours questions from a table: no model, instant and free."""
def _answer(self, messages) -> str:
question = normalize_messages(messages)[-1].text.lower() # str, Message or list -> list[Message]
for day, hours in HOURS.items():
if day in question:
return f"On {day.title()} we're closed." if hours is None else f"On {day.title()} we're open {hours}."
return "We're open Monday to Saturday; ask me about a specific day."
def run(self, messages=None, *, stream=False, session=None, **kwargs):
reply = self._answer(messages)
if stream:
async def updates():
yield AgentResponseUpdate(role="assistant", contents=[Content.from_text(reply)], author_name=self.name)
return ResponseStream(updates(), finalizer=AgentResponse.from_updates)
async def complete():
return AgentResponse(messages=[Message("assistant", [reply], author_name=self.name)])
return complete()
async def main():
hours = OpeningHoursAgent(name="opening_hours", description="Knows Velo's opening hours.")
print(isinstance(hours, SupportsAgentRun))
print((await hours.run("Are you open on Sunday?")).text)
stream = hours.run("And on Saturday?", stream=True)
async for update in stream:
print("streamed:", update.text)
print((await stream.get_final_response()).messages[0].author_name)
asyncio.run(main())True On Sunday we're closed. streamed: On Saturday we're open 10:00 to 16:00. opening_hours
run()follows the same rules asAgent.run(): withoutstream, it returns something toawaitthat gives anAgentResponse; withstream=True, it returns aResponseStreamofAgentResponseUpdatepieces, here finished withAgentResponse.from_updates.normalize_messagesturns whatever the caller passed (a string, a message or a list) into a list ofMessageobjects.BaseAgentsupplies theid,name,description,create_session()andget_session(), so the class satisfiesSupportsAgentRun.
Custom agents are useful for answers that must be exact (prices, opening hours), for wrapping an existing chatbot or rules engine, and as cheap stand-ins in tests. In a multi-agent system they sit next to model-based agents.
Agent and RawAgent
import asyncio
from agent_framework import Agent, RawAgent
from agent_framework.openai import OpenAIChatClient
print([layer.__name__ for layer in Agent.__mro__[:4]])
async def main():
bare = RawAgent(client=OpenAIChatClient(model="MODEL_NAME"), instructions="Answer in five words or fewer.")
print((await bare.run("Describe Porto.")).text)
asyncio.run(main())['Agent', 'AgentMiddlewareLayer', 'AgentTelemetryLayer', 'RawAgent'] Hilly, colourful, riverside, port wine.
Like chat clients, agents are built from layers: Agent is RawAgent with AgentMiddlewareLayer (agent middleware) and AgentTelemetryLayer (OpenTelemetry tracing) on top. The tool-calling loop lives one level down, in the chat client's FunctionInvocationLayer. Hosted agent types follow the same pattern: RawFoundryAgent, RawClaudeAgent and RawGitHubCopilotAgent are the versions without layers, and FoundryAgent even lets you choose its client with client_type=RawFoundryAgentChatClient. Use the layered classes unless you're building your own stack.
Common mistakes
Write the answering logic of a tiny rule-based agent, like the custom agent in this lesson.
FAQ = {
"helmet": "Helmets start at 39 EUR.",
"rent": "E-bikes cost 35 EUR a day.",
"parking": "There's free bike parking in front of the shop.",
}
def answer(question):
# Return the FAQ answer whose keyword appears in the question (lower-case it first),
# or "Let me connect you to a person." if no keyword matches.
pass
for question in ["Can I RENT a bike?", "Do you sell helmets?", "Can I pay with crypto?"]:
print(answer(question))
Your company's support agent was built and versioned by another team in the Microsoft Foundry portal. Which class lets your code use it?
Summary
- Every agent type has the same
run()and returns anAgentResponse, so they can be mixed freely. FoundryAgentuses agents defined in Microsoft Foundry;CopilotStudioAgentuses Copilot Studio agents.ClaudeAgentandGitHubCopilotAgentwrap coding assistants that can change files: restrict their tools and folder.A2AAgentcalls any remote agent that speaks the A2A protocol.- Subclass
BaseAgentfor your own agents;AgentisRawAgentplus middleware and telemetry layers.
Next: Function Tools.
Finished reading? Tick it off to track your progress.