"Which agent framework should I use?" is the wrong first question. The better one is: which part of the agent are you building?
An agent isn't one thing. It's a loop that calls a model, some tools, some state, and some context about the world it's working in. So instead of crowning one framework, here are seven Python libraries I'd actually pick in 2026, each for one job, with a short snippet for every one.
I work on Graphify (it's #7). Everything else is here because it's genuinely good at its job.
TL;DR
| # | Library | Pick it for | ⭐ (Nov 16, 2026) |
|---|---|---|---|
| 1 | Pydantic AI | Typed agents and validated output | ~21.2k |
| 2 | LangGraph | Stateful, multi-step workflows | ~45k |
| 3 | OpenAI Agents SDK | A small agent loop with tools and handoffs | ~30.7k |
| 4 | smolagents | Agents that write and run Python | ~30.4k |
| 5 | MCP Python SDK | Exposing tools to any MCP client | ~24.9k |
| 6 | LiteLLM | One API for every model provider | ~63.3k |
| 7 | Graphify | Giving coding agents a map of a codebase | ~148k |
1. Pydantic AI: when the output has to be right
Pydantic AI (MIT) is from the Pydantic team, and it feels like it. You describe the output as a model, and the agent has to hand you back something that validates.
from pydantic import BaseModel
from pydantic_ai import Agent
class Answer(BaseModel):
city: str
country: str
agent = Agent("test", output_type=Answer, instructions="Answer briefly.")
result = agent.run_sync("Where were the 2012 Olympics?")
print(result.output)
Small trick: "test" is a built-in fake model, so this runs offline and is great in unit tests. Swap in a real model string like "openai:gpt-4o" when you're ready.
Pick it when your agent feeds another system and a malformed response is a bug.
2. LangGraph: when the agent is really a workflow
LangGraph (MIT) models your agent as a graph of steps with shared state. Branches, retries, human approval, checkpoints: it's built for the parts of an agent that need to be boring and reliable.
from typing import TypedDict
from langgraph.graph import StateGraph, START, END
class State(TypedDict):
question: str
answer: str
def think(state: State) -> dict:
return {"answer": f"thinking about: {state['question']}"}
graph = StateGraph(State)
graph.add_node("think", think)
graph.add_edge(START, "think")
graph.add_edge("think", END)
app = graph.compile()
print(app.invoke({"question": "what calls make_context?"}))
Pick it when you can draw your agent on a whiteboard as boxes and arrows.
3. OpenAI Agents SDK: the smallest useful agent loop
OpenAI Agents SDK (MIT) gives you agents, tools, handoffs between agents, guardrails and tracing, and not much else. A plain Python function becomes a tool with one decorator.
from agents import Agent, Runner, function_tool
@function_tool
def get_weather(city: str) -> str:
"""Get the weather for a city."""
return f"It's sunny in {city}."
agent = Agent(name="Helper", instructions="Be concise.", tools=[get_weather])
result = Runner.run_sync(agent, "What's the weather in Hyderabad?")
print(result.final_output)
Pick it when you want a working agent in 15 lines and you'll add structure later.
4. smolagents: agents that think in code
smolagents (Apache-2.0) from Hugging Face has a fun twist: its CodeAgent writes Python to call your tools instead of emitting JSON tool calls. For multi-step tasks that's often a more natural fit, since the model can loop, branch and combine results in one go.
from smolagents import CodeAgent, InferenceClientModel, tool
@tool
def word_count(text: str) -> int:
"""Count the words in a piece of text.
Args:
text: The text to count.
"""
return len(text.split())
agent = CodeAgent(tools=[word_count], model=InferenceClientModel())
agent.run("How many words are in 'agents are just loops with tools'?")
Pick it when your task looks more like a small script than a single tool call.
5. MCP Python SDK: write a tool once, use it everywhere
The official MCP Python SDK (MIT) is how you expose your tools to Claude Code, Cursor, Codex and every other MCP client. Heads up if you're coming from older tutorials: in mcp 2.x, FastMCP is now MCPServer.
from mcp.server.mcpserver import MCPServer
server = MCPServer("demo")
@server.tool()
def add(a: int, b: int) -> int:
"""Add two numbers."""
return a + b
if __name__ == "__main__":
server.run()
Pick it when more than one agent or client should use the same tools. And keep the tool list short. Every schema costs context on every turn.
6. LiteLLM: stop rewriting provider code
LiteLLM gives you one completion() call for OpenAI, Anthropic, Gemini, Bedrock, local models and a long list of others. Switching models becomes a string change. It also has a proxy server if you want keys, budgets and logging in one place.
from litellm import completion
resp = completion(
model="anthropic/claude-sonnet-4-5",
messages=[{"role": "user", "content": "Say hi"}],
mock_response="hi!", # remove this to make a real call
)
print(resp.choices[0].message.content)
Pick it when you want to compare models, or you don't want your agent married to one provider.
7. Graphify: give your coding agent a map
If the agent you're building works on code, the hardest part is usually context: knowing what calls what, where things live, and what breaks if you touch something. Graphify (Apache-2.0) turns a repo into a knowledge graph with tree-sitter (no embeddings, no vector store) and serves it to agents over MCP.
pip install "graphifyy[mcp]"
graphify update .
claude mcp add --transport stdio graphify -- graphify-mcp "$(pwd)/graphify-out/graph.json"
On Click that build takes about 3 seconds and produces 3,498 nodes and 6,798 edges. Then "who calls make_context?" is one get_neighbors call that returns every caller and callee with file and line, in about 188 tokens. Reading the files that mention it would be close to 49,000.
The PyPI package is graphifyy (two y's); the command is graphify. If you'd rather not run it locally, hosted Graphify keeps the graph fresh for your GitHub repos.
Pick it when your agent spends more time grepping than coding.
How I'd combine them
You don't need all seven. A setup I like for a coding agent:
- LiteLLM for the model call
- Pydantic AI or the OpenAI Agents SDK for the loop
- LangGraph once you need state, retries or approvals
- MCP for tools, with Graphify as the codebase map
If this list helped, a ⭐ on Graphify's GitHub genuinely helps, and come say hi in our Discord.
What's the one Python library you'd add to this list for building agents? Tell me in the comments and why. I'll try the best ones and do a follow-up.
Top comments (0)