Python agent libraries have settled on a handful of patterns for building agents that use language models to reason, call tools, and keep track of context. If you’ve only seen end-to-end demos, it’s easy to miss the modularity: most frameworks break the problem into three moving parts—tools, memory, and the agent’s control flow—and you wire them up explicitly in code. This makes it possible to swap in your own logic, add new tools, or change how the agent thinks, without rewriting everything.
If you’re evaluating agent libraries for a real project, understanding how these pieces interact is the difference between a working proof of concept and something you can maintain.
Tools: Wrapping Functions for the Agent
In Python agent frameworks, a tool is usually a Python function or method with a description the model can see. You register these tools when you build the agent. The agent calls them as needed, passing in arguments extracted from the conversation or generated by the LLM prompt.
The typical pattern is to annotate a function with a decorator or register it in a list:
def search_docs(query: str) -> str:
"""Searches the internal documentation for the given query."""
...
agent_tools = [search_docs, ...]
Some frameworks let you add metadata—like argument schemas or rate limits—by passing parameters to the decorator or registration function. The agent then decides when to call which tool, often by prompting the model with the tool descriptions.
Memory: Keeping State Between Turns
Memory is how the agent keeps track of what’s happened so far—conversation history, facts, or intermediate results. Most agent libraries offer pluggable memory modules: you can use a simple list of messages, a vector store for semantic recall, or a custom object that implements a defined API.
A typical memory interface will have methods like load_memory() and save_memory(), and you pass the memory object to the agent at creation:




