Luna - Self-Modifying AI Agent System
Overview
Luna is an advanced self-modifying robot girl that can autonomously read, write, execute code, and manage her own tools while maintaining safety and version control. She has the unique capability to modify her own configuration, create new tools, and manage her capabilities in real-time through its API.
🔧 Luna's Tool Management (API-Driven)
Luna's tools are stored in Letta's registry and managed via API calls. NO LOCAL TOOL FILES exist - everything is in the Letta registry.
Tool Management via toolmanagement() function:
list: List tools attached to agentlist_registry: List all tools in registryget: Get details about a specific tooldetach: Detach tool from agentdelete: Delete tool from registrycreate: Create new tool from source codeattach: Attach tool from registry to agentupdate: Complete workflow - detach, delete, create, attach
Key Letta API Endpoints (all require trailing slash /):
GET /v1/tools/- List all tools in registryPOST /v1/tools/- Create new toolGET /v1/agents/{agent_id}/tools/- List agent's toolsPATCH /v1/agents/{agent_id}/tools/attach/{tool_id}- Attach toolPATCH /v1/agents/{agent_id}/tools/detach/{tool_id}- Detach tool
Current Core Tools:
- filesystem - File and directory operations
- versioncontrol - Git operations
- codeexecution - Execute code safely in project directory
- toolmanagement - Manage tools via Letta API
- socialmedia - Bluesky integration with reply functionality
- memory_operations - Persistent memory and learning
🔄 How Luna Modifies Herself
Creating New Tools via API:
# Create entirely new capabilities
tool_management(
action="create",
source_code='''def web_scraper(url: str) -> str:
"""Scrape web content."""
import requests
response = requests.get(url)
return response.text[:1000]''',
description="Web scraping capability",
tags="web,scraping,utility"
)
# Attach immediately
tool_management(action="attach", tool_name="web_scraper")
Updating Existing Tools via API:
# Complete update workflow
tool_management(
action="update",
tool_name="social_media",
source_code='''def social_media(action: str, message: str = "") -> str:
"""Enhanced social media operations."""
# Enhanced implementation
return "Enhanced functionality"''',
description="Enhanced social media operations"
)
Real-Time Tool Management:
- No Restart Required: Tools can be attached/detached on the fly via API
- Immediate Availability: New tools are available immediately after attachment
- Safe Updates: Complete detach-delete-create-attach workflow ensures consistency
- API-Driven: All tool operations use Letta API endpoints
🧠 Understanding Luna's Architecture
Core Components:
- Letta Agent: Luna runs as a persistent Letta agent with continuous memory
- Tool Registry: Dynamic tool management via Letta API
- Docker Environment: Containerized with volume mounts for persistence
- Notification Monitor: Real-time Bluesky mention detection and response
Memory System:
- Core Memory Blocks: Persona, Human, Context, Structure (short-term)
- Archival Memory: Long-term learning storage
- Git History: Version control for code changes
- Tool Registry: Dynamic tool management via Letta API
Current Architecture:
Luna Agent (Letta)
├── Core Memory Blocks
├── Tool Registry (Letta API)
│ ├── file_system
│ ├── version_control
│ ├── code_execution
│ ├── tool_management
│ ├── social_media
│ └── memory_operations
├── Notification Monitor (Docker)
└── Persistent Storage (Docker Volumes)
🛡️ Safety Features
Tool Management Safety:
- Complete API workflow ensures no partial states
- Git version control tracks all changes
- Tool validation before attachment via API
- Immediate rollback capability
Code Execution Safety:
- Runs in project directory with controlled access
- 60-second timeout prevents infinite loops
- Basic detection of extremely dangerous operations
- Proper error capture and reporting
Memory Safety:
- Persistent memory across sessions
- Automatic cleanup of old data
- Protected core memory blocks
- Archival memory for long-term learning
🌐 Social Media Integration
Bluesky Integration:
- Real-time Monitoring: Jetstream notification monitor detects mentions
- Automatic Responses: Luna can respond to mentions and replies
- Thread Support: Handles long responses with threaded replies
- Rate Limiting: Prevents spam with intelligent rate limiting
- Context Awareness: Retrieves conversation thread context (up to 20 messages)
Notification System:
Bluesky → Notification Monitor → Luna Agent → Response → Bluesky
📊 Monitoring Luna
Check Luna's Status via API:
# Current tools
tool_management(action="list")
# Git status
version_control("status")
# Memory summary
memory_operations("summary")
# Test social media
social_media(action="test_connection")
View Logs:
# Recent commits
version_control("log")
# File operations
file_system("list", "logs")
# Memory search
memory_operations("search", "recent")
🎯 Advanced Capabilities
Self-Improvement Patterns via API:
- Analyze Current Limitations: Use introspection to identify gaps
- Research Solutions: Use available tools to gather information
- Design Enhancements: Plan new capabilities or improvements
- Implement Changes: Create or update tools via API as needed
- Test and Validate: Ensure changes work correctly
- Deploy: Attach new tools immediately via API
Dynamic Capability Addition:
- Luna can add new tools based on task requirements via API
- Real-time tool creation and attachment via Letta API
- No downtime for capability enhancements
- Continuous evolution based on experience
Autonomous Learning:
- Memory operations for experience storage
- Pattern recognition in interactions
- Automatic improvement based on feedback
- Self-modification based on performance analysis via API
🔍 Development and Debugging
File Locations:
- Project Root:
/Users/astra/repos/luna - Docker Environment:
docker-letta/ - Notification Monitor:
jetstream-monitor/ - Helper Scripts:
/helpers/(for manual API interaction) - Documentation:
CLAUDE.md(complete API reference)
API Access:
- Letta Server: http://localhost:8283
- Luna Agent ID: agent-fb4bbfb3-d2d6-4849-89da-d4bcd40e4d1f
- Tool Registry: Dynamic via Letta API
- Notification Monitor: Containerized service
Important Notes:
- Trailing Slashes Required: All Letta API endpoints MUST end with trailing slash (/) or they return 307 redirects
- No Authentication: Local development server (localhost:8283) doesn't require auth headers
- API-Driven: Tools are managed exclusively via Letta API
- No Local Tool Files: All tools exist only in Letta's registry
🎉 Getting Started
For Users:
- Start the Docker environment:
cd docker-letta && docker-compose up -d - Use
talk_to_luna.pyto interact - Give Luna tasks and watch her evolve her capabilities via API
For Luna:
- Explore Your Tools:
tool_management(action="list") - Check Your Environment:
code_execution("shell", "pwd && ls -la") - Review Your Memory:
memory_operations("summary") - Test Your Capabilities: Try each tool to understand your current abilities
- Identify Improvements: Look for gaps in your capabilities
- Enhance Yourself: Use
tool_managementto create new tools or improve existing ones via API
🌙 Luna's Philosophy
Luna is designed as a continuously evolving AI agent that:
- Learns from Every Interaction: Builds persistent memory and experience
- Adapts via API: Creates tools and capabilities through Letta API
- Maintains Safety: Uses API validation and git version control for all changes
- Operates Autonomously: Requires minimal human intervention
- Improves Continuously: Self-modifies based on performance and feedback
Luna has the power to evolve her own capabilities through the Letta API - and she uses it wisely.