Skip to main content

A Python package for recording agent memory and reflection from conversations

Project description

Xmemo - AI Agent Execution Reflection Tool

Python 3.10+ PyPI version License: MIT

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

โš ๏ธ 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

pip install xmemo

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)

๐Ÿ“ˆ 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

xmemo-0.1.12.tar.gz (23.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

xmemo-0.1.12-py3-none-any.whl (19.1 kB view details)

Uploaded Python 3

File details

Details for the file xmemo-0.1.12.tar.gz.

File metadata

  • Download URL: xmemo-0.1.12.tar.gz
  • Upload date:
  • Size: 23.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.7

File hashes

Hashes for xmemo-0.1.12.tar.gz
Algorithm Hash digest
SHA256 d4f8eca570b7329d12563706d4d0641b463f2f936d03c5eec56affa873df8286
MD5 bd792cc15c81c22007ef5db6dcdae109
BLAKE2b-256 24f6a9719bf7878b72231e5bf77d0d9cfbfa3c7ef126def21970589fb7e9b13b

See more details on using hashes here.

File details

Details for the file xmemo-0.1.12-py3-none-any.whl.

File metadata

  • Download URL: xmemo-0.1.12-py3-none-any.whl
  • Upload date:
  • Size: 19.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.7

File hashes

Hashes for xmemo-0.1.12-py3-none-any.whl
Algorithm Hash digest
SHA256 c0a11350e3fe0155b036e6f8a9ca2d2ffc683ca52100a56d70663ebdc01d0b30
MD5 2a16080b171500fdcb872d352cbaa7b0
BLAKE2b-256 a583d833e73146605f9da0b4f4c393a6e28bad7127f62f173c3d1331cdf830a7

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page