You might have seen that in my earlier articles I used Azure AI Initiatives shopper library for Python – model 2.5.0 library. These articles illustrate find out how to construct AI Brokers, MCP Instruments, and infer directions utilizing an LLM.
That library works advantageous, however after extra learnings I’ve found a way more thrilling and Azure pleasant library which is the Microsoft Agent Framework. “The Microsoft Agent Framework is the following era of each Semantic Kernel and AutoGen, constructed by the identical groups. It combines AutoGen’s easy agent abstractions with Semantic Kernel’s enterprise options—session-based state administration, sort security, middleware, and telemetry—and provides graph-based workflows for express multi-agent orchestration. The outcome is a versatile, production-ready SDK for constructing single-agent and multi-agent options.”
You will note could similarities utilizing the Microsoft Agent Framework as you probably did with the library from these earlier articles. To import the Microsoft Agent Framework you want to set up the agent-framework-core and the agent-framework-foundry initiatives into your surroundings and import them like the next.
from agent_framework import instrument, Agent from agent_framework.foundry import FoundryChatClient
Itemizing 1, importing the Microsoft Agent Framework
To create a instrument you utilize the @instrument decorator like proven right here. Discover that there’s a approval_mode which help the Human In The Loop (HITL) functionality. Additionally discover that the operate has clear descriptions of every parameter wanted for the useful to execute. Descriptions are what the LLM makes use of to find out which instruments to make use of, so make them desrciptive.
@instrument(approval_mode="never_require")
def submit_claim(
to: Annotated[str, Field(description="Who to send the email to")],
topic: Annotated[str, Field(description="The subject of the email.")],
physique: Annotated[str, Field(description="The text body of the email.")]):
print("nTo:", to)
print("Topic:", topic)
print(physique, "n")
Itemizing 2, declaring and defining an AI Agent instrument
Subsequent you’ll create the chat shopper as proven right here. The shopper wants the Microsoft Foundry endpoint which exposes the deployed AI mannequin, on this case gpt-5-mini. An fascinating level right here is the utilization of the AzureCliCredential as a substitute of DefaultAzureCredential. Each will work and for a neighborhood improvement, proof of idea (POC) exercise it’s advantageous to make use of AzureCliCredential. Nevertheless, if the code is deployed to Azure, AzureCliCredential is not going to operate, so think about using DefaultAzureCredential as a result of when deployed to Azure it can in the end use managed id to entry sources, that is known as a credential chain. The place DefaultAzureCredential makes use of your id whereas coding regionally, then will try different authentication strategies when working from different environments.
shopper = FoundryChatClient(
project_endpoint=os.getenv("PROJECT_ENDPOINT"),
mannequin=os.getenv("MODEL_DEPLOYMENT_NAME"),
credential=AzureCliCredential()
)
Itemizing 3, constructing the chat shopper
Initializing the AI Agent is as proven right here as agent. It makes use of the shopper created beforehand, the system immediate, and the instrument to make use of when the AI Agent is invoked.
async with (
Agent(
shopper=shopper,
identify="ExpenseClaimAgent",
directions="""You might be an AI assistant for expense declare submission.....""",
instruments=[submit_claim],
) as agent,
):
Itemizing 4, initializing the AI Agent
To then name the AI Agent and execute the directions and immediate use this code.
attempt:
prompt_messages = [f"{prompt}: {'09-SEP-2026,taxi,24.00'}"]
response = await agent.run(prompt_messages)
print(f"n# Agent:n{response}")
besides Exception as e:
print (e)
Itemizing 5, use the agent
It’s all the time good apply to position you code inside attempt…catch blocks in order that worth error messages could be rendered. The messages are very helpful when troubleshooting. Lastly, when the expense declare is submitted you’ll expertise the next.

