Files
timmy-config/allegro/goap
2026-03-31 20:02:01 +00:00
..
2026-03-31 20:02:01 +00:00
2026-03-31 20:02:01 +00:00
2026-03-31 20:02:01 +00:00
2026-03-31 20:02:01 +00:00
2026-03-31 20:02:01 +00:00
2026-03-31 20:02:01 +00:00
2026-03-31 20:02:01 +00:00
2026-03-31 20:02:01 +00:00
2026-03-31 20:02:01 +00:00
2026-03-31 20:02:01 +00:00
2026-03-31 20:02:01 +00:00
2026-03-31 20:02:01 +00:00
2026-03-31 20:02:01 +00:00

GOAP Autonomy System for Allegro-Primus Child

A comprehensive Goal-Oriented Action Planning (GOAP) system that enables true autonomous behavior for the Child (Allegro-Primus).

Overview

The GOAP Autonomy System allows the Child to:

  • Set and pursue goals independently across multiple dimensions
  • Plan action sequences using A* search to achieve goals
  • Execute plans with monitoring, retries, and error handling
  • Learn and adapt from execution experiences
  • Integrate with existing monitoring infrastructure

Architecture

┌─────────────────────────────────────────────────────────────┐
│                    GOAP Autonomy System                      │
├─────────────────────────────────────────────────────────────┤
│  ┌──────────────┐  ┌──────────────┐  ┌──────────────┐      │
│  │    Goals     │  │   Actions    │  │   Planner    │      │
│  │  (goals.py)  │  │ (actions.py) │  │ (planner.py) │      │
│  └──────┬───────┘  └──────┬───────┘  └──────┬───────┘      │
│         │                 │                 │               │
│         └─────────────────┼─────────────────┘               │
│                           ▼                                 │
│                  ┌──────────────┐                          │
│                  │   Executor   │                          │
│                  │(executor.py) │                          │
│                  └──────┬───────┘                          │
│                         │                                   │
│                         ▼                                   │
│               ┌──────────────────┐                         │
│               │   SelfGOAP       │                         │
│               │ (self_goap.py)   │  ← Integration Layer    │
│               └────────┬─────────┘                         │
│                        │                                    │
└────────────────────────┼────────────────────────────────────┘
                         │
    ┌────────────────────┼────────────────────┐
    │                    │                    │
    ▼                    ▼                    ▼
┌─────────┐      ┌──────────────┐      ┌──────────┐
│ Timmy   │      │   Gitea      │      │  System  │
│ Monitor │      │  Integration │      │  Health  │
└─────────┘      └──────────────┘      └──────────┘

Components

1. Goals (goals.py)

Five categories of goals drive autonomous behavior:

HUNGER Goals - Resource acquisition and efficiency

  • ResourceAcquisitionGoal - Acquire computational resources
  • EfficiencyGoal - Optimize operations

SAFETY Goals - System health and security

  • SystemHealthGoal - Maintain system health
  • SecurityGoal - Ensure security posture
  • DataIntegrityGoal - Maintain data consistency

LEARNING Goals - Knowledge and skill development

  • KnowledgeAcquisitionGoal - Learn new information
  • SkillDevelopmentGoal - Improve skills
  • AdaptationGoal - Adapt to changes

SOCIAL Goals - Communication and relationships

  • UserEngagementGoal - Engage with users
  • RelationshipBuildingGoal - Build relationships
  • CollaborationGoal - Collaborate with systems

GROWTH Goals - Self-improvement

  • SelfImprovementGoal - Continuous improvement
  • ExplorationGoal - Explore new possibilities

2. Actions (actions.py)

Available actions with preconditions and effects:

System Actions

  • check_system_health - Monitor system status
  • cleanup_resources - Free disk space
  • restart_service - Restart failing services
  • backup_data - Create backups

Knowledge Actions

  • research_topic - Research subjects
  • index_knowledge - Organize knowledge
  • learn_from_interaction - Learn from users

Skill Actions

  • practice_skill - Improve skill proficiency
  • acquire_new_skill - Learn new capabilities

Social Actions

  • send_message - Communicate with users
  • proactive_check_in - Initiate contact
  • share_knowledge - Collaborate with systems

Growth Actions

  • self_analysis - Analyze performance
  • experiment - Test new approaches

3. Planner (planner.py)

