# What is an agent framework, and do you need one?

Date: 2024-06-13 · Author: Robert Scales · https://guidetoartificialintelligence.com/en/learn/agent-framework-need/

**Answer:** An agent framework is a code library that supplies the plumbing every AI agent needs, such as the think-act-observe loop, tool definitions, memory and the hand-offs between several agents, so you write less of it yourself. You need one when you have several agents, many tools or a team to share code with; for a single agent with two or three tools, about fifty lines of plain Python are often easier to read and debug.

An AI agent is a program in which a language model chooses the next step: call a search tool, read the result, decide what to do with it, and repeat until the job is done. Writing one from scratch means writing the same pieces every time: a loop, a way to describe tools to the model, code that runs those tools, a record of what has happened so far, and rules for when to stop. An agent framework is a library that ships those pieces ready-made.

That convenience has a cost. Each framework brings its own vocabulary, its own defaults and its own layers between you and the model. When something goes wrong, you debug the framework as well as your idea. So the honest answer to "do I need one?" is: it depends on how many moving parts you have.

## What a framework actually gives you

Most agent frameworks in mid-2024 offer some mix of the following:

- **A run loop.** The cycle of asking the model, reading its chosen action, running it and feeding back the result.
- **Tool wrappers.** Ready-made connections to web search, file readers, databases or code execution, plus a standard way to add your own.
- **Model connectors.** One interface for several providers, so switching from one model to another is a setting rather than a rewrite.
- **Memory and state.** A place to keep the conversation, intermediate results and notes between steps.
- **Multi-agent coordination.** Ways for several specialized agents to pass work to one another.
- **Tracing.** Logs of every prompt, tool call and reply, which is the single most useful thing when an agent misbehaves.

## A worked example: one research task, two ways

Say you want a small research assistant: it searches the web for recent news on a topic, then a second step turns the notes into a short briefing.

**With a framework.** In CrewAI, you describe each agent by its role, goal and a short backstory, give it tools, then list the tasks and start the crew. The sketch below follows the pattern in CrewAI's README. The web search tool comes from the optional `crewai[tools]` package and needs a key from the Serper search service; CrewAI calls the OpenAI API by default, so an OpenAI key is needed too.

```python
from crewai import Agent, Task, Crew
from crewai_tools import SerperDevTool   # needs SERPER_API_KEY; OPENAI_API_KEY for the model

searcher = Agent(
    role="News researcher",
    goal="Find reliable, recent reporting on the assigned topic",
    backstory="A careful fact-finder who notes where each claim comes from.",
    tools=[SerperDevTool()],
    allow_delegation=False,
)
writer = Agent(
    role="Briefing writer",
    goal="Turn research notes into a plain-language briefing",
    backstory="Writes short, clear summaries for busy managers.",
    allow_delegation=False,
)

research = Task(
    description="Collect five recent developments in heat-pump technology, with the source of each.",
    expected_output="Five bullet points, each with a source link",
    agent=searcher,
)
briefing = Task(
    description="Write a 200-word briefing from the research notes.",
    expected_output="One briefing of about 200 words",
    agent=writer,
)

crew = Crew(agents=[searcher, writer], tasks=[research, briefing])
print(crew.kickoff())
```

That is roughly thirty lines, and the framework handles the loop, the tool calls and passing the first task's output to the second.

**With plain code.** The same job is two model calls and one search call: search, ask the model to pick and summarize five items with sources, then ask it to write the briefing. You control every prompt and can print every step, using the same think-act-observe loop that any agent runs underneath. For a fixed two-step job like this, plain code is shorter to understand, even if it is a few more lines to type.

> **Try it:** Write down your agent idea as a list of steps. If every step is known in advance, build it as a plain script first. If the model must choose among many tools, or several roles need to hand work back and forth, try the same idea in a framework and compare how easy each version is to debug.

## A quick rule of thumb

| Your situation | Suggested starting point |
|---|---|
| One model, one to three tools, fixed steps | Plain code |
| Many tools, or swapping between model providers | A framework with good connectors |
| Several roles that hand work to each other | A multi-agent framework |
| A team maintaining the agent for months | A framework, for shared conventions and tracing |

Whatever you choose, keep a step limit, log every tool call, and ask for human approval before any action with real consequences, such as sending email or spending money. No framework removes those responsibilities.

## How do LangChain, CrewAI and AutoGen differ?

**LangChain** is the broadest of the three. Its README describes a toolkit for any application built on language models: retrieval over your own documents, structured data extraction, chatbots and agents. It is split into packages, with `langchain-core` for the basic building blocks, `langchain-community` and partner packages for hundreds of integrations, and LangGraph, a companion library that models an agent's steps as nodes and connections in a graph, for custom agents that need fine control over each step. LangSmith, its hosted service, adds tracing and testing. Choose it when you need many integrations or precise control over flow, and expect a learning curve.

**CrewAI** is built around a team metaphor. You define agents with roles, goals and backstories, assign them tasks with an expected output, and run them as a crew, either in sequence or under a manager agent that plans and delegates. It is the quickest of the three to read, which makes it a good fit for role-based workflows like research-then-write. Note that its README says it sends anonymous usage statistics by default.

**AutoGen**, from Microsoft Research and university partners, treats an application as a conversation among agents. Its basic example pairs an assistant agent, which writes answers and code, with a user proxy agent that can run that code and report back; the two talk until the task is solved, and a person can join in at any point. It is strongest for tasks where writing and running code is the main tool. Because it executes code, the project recommends running it inside Docker, an isolated container, rather than directly on your machine.

## Sources

- crewAI README (commit ab066a1): https://github.com/crewAIInc/crewAI/blob/ab066a11a8bb481bf3de3af21a4617f57736b5c1/README.md
- LangChain README (commit abb0cec): https://github.com/langchain-ai/langchain/blob/abb0cecb44005f6c1cf712ffa2f8c083c552097c/README.md
- AutoGen README (commit 1e5c03f): https://github.com/microsoft/autogen/blob/1e5c03f66a0df121642acb277db3e72f52c8a318/README.md
