Documentation Index
Fetch the complete documentation index at: https://spacesail.mintlify.app/llms.txt
Use this file to discover all available pages before exploring further.
This example demonstrates how to create an agent with basic session state management, maintaining a shopping list across interactions using SQLite storage.
Code
from agno.agent import Agent
from agno.db.sqlite import SqliteDb
from agno.models.openai import OpenAIChat
def add_item(session_state, item: str) -> str:
"""Add an item to the shopping list."""
session_state["shopping_list"].append(item) # type: ignore
return f"The shopping list is now {session_state['shopping_list']}" # type: ignore
# Create an Agent that maintains state
agent = Agent(
model=OpenAIChat(id="gpt-5-mini"),
# Initialize the session state with a counter starting at 0 (this is the default session state for all users)
session_state={"shopping_list": []},
db=SqliteDb(db_file="tmp/agents.db"),
tools=[add_item],
# You can use variables from the session state in the instructions
instructions="Current state (shopping list) is: {shopping_list}",
markdown=True,
)
# Example usage
agent.print_response("Add milk, eggs, and bread to the shopping list", stream=True)
print(f"Final session state: {agent.get_session_state()}")
Usage
Create a virtual environment
Open the Terminal and create a python virtual environment.python3 -m venv .venv
source .venv/bin/activate
Install libraries
pip install -U agno openai
Export your OpenAI API key
export OPENAI_API_KEY="your_openai_api_key_here"
Create a Python file
Create a Python file and add the above code.touch session_state_basic.py
Run Agent
python session_state_basic.py
Find All Cookbooks
Explore all the available cookbooks in the Agno repository. Click the link below to view the code on GitHub:Agno Cookbooks on GitHub