True
Agno Notebook
First, what is Agno?
Agno is a tool to orchestrate LLM models, such as LangChain. The main difference is how the workflow is builded: While LangChain has established itself as flexible framework for chaining LLM calls with external tools and APIs, Agno is a minimalist, production-ready alternative that emphasizes transparency and simplicity.
The choice between these 2 frameworks must be taken thinking about the philosophy of the project: If demands a robust ecosystem to a complex project, with memory management, agents, tools and retrievevers, LangChain is the best option (Castlewall scenario).
Agno, on the other hand, strips down the LLM pipeline to its bare essentials, favoring deterministic behavior, easy debugging and a more manutenable python code.
Main sources: - Agno Medium Article - Agno Documentation
Bellow is 2 projects examples, demonstrating how simple it is to build a workflow with Agno
Financial Query (retriever = YFinanceTools)
from agno.agent import Agent
from agno.models.openai import OpenAIChat
from agno.tools.yfinance import YFinanceTools
agent = Agent(
model=OpenAIChat(id="gpt-4o-mini"),
tools=[YFinanceTools(stock_price=True)],
instructions="Use tables to display data. Don't include any other text.",
markdown=True,
)
agent.print_response("What is the stock price of Apple?", stream=True)Multi-agent workflow, with 2 retrievers
from agno.agent import Agent
from agno.models.openai import OpenAIChat
from agno.tools.duckduckgo import DuckDuckGoTools
from agno.tools.yfinance import YFinanceTools
web_agent = Agent(
name="Web Agent",
role="Search the web for information",
model=OpenAIChat(id="gpt-4o-mini"),
tools=[DuckDuckGoTools()],
instructions="Always include sources",
markdown=True,
)
finance_agent = Agent(
name="Finance Agent",
role="Get financial data",
model=OpenAIChat(id="gpt-4o-mini"),
tools=[YFinanceTools(stock_price=True, analyst_recommendations=True, company_info=True)],
instructions="Use tables to display data",
markdown=True,
)
agent_team = Agent(
team=[web_agent, finance_agent],
model=OpenAIChat(id="gpt-4o-mini"), # It can be a different model
instructions=["Always include sources", "Use tables to display data"],
# show_tool_calls=True, # Uncomment to see tool calls in the response
markdown=True,
)
# Give the team a task
agent_team.print_response("What's the market outlook and financial performance of AI semiconductor companies?", stream=True)/home/quentino/miniconda3/envs/agent/lib/python3.10/site-packages/agno/tools/duckduckgo.py:71: RuntimeWarning: This package (`duckduckgo_search`) has been renamed to `ddgs`! Use `pip install ddgs` instead. ddgs = DDGS(
/home/quentino/miniconda3/envs/agent/lib/python3.10/site-packages/agno/tools/duckduckgo.py:90: RuntimeWarning: This package (`duckduckgo_search`) has been renamed to `ddgs`! Use `pip install ddgs` instead. ddgs = DDGS(
Agno Agents with knowledge and storage
from agno.agent import Agent
from agno.embedder.openai import OpenAIEmbedder
from agno.knowledge.url import UrlKnowledge
from agno.models.openai import OpenAIChat
from agno.storage.sqlite import SqliteStorage
from agno.vectordb.lancedb import LanceDb, SearchType
# Load Agno documentation in a knowledge base
knowledge = UrlKnowledge(
urls=["https://docs.agno.com/introduction.md"],
vector_db=LanceDb(
uri="tmp/lancedb",
table_name="agno_docs",
search_type=SearchType.hybrid,
# Use OpenAI for embeddings
embedder=OpenAIEmbedder(id="text-embedding-3-small", dimensions=1536),
),
)
# Store agent sessions in a SQLite database
storage = SqliteStorage(table_name="agent_sessions", db_file="tmp/agent.db")
agent = Agent(
name="Agno Assist",
model=OpenAIChat(id="gpt-4o-mini"),
instructions=[
"Search your knowledge before answering the question.",
"Only include the output in your response. No other text.",
],
knowledge=knowledge,
storage=storage,
add_datetime_to_instructions=True,
# Add the chat history to the messages
add_history_to_messages=True,
# Number of history runs
num_history_runs=3,
markdown=True,
)
if __name__ == "__main__":
# Load the knowledge base, comment out after first run
# Set recreate to True to recreate the knowledge base if needed
agent.knowledge.load(recreate=False)
agent.print_response("What is Agno?", stream=True)INFO Loading knowledge base
INFO Skipped 2 existing/duplicate documents.
INFO Added 0 documents to knowledge base
INFO Found 3 documents
agent.print_response("What is Agno?", stream=True)from agno.agent import Agent
from agno.memory.v2.db.sqlite import SqliteMemoryDb
from agno.memory.v2.memory import Memory
from agno.models.openai import OpenAIChat
from agno.tools.reasoning import ReasoningTools
from agno.tools.yfinance import YFinanceTools
memory = Memory(
# Use any model for creating and managing memories
model=OpenAIChat(id="gpt-4o-mini"),
# Store memories in a SQLite database
db=SqliteMemoryDb(table_name="user_memories", db_file="tmp/agent.db"),
# We disable deletion by default, enable it if needed
delete_memories=True,
clear_memories=True,
)
agent = Agent(
model=OpenAIChat(id="gpt-4o-mini"),
tools=[
ReasoningTools(add_instructions=True),
YFinanceTools(stock_price=True, analyst_recommendations=True, company_info=True, company_news=True),
],
# User ID for storing memories, `default` if not provided
user_id="ava",
instructions=[
"Use tables to display data.",
"Include sources in your response.",
"Only include the report in your response. No other text.",
],
memory=memory,
# Let the Agent manage its memories
enable_agentic_memory=True,
markdown=True,
)
if __name__ == "__main__":
# This will create a memory that "ava's" favorite stocks are NVIDIA and TSLA
agent.print_response(
"My favorite stocks are NVIDIA and TSLA",
stream=True,
show_full_reasoning=True,
stream_intermediate_steps=True,
)
# This will use the memory to answer the question
agent.print_response(
"Can you compare my favorite stocks?",
stream=True,
show_full_reasoning=True,
stream_intermediate_steps=True,
)<string>:13: ResourceWarning: unclosed <ssl.SSLSocket fd=98, family=AddressFamily.AF_INET,
type=SocketKind.SOCK_STREAM, proto=6, laddr=('192.168.1.12', 34008), raddr=('162.159.140.245', 443)>
ResourceWarning: Enable tracemalloc to get the object allocation traceback