The Problem: When Your AI Has a “Goldfish Memory”
Last week, I spent a sleepless night handling a tough production issue. The customer support chatbot kept forgetting everything; after just three turns of conversation, it had completely lost track of the user’s initial request. Worse yet, it couldn’t perform any actions beyond simple text replies. If you’ve ever found LangChain too bulky with its endless boilerplate code, Phidata is the lightweight “lifesaver” you need.
Phidata packages LLMs (OpenAI, Claude, Llama…) along with Memory and Tools (action capabilities) into a single entity. Instead of manually managing the messages array, you can focus entirely on your business logic.
Experiment: Running Your First AI Assistant in 2 Minutes
Enough theory, let’s see how fast the code actually runs. You just need to install the library and prepare an OpenAI API Key to get started.
pip install -U phidata openai duckduckgo-search
Create an assistant.py file with the content below. This bot can search the web to update real-time data instantly:
from phi.assistant import Assistant
from phi.tools.duckduckgo import DuckDuckGo
import os
os.environ["OPENAI_API_KEY"] = "sk-xxxx..."
assistant = Assistant(
tools=[DuckDuckGo()],
show_tool_calls=True
)
assistant.print_response("What is the price of Bitcoin today?", markdown=True)
The best part: You don’t need to code search logic. When you ask about the Bitcoin price, the AI automatically understands it lacks information and triggers the DuckDuckGo tool. This is the power of Function Calling.
Why Phidata is Worth Using Over Other Frameworks?
Many current frameworks overcomplicate things with too many layers of abstraction. Phidata takes a more pragmatic approach, helping you reduce structural coding time by about 50%:
- Automatic Function Calling: Just drop a Python function into
tools, and Phidata handles the JSON schema for the LLM. - Streamlined Session Management: The bot’s memory is saved directly to a database instead of just being stored temporarily in RAM.
- Polished Output: Supports streaming and beautiful Markdown formatting out of the box without extra configuration.
How to Implement “Long-term Memory” (Memory)
Normally, an AI forgets everything once you stop the script. To help the bot recognize returning customers, we need to use Storage. SQLite is an excellent choice for a quick start on your local machine.
from phi.assistant import Assistant
from phi.storage.assistant.sqlite import SqlAssistantStorage
assistant = Assistant(
storage=SqlAssistantStorage(
table_name="ai_memory",
db_file="agents.db",
),
read_chat_history=True,
add_chat_history_to_messages=True,
session_id="user_unique_001"
)
assistant.print_response("Hi, I'm Nam, a developer from Hanoi.")
assistant.print_response("Where did I just say I was from?")
Phidata will create an agents.db file to track everything. Even if you restart the app, as long as you use the correct session_id, the bot will remember who you are. This is the foundation for building deeply personalized applications.
Turning AI into a Real “Employee” with Function Calling
This is my favorite feature. Instead of just chatting, the AI can look up orders or send emails to customers. You just need to write a pure Python function.
import json
def check_shipping_status(order_id: str):
"""Use this function to check the shipping status of an order."""
# Simulating a database query
db = {"ORD123": "In transit", "ORD456": "Delivered"}
return json.dumps(
{"status": db.get(order_id, "Not found")}
)
assistant = Assistant(tools=[check_shipping_status], show_tool_calls=True)
assistant.print_response("Where is my order ORD123?")
Pro tip: The docstring (function description) is extremely important. The AI relies on it to decide when to call the function. Write clear descriptions to prevent the bot from calling the wrong tool.
Advanced Workflow: RAG Combined with Memory
In the real-world systems I’ve deployed, an Assistant usually operates in a 5-step process:
- Receive the question and check Memory for context.
- Retrieve information from the Knowledge Base (PDF files, Docs) to find relevant data.
- Check if **Tools** (3rd-party APIs) are needed.
- The LLM synthesizes information from all sources.
- Return the final response to the user.
Real-world Deployment Experience
After several “stumbles” while bringing AI to production, I’ve gathered three vital lessons:
- API Key Security: Never hardcode your keys. Use a
.envfile to avoid losing money if you accidentally push code to GitHub. - Prevent Infinite Loops: LLMs occasionally suffer from logic errors and call tools repeatedly. Set
max_calls=5to limit the number of tool calls per conversation turn. - Enable Debugging: During development, use
debug_mode=True. You’ll see detailed payloads for every request, making bug fixing many times faster.
Phidata truly makes building AI Agents more “breathable” and practical. If you’re looking for a framework that balances features and simplicity, give Phidata a try today.

