This repository provides examples of many popular Python AI agent frameworks using LLMs from GitHub Models. Those models are free to use for anyone with a GitHub account, up to a daily rate limit.
- Getting started
- Running the Python examples
- Configuring GitHub Models
- Provisioning Azure AI resources
- Resources
You have a few options for getting started with this repository. The quickest way to get started is GitHub Codespaces, since it will setup everything for you, but you can also set it up locally.
You can run this repository virtually by using GitHub Codespaces. The button will open a web-based VS Code instance in your browser:
-
Open the repository (this may take several minutes):
-
Open a terminal window
-
Continue with the steps to run the examples
A related option is VS Code Dev Containers, which will open the project in your local VS Code using the Dev Containers extension:
-
Start Docker Desktop (install it if not already installed)
-
Open the project:
-
In the VS Code window that opens, once the project files show up (this may take several minutes), open a terminal window.
-
Continue with the steps to run the examples
-
Make sure the following tools are installed:
- Python 3.10+
- Git
-
Clone the repository:
git clone https://github.com/Azure-Samples/python-ai-agent-frameworks-demos cd python-ai-agents-demos
-
Set up a virtual environment:
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
-
Install the requirements:
pip install -r requirements.txt
You can run the examples in this repository by executing the scripts in the examples
directory. Each script demonstrates a different AI agent pattern or framework.
Example | Description |
---|---|
agentframework_basic.py | Uses Agent Framework to build a basic informational agent. |
agentframework_tool.py | Uses Agent Framework to build an agent with a single weather tool. |
agentframework_tools.py | Uses Agent Framework to build a weekend planning agent with multiple tools. |
agentframework_supervisor.py | Uses Agent Framework with a supervisor orchestrating activity and recipe sub-agents. |
Example | Description |
---|---|
langchainv1_basic.py | Uses LangChain v1 to build a basic informational agent. |
langchainv1_tool.py | Uses LangChain v1 to build an agent with a single weather tool. |
langchainv1_tools.py | Uses LangChain v1 to build a weekend planning agent with multiple tools. |
langchainv1_supervisor.py | Uses LangChain v1 with a supervisor orchestrating activity and recipe sub-agents. |
langchainv1_quickstart.py | Uses LangChain v1 to build an assistant with tool calling, structured output, and memory. Based off official Quickstart docs. |
langchainv1_mcp_github.py | Uses Langchain v1 agent with GitHub MCP server to triage repository issues. |
langchainv1_mcp_http.py | Uses Langchain v1 agent with tools from local MCP HTTP server. |
langgraph_agent.py | Builds LangGraph graph for an agent to play songs. |
langgraph_mcp.py | Builds Langgraph graph that uses tools from MCP HTTP server. |
Example | Description |
---|---|
openai_githubmodels.py | Basic setup for using GitHub models with the OpenAI API. |
openai_functioncalling.py | Uses OpenAI Function Calling to call functions based on LLM output. |
openai_agents_basic.py | Uses the OpenAI Agents framework to build a single agent. |
openai_agents_handoffs.py | Uses the OpenAI Agents framework to handoff between several agents with tools. |
openai_agents_tools.py | Uses the OpenAI Agents framework to build a weekend planner with tools. |
openai_agents_mcp_http.py | Uses the OpenAI Agents framework with an MCP HTTP server (travel planning tools). |
Example | Description |
---|---|
pydanticai_basic.py | Uses PydanticAI to build a basic single agent (Spanish tutor). |
pydanticai_multiagent.py | Uses PydanticAI to build a two-agent sequential workflow (flight + seat selection). |
pydanticai_graph.py | Uses PydanticAI with pydantic-graph to build a small question/answer evaluation graph. |
pydanticai_tools.py | Uses PydanticAI with multiple Python tools for weekend activity planning. |
pydanticai_mcp_http.py | Uses PydanticAI with an MCP HTTP server toolset for travel planning (hotel search). |
pydanticai_mcp_github.py | Uses PydanticAI with an MCP GitHub server toolset to triage repository issues. |
Example | Description |
---|---|
llamaindex.py | Uses LlamaIndex to build a ReAct agent for RAG on multiple indexes. |
smolagents_codeagent.py | Uses SmolAgents to build a question-answering agent that can search the web and run code. |
If you open this repository in GitHub Codespaces, you can run the scripts for free using GitHub Models without any additional steps, as your GITHUB_TOKEN
is already configured in the Codespaces environment.
If you want to run the scripts locally, you need to set up the GITHUB_TOKEN
environment variable with a GitHub personal access token (PAT). You can create a PAT by following these steps:
-
Go to your GitHub account settings.
-
Click on "Developer settings" in the left sidebar.
-
Click on "Personal access tokens" in the left sidebar.
-
Click on "Tokens (classic)" or "Fine-grained tokens" depending on your preference.
-
Click on "Generate new token".
-
Give your token a name and select the scopes you want to grant. For this project, you don't need any specific scopes.
-
Click on "Generate token".
-
Copy the generated token.
-
Set the
GITHUB_TOKEN
environment variable in your terminal or IDE:export GITHUB_TOKEN=your_personal_access_token
-
Optionally, you can use a model other than "gpt-4o" by setting the
GITHUB_MODEL
environment variable. Use a model that supports function calling, such as:gpt-4o
,gpt-4o-mini
,o3-mini
,AI21-Jamba-1.5-Large
,AI21-Jamba-1.5-Mini
,Codestral-2501
,Cohere-command-r
,Ministral-3B
,Mistral-Large-2411
,Mistral-Nemo
,Mistral-small
You can run all examples in this repository using GitHub Models. If you want to run the examples using models from Azure OpenAI instead, you need to provision the Azure AI resources, which will incur costs.
This project includes infrastructure as code (IaC) to provision Azure OpenAI deployments of "gpt-4o" and "text-embedding-3-large". The IaC is defined in the infra
directory and uses the Azure Developer CLI to provision the resources.
-
Make sure the Azure Developer CLI (azd) is installed.
-
Login to Azure:
azd auth login
For GitHub Codespaces users, if the previous command fails, try:
azd auth login --use-device-code
-
Provision the OpenAI account:
azd provision
It will prompt you to provide an
azd
environment name (like "agents-demos"), select a subscription from your Azure account, and select a location. Then it will provision the resources in your account. -
Once the resources are provisioned, you should now see a local
.env
file with all the environment variables needed to run the scripts. -
To delete the resources, run:
azd down