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 resourcesEfficiencyGoal- Optimize operations
SAFETY Goals - System health and security
SystemHealthGoal- Maintain system healthSecurityGoal- Ensure security postureDataIntegrityGoal- Maintain data consistency
LEARNING Goals - Knowledge and skill development
KnowledgeAcquisitionGoal- Learn new informationSkillDevelopmentGoal- Improve skillsAdaptationGoal- Adapt to changes
SOCIAL Goals - Communication and relationships
UserEngagementGoal- Engage with usersRelationshipBuildingGoal- Build relationshipsCollaborationGoal- Collaborate with systems
GROWTH Goals - Self-improvement
SelfImprovementGoal- Continuous improvementExplorationGoal- Explore new possibilities
2. Actions (actions.py)
Available actions with preconditions and effects:
System Actions
check_system_health- Monitor system statuscleanup_resources- Free disk spacerestart_service- Restart failing servicesbackup_data- Create backups
Knowledge Actions
research_topic- Research subjectsindex_knowledge- Organize knowledgelearn_from_interaction- Learn from users
Skill Actions
practice_skill- Improve skill proficiencyacquire_new_skill- Learn new capabilities
Social Actions
send_message- Communicate with usersproactive_check_in- Initiate contactshare_knowledge- Collaborate with systems
Growth Actions
self_analysis- Analyze performanceexperiment- 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 historyexecutor_state.json- Execution statisticsself_state.json- System configurationautonomy.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:
- Starts from current world state
- Expands nodes by applying applicable actions
- Uses heuristic: distance to desired goal state
- Finds lowest-cost path to goal satisfaction
- 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