This is an updatable Linux activity agent that runs in a continuous loop and supports automatic updates through a mutex system.
- Continuous Operation: Runs in a
while Trueloop performing agent tasks - Automatic Updates: Monitors for new versions and updates itself through the mutex system
- Mutex-based User Isolation: Ensures only one agent instance per user/template
- Database Integration: Loads configuration from PostgreSQL database
- Application Simulation: Simulates user activity in various applications
- Heartbeat Support: Sends regular status updates to backend
- Plugin System: Supports loading custom plugins for extended functionality
- Python 3.8+
- PostgreSQL database with the required schema
- Nuitka for compilation
- Required Python packages:
- psycopg2
- psutil
- Other dependencies as specified in the agent
The agent expects a PostgreSQL database with the following configuration:
DATABASE_CONFIG = {
"host": "127.0.0.1",
"port": 5432,
"database": "lisa_dev",
"user": "lisa",
"password": "pass"
}Make sure your database contains:
behavior_templatestable with user templatesapplications_templatetable with application configurationsagentstable for agent registrationagent_buildstable for tracking builds
Use the provided builder script to compile the agent:
# Build agent for a specific template
python3 fixed_updatable_agent_builder.py build <template_id> --name <agent_name>
# Example
python3 fixed_updatable_agent_builder.py build 1 --name agent_template_1The compiled binary will be placed in /opt/agent_builds/ by default.
Deploy the compiled agent to the target location:
# Deploy agent
python3 fixed_updatable_agent_builder.py deploy <template_id> <user_id>
# Example
python3 fixed_updatable_agent_builder.py deploy 1 USER_001Run the compiled agent directly:
# Run with template ID and user ID
./agent <template_id> <user_id>
# Example
./agent 1 USER_001The deployment script creates a systemd service. You can manage it with:
# Start the agent
sudo systemctl start activity-agent-template-1-user-USER_001
# Enable auto-start on boot
sudo systemctl enable activity-agent-template-1-user-USER_001
# Check status
sudo systemctl status activity-agent-template-1-user-USER_001
# View logs
sudo journalctl -u activity-agent-template-1-user-USER_001 -f
# Stop the agent
sudo systemctl stop activity-agent-template-1-user-USER_001Once launched, the agent will:
- Initialize: Connect to database, load configuration, acquire mutex
- Main Loop: Continuously run in a
while Trueloop:- Check for updates every 5 minutes through the mutex system
- Perform agent tasks based on work schedule
- Simulate user activities in applications
- Handle inactive periods (breaks, non-work hours)
- Send heartbeats to backend (if enabled)
The agent monitors for updates automatically:
- Update Check: Every 5 minutes, the agent checks the database for new builds
- Version Comparison: Compares current version hash with latest build
- Self-Update: If a new version is found:
- Launches the new binary
- New instance acquires mutex (killing old instance)
- Seamless transition with minimal downtime
To update an agent manually:
-
Build New Version:
# Make changes to complete_updatable_agent.py # Then build python3 fixed_updatable_agent_builder.py build <template_id>
-
Deploy New Version:
python3 fixed_updatable_agent_builder.py deploy <template_id> <user_id>
-
Restart Service (if using systemd):
sudo systemctl restart activity-agent-template-1-user-USER_001
The update process works through the mutex system:
- New agent binary is deployed to the system
- Running agent detects new version in database
- Running agent launches new binary
- New binary tries to acquire mutex for the user
- Mutex manager detects existing agent and sends SIGTERM
- Old agent performs graceful shutdown
- New agent acquires mutex and starts operation
List all running agents:
python3 fixed_updatable_agent_builder.py list-runningList available builds:
python3 fixed_updatable_agent_builder.py list-buildsLogs are written to:
/var/log/activity_agent/updatable_agent.log(if permissions allow)/tmp/updatable_agent.log(fallback)
Mutex lock files are stored in:
/var/run/activity_agents/(primary)/tmp/activity_agents/(fallback)
Format: agent_user_<user_id>_template_<template_id>.lock
Defined in the behavior template:
{
"work_schedule": {
"start_time": "09:00",
"end_time": "18:00",
"breaks": [
{"start": "12:00", "duration_minutes": 60}
]
}
}Applications can be:
- Built-in: Hardcoded in the agent (Terminal, Firefox, VSCode, etc.)
- Database: Defined in
applications_templatetable - Plugins: Loaded from plugin directory
HEARTBEAT_CONFIG = {
"enabled": True,
"backend_url": "http://localhost:8000/api/agents/heartbeat",
"interval_hours": 24,
"include_statistics": True,
"api_key": "sk-agent-heartbeat-key-2024"
}- Check database connectivity
- Verify template exists in database
- Check mutex directory permissions
- Review logs for errors
- Verify new build exists in database
- Check update monitoring is enabled
- Ensure mutex system is working
- Check agent has permission to launch new processes
The mutex system prevents multiple instances. If you see duplicates:
- Check mutex files in
/var/run/activity_agents/ - Manually remove stale lock files
- Use
pkillto terminate orphaned processes
- Database Credentials: Store securely, consider using environment variables
- Mutex Permissions: Ensure proper permissions on mutex directories
- Binary Permissions: Compiled agents should have appropriate execute permissions
- Update Security: Verify binary integrity before auto-updates
To modify the agent:
- Edit
complete_updatable_agent.py - Test changes locally
- Build new version with the builder
- Deploy and monitor the update process
For issues or questions:
- Check agent logs
- Verify database connectivity
- Review systemd service status
- Examine mutex lock files