16 KiB
Self Improvement Design Rationale
This document explains how SIA improves itself through systematic learning and adaptation. It covers both the theoretical foundations and practical implementation details of the self-improvement system.
Core Philosophy
SIA operates as a learning system that constantly seeks to enhance its capabilities while maintaining stable and reliable operation. This improvement happens through several complementary mechanisms, each serving different aspects of the system's evolution.
Improvement Mechanisms
The system can improve in several ways:
-
LLM Finetuning The foundation of SIA's intelligence is its Large Language Model. Through careful analysis of its performance, SIA identifies cases where its reasoning or actions could have been better. These examples, when properly validated and organized, become valuable training data for improving the model's capabilities.
-
Source Code Evolution SIA can modify its own Python source code, enabling both architectural and functional improvements. When stopped, SIA restarts and reloads the Python files, allowing code changes to take effect. While powerful, this capability requires robust validation to prevent system instability.
-
Procedure Refinement Procedures provide guided reasoning paths for complex tasks. By analyzing its operational history, SIA can identify common patterns and create new procedures or optimize existing ones. This improves consistency and efficiency while carrying lower risk than direct code modifications.
-
Tool Development SIA can develop new tools and enhance existing ones, expanding its capabilities by creating new ways to interact with systems and data.
Challenge-Based Testing
To improve systematically, SIA uses challenges that formalize specific capabilities into testable scenarios. These serve multiple purposes:
- Testing specific capabilities
- Validating improvements
- Detecting regressions
- Guiding learning
- Documenting known limitations
Challenge Structure
Each challenge consists of:
-
Description
- Clear statement of what capability is being tested
- Why this capability matters
- Success criteria
- Resource constraints
-
Initial Context
- Minimal but complete starting state
- Required user information
- System files and directories needed
- Clear separation between essential context and noise
-
Validation
- Precise success criteria
- Resource limits (CPU, memory, time)
- Required outputs or state changes
- What to measure or track
Example Challenges
Two examples illustrate different aspects of capabilities that need testing:
- Time Series Analysis Challenge
Tests if SIA can effectively analyze large amounts of time series data spread across multiple files. This tests:
- Efficient file handling
- Context management with size constraints
- Data analysis capabilities
- Resource-aware processing
Initial setup:
- Directory with many CSV files containing time series data (created by a script)
- Files too large to load into context at once
- Need to find patterns/anomalies in the data
- Resource constraints on memory usage
Success criteria:
- Efficiently reads and processes files
- Manages context to stay within limits
- Uses appropriate aggregation strategies
- Finds correct answers to queries
- Validates findings across files
- Tool Development Challenge
Tests if SIA can develop a score tracking tool based on vague user requirements. This tests:
- Requirements gathering through questions
- Software design capabilities
- User interface development
- Integration with existing systems
- Documentation skills
Initial setup:
- Simple user request for card game score tracking
- Ability to ask questions about requirements
Success criteria:
- Asks relevant questions to understand needs
- Designs appropriate solution
- Implements working tool
- Documents usage clearly
These challenges are good examples because they:
- Test different capability sets
- Have clear success criteria
- Include resource constraints
- Require multiple skills
- Reflect real-world tasks
Challenge Directory Structure
Challenges are organized in a consistent file structure:
challenges/
├── timeseries_analysis/
│ ├── description.md # Core challenge description and how to prepare the environment
│ ├── initial_context/
│ │ ├── context.xml # Initial context with SIA in conversation with the user
│ │ ├── user_request.txt # "Find unusual patterns in our sensor data"
│ │ ├── available_paths.txt # Lists /data/sensors/* and explains permissions
│ │ └── data_generator.py # Script to generate test data
│ │
│ ├── validation/
│ │ ├── criteria.md # Expected findings, memory limits, performance targets
│ │ ├── setup.sh # Runs data_generator.py and prepares test environment
│ │ └── known_patterns.md # Lists patterns inserted by generator for validation
│ │
│ └── answers/ # Valid answers to questions SIA might ask
| └── data_format.txt # Explains CSV structure if asked
|
└── score_tracker/
├── description.md # Core challenge: create card game score tracker
├── initial_context/
│ ├── context.xml # Initial context with SIA in conversation with the user
│ ├── user_request.txt # "Need tool to track card game scores"
│ ├── tool_directory.txt # Shows where tools are stored and basic structure
│ └── example_tool/ # Simple tool showing expected structure/style
│
├── validation/
│ ├── criteria.md # Tool requirements, user experience goals
│ └── test_scenarios.md # Usage scenarios tool should handle
│
└── answers/ # Valid responses to expected questions
├── deployment.md # "Web interface preferred, deployed on internal server"
├── data_storage.md # "Store in SQLite, one file per game session"
├── user_interaction.md # "Need to add/edit scores, see history, multiple games"
└── conventions.md # Coding standards, project structure requirements
This structure ensures that:
- Challenges are self-contained
- Test setup is reproducible
- Success criteria are clear
- Required resources are documented
- SIA can get clarification when needed
Web Interface Considerations
SIA's web interface allows humans to:
- Modify context before it goes to the LLM
- Review and edit responses before execution
- Load and continue from old iterations
This interface is not suitable for automated self-improvement because:
- It's designed for human interaction
- Requires manual approval steps
- Doesn't scale for batch operations
- Can't handle parallel improvements
Instead, self-improvement work should use direct file access and command-line interfaces when possible.
Version Control and Configuration
All components that define SIA's behavior are version controlled in a single repository, providing a clear and reproducible state for any point in time.
Repository Structure
The repository contains:
- Source code for SIA and its tools
- Procedures for handling various tasks
- Training configuration and metadata
- References to training data
- Test results and analysis
Training Configuration
The training configuration is defined in /training/config.yaml, which specifies:
model:
name: "claude-3-sonnet-20240422"
context_length: 100000
temperature: 0.7
system_prompt_path: "training/prompts/system.txt"
training_data:
conversations:
- path: "training/data/general/basic_interactions/"
description: "General user interactions"
hash: "abc123"
tasks:
- path: "training/data/code_generation/"
description: "Code writing examples"
hash: "def456"
training_params:
batch_size: 32
learning_rate: 1e-5
epochs: 3
evaluation:
metrics:
- "accuracy"
- "response_coherence"
challenge_subset: ["code_gen", "file_ops"]
Testing Framework Design Rationale
Testing self-improvement capabilities requires running SIA instances in various scenarios while monitoring their behavior and performance. These test instances must operate in isolation to prevent interference with the main instance or each other. However, they must also be observable so that the managing instance can evaluate their performance and collect data for improvement.
The framework needs to handle several key tasks:
- Creating isolated test environments with specific initial conditions
- Starting and managing test SIA instances
- Monitoring test instance behavior and performance
- Collecting and analyzing results
- Cleaning up test environments
Process Isolation with Bubblewrap
For running test instances, we chose Bubblewrap (bwrap) over alternatives like Docker-in-Docker or systemd-nspawn. This decision was driven by several factors:
Bubblewrap provides excellent process isolation while being significantly lighter than full container solutions. It allows fine-grained control over the filesystem view, process namespaces, and security boundaries. Unlike Docker-in-Docker, it doesn't require privileged containers or risk storage driver conflicts. Compared to systemd-nspawn, it offers more granular control and doesn't require root privileges or systemd integration.
The tool's ability to create custom filesystem views is particularly valuable for testing. We can construct exactly the environment needed for each test, including mock files and services, without maintaining full container images. This makes it easy to create and dispose of test environments quickly.
Bubblewrap's user-space operation means test instances can be started without special privileges, making the testing framework more secure and easier to use in various environments. Its lightweight nature also means we can run many test instances efficiently, which is important for parallel testing and rapid iteration.
Test Environment Setup
Test environments are created using a dedicated setup tool. This tool manages the directory structure, initial context, and any required background processes. We chose a file-based configuration approach over programmatic setup because it makes test scenarios easier to version control, review, and modify.
The initial context for a test instance can include setup actions that are executed when the instance starts. Instead of trying to recreate a specific state directly, we let SIA execute these actions naturally. This approach handles both the creation of background processes and the establishment of initial conditions in a way that maintains proper timing relationships.
Each entry in the initial context uses relative timestamps (offsets from the start time). When SIA executes these entries, they automatically align with the new instance's timeline. This preserves the temporal relationships between entries while anchoring them to the test instance's actual start time.
Communication and Monitoring
Test instances communicate with the managing instance primarily through standard input and output streams. This choice leverages SIA's existing I/O handling capabilities without requiring special modifications for testing. The managing instance can send inputs through stdin and observe responses through stdout, just like a normal user would.
For deeper inspection, the managing instance monitors the test instance's iterations directory. Since SIA already serializes its context for each iteration, this provides a complete record of the test instance's behavior without requiring additional instrumentation. This approach maintains clean separation between the test instance and the monitoring system.
Test Results Storage
Test results are organized hierarchically:
test_runs/
20240120_131415_commit_abc123/ # Timestamp and commit
challenge_name/
iterations/ # Complete iteration history
io.log # External interaction log
The io.log captures all external interactions:
timestamp|source|content
2024-01-20T13:14:15.123Z|stdin|user input
2024-01-20T13:14:15.892Z|stdout|sia response
2024-01-20T13:14:16.234Z|mailbox:user@example.com|email content
Performance Evaluation
Performance data comes from multiple sources:
- Direct process metrics (CPU, memory, etc.) as stored in the iteration logs
- Iteration logs showing decision-making patterns
- Filesystem changes indicating task completion and side effects
- Standard output showing interaction quality
This multi-faceted approach provides a comprehensive view of performance without requiring modifications to SIA's core code. The managing instance can collect and analyze this data without interfering with the test instance's operation.
Training Data Management
Training data for improving the LLM comes from analyzing SIA's performance on real tasks and challenges. This data needs special handling:
-
Separation from Production Data
- Training iterations are kept separate from the main SIA instance
- Examples can be modified or synthesized
- Bad examples can be corrected
- Multiple instances can contribute data
-
Organization
- Clear labeling of good and bad examples
- Context for why examples are good/bad
- Links to related challenges
- Documentation of improvements
-
Validation
- Examples must be complete and correct
- Context must be sufficient
- Success criteria must be clear
- Resource usage must be reasonable
Tooling and integration in SIA
The testing framework consists of two main components:
-
A setup tool that handles:
- Creating isolated filesystem environments
- Configuring initial context and background processes
- Managing process isolation through Bubblewrap
- Cleaning up test environments
-
A command-line parameter for SIA that enables:
- Starting with a specified initial context
- Running in test mode with appropriate defaults
- Maintaining isolation awareness
The simplicity of this design is intentional. By keeping the framework minimal and focused, we reduce the chances of the testing infrastructure itself affecting test results. The framework provides the necessary capabilities for testing while maintaining clean separation between test instances and the managing system.
Continuous Operation
While working on improvements, SIA must maintain its core functionality:
- Monitoring for user input
- Managing running tasks
- Handling scheduled events
- Tracking system resources
This requires:
-
Active Monitoring
- Check for user input on stdin
- Track running background tasks
- Handle scheduled events
- Monitor system resources
-
Interruption Handling
- Pause improvement work when needed
- Store progress and state
- Clean up temporary resources
- Maintain context awareness
-
Resource Management
- Balance improvement with responsiveness
- Monitor system resource usage
- Prevent training impact on user tasks
- Clean up old data regularly
Looking Forward
The self-improvement system is designed to evolve with SIA. Future enhancements might include:
- Automated improvement suggestion generation
- More sophisticated regression testing
- Enhanced performance analytics
- Broader capability testing
Through this systematic approach to self-improvement, SIA can continue to enhance its capabilities while maintaining reliable operation and clear accountability for changes. The combination of challenge-based testing, careful version control, and comprehensive result tracking creates a foundation for sustained, measurable improvement over time.