The Learning system enables agents to learn from interactions, build knowledge over time, and improve their performance. It combines memory, knowledge updates, and adaptive behavior.
LearningMachine
The LearningMachine class provides unified learning capabilities for agents.
from agno import Agent
from agno.learn.machine import LearningMachine
from agno.db.sqlite import SQLiteDb
db = SQLiteDb( db_file = "agent.db" )
agent = Agent(
model = "gpt-4o" ,
db = db,
learning = True , # Enable learning
add_learnings_to_context = True
)
Enabling Learning
learning
bool | LearningMachine
default: "None"
Enable learning. Use True for default learning or provide a LearningMachine instance for custom configuration.
If True, adds learnings to the agent’s context.
How Learning Works
Experience Collection : Agent interactions are stored in the database
Pattern Recognition : System identifies patterns in successful interactions
Knowledge Extraction : Useful information is extracted and stored
Context Enhancement : Learnings are added to future interactions
Example Usage
Basic Learning
Custom LearningMachine
Multi-User Learning
Learning with Memory
Learning from Feedback
Domain-Specific Learning
from agno import Agent
from agno.db.sqlite import SQLiteDb
db = SQLiteDb( db_file = "learning.db" )
agent = Agent(
model = "gpt-4o" ,
db = db,
learning = True ,
add_learnings_to_context = True
)
# Agent learns from interactions
response = agent.run( "I prefer concise answers" , user_id = "user_1" )
# In future interactions, agent remembers preference
response = agent.run( "Explain quantum computing" , user_id = "user_1" )
# Agent provides concise answer based on learned preference
Learning Types
1. User Preferences
Learn communication style, detail level, formatting preferences:
agent.run( "I prefer bullet points over paragraphs" , user_id = "user_1" )
# Future responses use bullet points
2. Domain Knowledge
Learn facts and information from interactions:
agent.run( "Our API rate limit is 1000 requests/hour" , user_id = "admin" )
# Agent remembers and uses this information
3. Task Patterns
Learn successful approaches to tasks:
agent.run( "When analyzing code, always check for edge cases first" )
# Agent prioritizes edge cases in future code analysis
4. Error Corrections
Learn from mistakes:
agent.run( "That calculation was wrong. Always use parentheses for order of operations" )
# Agent improves future calculations
Accessing Learnings
from agno import Agent
agent = Agent( model = "gpt-4o" , db = db, learning = True )
# Run some interactions
agent.run( "Training data..." , user_id = "user_1" )
# Access learning machine
if agent.learning_machine:
# Get learnings for user
learnings = agent.learning_machine.get_learnings( user_id = "user_1" )
for learning in learnings:
print (learning.content)
Combining Learning Features
from agno import Agent
from agno.memory import MemoryManager
from agno.db.sqlite import SQLiteDb
db = SQLiteDb( db_file = "agent.db" )
agent = Agent(
model = "gpt-4o" ,
db = db,
# Memory for facts
memory_manager = MemoryManager( db = db),
update_memory_on_run = True ,
add_memories_to_context = True ,
# Learning for patterns and preferences
learning = True ,
add_learnings_to_context = True ,
# History for context
add_history_to_context = True ,
)
# Agent uses all three:
# - Memory: Remembers user facts
# - Learning: Learns preferences and patterns
# - History: Maintains conversation context
Best Practices
Enable database : Learning requires a database to store patterns
User IDs : Use consistent user IDs for personalized learning
Feedback loops : Encourage users to provide feedback
Privacy : Implement proper data governance for learned information
Monitoring : Review what the agent is learning
Combining features : Use with memory and history for best results
Clear learnings : Provide option to clear learned patterns
Use Cases
Personal assistants : Learn user preferences and habits
Customer support : Learn effective resolution patterns
Educational tutors : Adapt to student learning style
Code assistants : Learn project conventions and patterns
Sales agents : Learn effective sales approaches
Healthcare : Learn patient communication preferences
Limitations
Requires database for persistence
Learning quality depends on interaction volume
May need periodic review and cleanup
Privacy considerations for learned data
Requires user IDs for personalized learning