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
  • 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


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.2.0.tar.gz (26.9 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.2.0-py3-none-any.whl (25.1 kB view details)

Uploaded Python 3

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

Hashes for xmemo-0.2.0.tar.gz
Algorithm Hash digest
SHA256 b5d01945f2e09e6dd266fbb1809602432f518f24595d6011cf08ea2a002b4524
MD5 ec2a9cb37e3cfe22ca036c128c70b3ae
BLAKE2b-256 583366068681291c6c8c7de48e56429e5c98a063d9f9c739e2c50b8eb39ff474

See more details on using hashes here.

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

Hashes for xmemo-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e5e79b8d6856b8933ab44ba71f4239f3528e74011d413ce7d236ef5c24f7a739
MD5 d6f0ec7edd869f3a628cb2feda40ba18
BLAKE2b-256 4e94ed99085fca0cd6a428db6ac54e164002185036eae203e0f34ae5d80acafe

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