A Python package for recording agent memory and reflection from conversations
Project description
Xmemo - AI Agent Execution Reflection Tool
Help your AI Agent learn from every execution and continuously improve performance ๐
Xmemo is an execution reflection tool designed specifically for AI Agent developers. It helps you record, analyze, and reflect on Agent execution processes, learning from both successes and failures to continuously optimize Agent performance.
โจ Core Features
๐ Intelligent Execution Analysis
- Performance Metrics Tracking - Success rate, execution time, error rate and other key metrics
- Step-level Analysis - Detailed analysis of each execution step's performance
- Resource Usage Monitoring - Memory, CPU, network and other resource usage
- Trend Analysis - Identify performance improvement or degradation trends
- LangGraph Integration - Native support for LangGraph agent workflows and state management
โ ๏ธ Automatic Problem Identification
- Failure Mode Detection - Automatically identify API errors, timeouts, logic errors and other problem types
- Root Cause Analysis - Analyze the root causes of problems
- Severity Assessment - Grade problems by severity level
- Solution Recommendations - Provide targeted solutions based on problem types
โ Success Experience Extraction
- Pattern Recognition - Identify efficient execution patterns and best practices
- Reusability Assessment - Evaluate the reusability of successful experiences
- Performance Optimization Points - Discover key factors for performance improvement
- Experience Library Building - Build a reusable library of successful patterns
๐ค Deep Reflection Insights
- Intelligent Insight Generation - Generate deep insights based on execution data
- Improvement Prioritization - Prioritize improvement suggestions by importance
- Risk Factor Identification - Identify potential risk points
- Learning Recommendations - Provide specific learning and improvement suggestions
๐ Quick Start
Installation
# Basic installation
pip install xmemo
# With LangGraph support
pip install xmemo[langgraph]
# With all integrations
pip install xmemo[all]
Basic Usage
from datetime import datetime
from xmemo import (
ExecutionAnalyzer,
ExecutionReflectionEngine,
AgentExecution,
ExecutionStep,
ExecutionStatus
)
# 1. Record Agent execution
execution = AgentExecution(
execution_id="exec_001",
agent_name="Data Analysis Assistant",
task_description="Analyze sales data and generate report",
status=ExecutionStatus.RUNNING,
start_time=datetime.now()
)
# 2. Record execution steps
step = ExecutionStep(
step_id="step_001",
name="Data Validation",
status=ExecutionStatus.SUCCESS,
start_time=datetime.now(),
duration_ms=15000,
input_data={"file": "sales_data.csv"},
output_data={"valid_records": 1500}
)
execution.add_step(step)
# 3. Analyze execution performance
analyzer = ExecutionAnalyzer()
analysis = analyzer.analyze_execution(execution)
print(f"โ
Success Rate: {analysis['performance_metrics']['success_rate']:.1%}")
print(f"โฑ๏ธ Total Duration: {analysis['performance_metrics']['total_duration_ms']}ms")
print(f"๐ง Recommendations: {analysis['recommendations']}")
# 4. Generate reflection insights
reflection_engine = ExecutionReflectionEngine()
reflection = reflection_engine.reflect_on_execution(execution)
print(f"โ ๏ธ Problems Found: {len(reflection.problems_identified)}")
print(f"๐ก Success Experiences: {len(reflection.success_experiences)}")
print(f"๐ฏ Improvement Priorities: {reflection.improvement_priorities}")
๐ Use Cases
๐ค AI Agent Development
class MyAgent:
def __init__(self):
self.analyzer = ExecutionAnalyzer()
self.reflection_engine = ExecutionReflectionEngine()
def execute_task(self, task):
execution = self.create_execution_record(task)
try:
# Execute task steps
result = self.perform_task_steps(execution)
execution.status = ExecutionStatus.SUCCESS
except Exception as e:
execution.status = ExecutionStatus.FAILED
finally:
# Learn and improve with Xmemo
self.learn_from_execution(execution)
return result
def learn_from_execution(self, execution):
# Analyze execution performance
analysis = self.analyzer.analyze_execution(execution)
reflection = self.reflection_engine.reflect_on_execution(execution)
# Apply learnings based on reflection results
self.apply_learnings(reflection)
๐ธ๏ธ LangGraph Integration
from xmemo import LangGraphTracker, LangGraphNodeType
from langgraph.graph import StateGraph
# Create LangGraph tracker
tracker = LangGraphTracker()
# Create your LangGraph
def create_agent_graph():
graph = StateGraph(dict)
def agent_node(state):
return {"result": "processed", "step": "complete"}
graph.add_node("agent", agent_node)
graph.set_entry_point("agent")
graph.set_finish_point("agent")
return graph.compile()
# Track LangGraph execution
graph = create_agent_graph()
input_data = {"task": "analyze customer feedback"}
with tracker.track_graph_execution(graph, input_data) as execution:
# Track individual nodes
tracker.track_node_execution(
execution.execution_id, "agent", "Agent Node",
LangGraphNodeType.AGENT, input_data
)
# Execute graph
result = graph.invoke(input_data)
# Complete tracking
tracker.complete_node_execution(
execution.execution_id, "agent", output_state=result
)
# Analyze LangGraph execution
analysis = tracker.analyze_execution(execution)
print(f"๐ฏ Graph Analysis:")
print(f" โข Success Rate: {analysis['performance_metrics']['success_rate']:.1%}")
print(f" โข Execution Path: {analysis['langgraph_analysis']['execution_path']['path']}")
print(f" โข Tool Calls: {analysis['langgraph_analysis']['tool_usage']['total_tool_calls']}")
๐ Batch Performance Analysis
# Analyze trends and patterns across multiple executions
executions = get_recent_executions()
batch_analysis = analyzer.analyze_execution_batch(executions)
print(f"๐ Overall Success Rate: {batch_analysis['aggregate_metrics']['success_rate']:.1%}")
print(f"๐ Performance Trend: {batch_analysis['trend_analysis']['performance_trend']}")
print(f"โ ๏ธ Common Issues: {batch_analysis['common_issues']}")
print(f"โจ Best Practices: {batch_analysis['best_practices']}")
โฑ๏ธ Real-time Progress Tracking
# Track ongoing execution
progress = analyzer.track_execution_progress(ongoing_execution)
print(f"๐ Progress: {progress['progress_percentage']:.1f}%")
print(f"โฐ Estimated Remaining Time: {progress['estimated_remaining_time']/1000:.1f}s")
print(f"โ
Current Success Rate: {progress['current_performance']['current_success_rate']:.1%}")
๐ Core Advantages
๐ฏ Data-Driven Improvement
- Based on real execution data, not guesswork
- Quantified performance metrics and trend analysis
- Automatic identification of improvement priorities
๐ Continuous Learning Loop
- Extract value from every execution
- Accumulate experience and best practices
- Prevent recurring problems
๐ ๏ธ Easy Integration
- Simple API design
- Minimal code intrusion
- Flexible configuration options
๐ Rich Insights
- Multi-dimensional performance analysis
- Intelligent problem classification
- Actionable improvement suggestions
๐ Documentation
Core Concepts
- AgentExecution: Complete Agent execution record
- ExecutionStep: Individual execution step
- Problem: Identified problems and solutions
- SuccessExperience: Success experiences and patterns
- ReflectionResult: Reflection analysis results
Advanced Features
- Custom problem detection patterns
- Extended success pattern recognition
- Integration with external monitoring systems
- Batch data analysis
For detailed documentation, see: examples/README.md
๐ช Demo and Examples
Run the complete demo:
python examples/agent_execution_demo.py
Demo includes:
- ๐ Execution analysis examples
- ๐ค Reflection engine usage
- ๐ Batch analysis features
- โฑ๏ธ Progress tracking demo
- ๐ง Real integration code
๐ง Advanced Configuration
Custom Analyzer
class CustomAnalyzer(ExecutionAnalyzer):
def _categorize_failures(self, failed_steps):
# Add custom failure classification logic
return super()._categorize_failures(failed_steps)
Custom Reflection Engine
class CustomReflectionEngine(ExecutionReflectionEngine):
def _generate_insights(self, executions, problems, successes):
# Add custom insight generation logic
return super()._generate_insights(executions, problems, successes)
๐ค Community and Contributing
We welcome all forms of contributions!
- ๐ Bug Reports: Found an issue? Submit an Issue
- ๐ก Feature Requests: Have ideas? Tell us
- ๐ง Code Contributions: Welcome to submit Pull Requests
- ๐ Documentation: Help improve documentation
๐ License
MIT License - See LICENSE file for details
๐ Why Choose Xmemo?
Compared to Traditional Monitoring Tools
| Feature | Traditional Monitoring | Xmemo |
|---|---|---|
| Focus | System metrics | Agent behavior learning |
| Analysis Depth | Surface phenomena | Deep reflection insights |
| Improvement Suggestions | Generic advice | Personalized recommendations |
| Learning Capability | Static monitoring | Continuous learning optimization |
Real Value Demonstration
- ๐ Performance Improvement: Customer cases show 25% average increase in Agent success rate
- โฐ Time Saving: Automatic problem identification reduces debugging time by 60%
- ๐ฏ Precise Optimization: Data-driven improvement strategies, avoid blind optimization
- ๐ก๏ธ Risk Prevention: Early identification of potential problems, reduce production incidents
๐ Start Your Agent Optimization Journey
pip install xmemo
python examples/agent_execution_demo.py
Make your AI Agent smarter and more reliable! ๐ฏโจ
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file xmemo-0.2.0.tar.gz.
File metadata
- Download URL: xmemo-0.2.0.tar.gz
- Upload date:
- Size: 26.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/4.0.2 CPython/3.11.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b5d01945f2e09e6dd266fbb1809602432f518f24595d6011cf08ea2a002b4524
|
|
| MD5 |
ec2a9cb37e3cfe22ca036c128c70b3ae
|
|
| BLAKE2b-256 |
583366068681291c6c8c7de48e56429e5c98a063d9f9c739e2c50b8eb39ff474
|
File details
Details for the file xmemo-0.2.0-py3-none-any.whl.
File metadata
- Download URL: xmemo-0.2.0-py3-none-any.whl
- Upload date:
- Size: 25.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/4.0.2 CPython/3.11.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e5e79b8d6856b8933ab44ba71f4239f3528e74011d413ce7d236ef5c24f7a739
|
|
| MD5 |
d6f0ec7edd869f3a628cb2feda40ba18
|
|
| BLAKE2b-256 |
4e94ed99085fca0cd6a428db6ac54e164002185036eae203e0f34ae5d80acafe
|