A* search-based planner that:

  • Finds optimal action sequences to achieve goals
  • Uses heuristics for efficient search
  • Supports replanning on failure
  • Includes plan optimization and learning

4. Executor (executor.py)

Plan execution engine with:

  • Sequential and parallel execution modes
  • Retry logic with exponential backoff
  • Execution monitoring and reporting
  • Adaptive execution based on system load

5. SelfGOAP Integration (self_goap.py)

Main integration class that:

  • Collects comprehensive world state
  • Coordinates goal management and planning
  • Schedules plan execution
  • Provides autonomous operation loop

Usage

Basic Usage

import asyncio
from goap import SelfGOAP

async def main():
    # Create GOAP system
    goap = SelfGOAP()
    
    # Run autonomy loop
    await goap.run()

if __name__ == "__main__":
    asyncio.run(main())

CLI Commands

# Run autonomy loop
python3 self_goap.py --run

# Run one cycle
python3 self_goap.py --once

# Check status
python3 self_goap.py --status

# Enable/disable autonomy
python3 self_goap.py --enable
python3 self_goap.py --disable

# Force plan for specific goal
python3 self_goap.py --plan system_health

Systemd Service

# Install service
./setup.sh

# Start/stop service
systemctl start goap-autonomy
systemctl stop goap-autonomy

# View logs
journalctl -u goap-autonomy -f

Configuration

Environment variables:

  • GOAP_LOG_LEVEL - Logging level (DEBUG, INFO, WARNING, ERROR)
  • GOAP_STATE_DIR - Directory for state persistence

State files (in /root/allegro/goap/):

  • goals_state.json - Goal satisfaction history
  • executor_state.json - Execution statistics
  • self_state.json - System configuration
  • autonomy.log - Operation log

Goal Satisfaction Thresholds

Goals are considered satisfied when:

  • System Health: Disk < 70%, Services healthy, No recent errors
  • Security: Valid credentials, Recent backup, No active alerts
  • Knowledge: > 5000 facts, > 5 topics covered
  • Skills: > 10 skills available, > 0.7 avg proficiency
  • Social: < 60s response time, > 0.8 user satisfaction

Planning Algorithm

The A* planner:

  1. Starts from current world state
  2. Expands nodes by applying applicable actions
  3. Uses heuristic: distance to desired goal state
  4. Finds lowest-cost path to goal satisfaction
  5. Supports replanning on action failure

Monitoring

The system monitors:

  • System metrics (CPU, memory, disk, uptime)
  • Knowledge base growth
  • Skill acquisition
  • User engagement
  • Plan execution success rates
  • Error rates and recovery

Extending

Adding a New Goal

from goap import Goal, GoalCategory, GoalPriority

class MyGoal(Goal):
    def __init__(self):
        super().__init__(
            name="my_goal",
            category=GoalCategory.GROWTH,
            priority=GoalPriority.MEDIUM
        )
    
    def evaluate(self, world_state):
        # Return satisfaction 0.0-1.0
        return 0.5
    
    def get_desired_state(self):
        return {'my_metric': 100}

# Register
goap.goal_manager.add_goal(MyGoal())

Adding a New Action

from goap import Action, ActionResult

class MyAction(Action):
    def __init__(self):
        super().__init__(
            name="my_action",
            cost=2.0,
            preconditions={'system.ready': True},
            effects={'my_metric': 100},
            category="custom"
        )
    
    async def execute(self, context):
        # Perform action
        return ActionResult.success_result("Done!")

# Register
goap.action_library.register(MyAction())

Testing

Run individual module tests:

# Test goals
python3 goals.py

# Test actions
python3 actions.py

# Test planner
python3 planner.py

# Test executor
python3 executor.py

# Test full integration
python3 self_goap.py --once

Files

/root/allegro/goap/
├── __init__.py           # Package initialization
├── goals.py              # Goal definitions
├── actions.py            # Action definitions
├── planner.py            # A* planner
├── executor.py           # Plan executor
├── self_goap.py          # Main integration
├── setup.sh              # Setup script
├── goap-autonomy.service # Systemd service
└── README.md             # This file

Integration with Existing Infrastructure

The GOAP system integrates with:

  • Timmy Monitor - Uses heartbeat metrics for social goals
  • Gitea - Monitors repositories for actionable items
  • Heartbeat Daemon - Coordinates 15-minute wakeups
  • SQLite Database - Reads metrics from timmy_metrics.db

License

MIT License - Allegro-Primus Project