agentleFS
bowen31337bowen31337/autonomous-agent-framework/SKILL.md

long-running-agent

Skill0 starsChanged 10 months agoMITView on GitHub

Build autonomous, long-running AI agents that parse PRDs/specifications into structured task lists and execute them autonomously with state persistence, error recovery, and cross-session resumption. Works with any agent framework (Cursor, OpenCode, etc.).

6 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use skill-creator.

Other files people use alongside this one.

Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
  • SentrySkill

    skill-creator

    Create new agent skills following the Agent Skills specification. Use when asked to "create a skill", "add a new skill", "write a skill", "make a skill", "build a skill", or scaffold a new skill with SKILL.md. Guides through requirements, writing, registration, and verification.

    Also in 4 projects that use this

  • Other versions6 projects use a version of this.

    Word for word · 0

    None found.

    Edited · 0

    None found.

    Wrote their own version · 6

    1. mikeOnBreeze/cc-crossbeam★ 297same name
    2. pbc-os/smb-starter-kit★ 10same name
    3. madeinlowcode/skills-claude-code★ 7same name
    4. simtransforma/HAOS-CC-Model★ 1same name
    5. Throokie/claude-code-skills★ 1same name
    6. jaakjuu1/claude-skills★ 0same name

    How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.

The file

We split this skill into the rules it gives an agent

5 rules. 0 are common, 4 are distinctive, and 1 is very specific to this project.

  • 0

    Common

    Most of the 5 edited versions we read keep these.

  • 4

    Distinctive

    This author's own choices. Worth a look.

  • 1

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Create the basic directory structure for persistent state management:

    line 32
  2. Distinctive:

    Create persistent state management for cross-session continuity:

    line 101
  3. Distinctive:

    Load this skill: when starting a new project or resuming work

    line 212
  4. Very specific:

    Monitor progress: Check files in tasks/my-project/

    line 282
  5. Distinctive:

    Read and write files

    line 288

“Common” is measured: kept by at least 6 in 10 of the 5 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Long Running Agent

Build resilient autonomous agents that can parse PRDs/specifications, generate structured task lists, and execute tasks autonomously over extended periods with state persistence and automatic recovery.

This skill provides agent-agnostic patterns that work with any AI agent framework including Cursor, OpenCode, Claude, and others.

Core Architecture

A long-running agent consists of seven core systems that work with any agent framework:

  1. PRD/Spec Processing - Parse requirements documents into structured, executable task lists
  2. Task Execution Engine - Autonomous task processing with dependency management
  3. API Rotation & Management - Intelligent API key rotation, rate limiting, and load balancing
  4. State Management - File-based persistence for workflow states and task tracking
  5. Error Handling - Classification, recovery strategies, and graceful degradation
  6. Cross-Session Persistence - Resume work across interruptions and restarts
  7. Learning & Memory - Pattern recognition and improvement over time

These patterns are framework-agnostic and can be implemented with any AI agent that has file system access.

Implementation Workflow

Step 1: Set Up Project Structure

Create the basic directory structure for persistent state management:

def setup_project_structure(project_name: str):
    """Create directory structure for long-running agent."""
    directories = [
        f"tasks/{project_name}",
        f"results/{project_name}", 
        f"memories/{project_name}",
        f"logs/{project_name}"
    ]
    
    for directory in directories:
        os.makedirs(directory, exist_ok=True)
        print(f"✅ Created: {directory}")

Step 2: Implement PRD Processing

Parse requirements documents into structured, executable task lists:

def parse_prd_to_tasks(prd_content: str, project_name: str) -> Dict:
    """Parse PRD into structured task list with dependencies."""
    # See references/prd-processing.md for full implementation
    
    tasks = {
        "project_name": project_name,
        "created_at": datetime.now().isoformat(),
        "total_tasks": 0,
        "completed_tasks": 0,
        "tasks": []
    }
    
    # Extract sections, analyze dependencies, categorize tasks
    # Returns structured JSON with full task metadata
    return tasks

Full Implementation: See references/prd-processing.md

Step 3: Set Up API Rotation and Management

Configure intelligent API rotation for external service calls:

def setup_api_rotation(api_configs: List[Dict]):
    """Setup API rotation with multiple endpoints."""
    # See references/api-rotation.md for full implementation
    
    global api_manager
    api_manager = APIRotationManager()
    
    for config in api_configs:
        api_manager.add_endpoint(
            name=config["name"],
            base_url=config["base_url"], 
            api_key=config["api_key"],
            rate_limit=config.get("rate_limit", 60),
            quota_limit=config.get("quota_limit", 1000)
        )
    
    print(f"🔄 API rotation configured with {len(api_configs)} endpoints")

Full Implementation: See references/api-rotation.md

Step 4: Implement State Management

Create persistent state management for cross-session continuity:

def save_task_list(task_list: Dict, file_path: str = None):
    """Save task list to persistent storage."""
    # See references/state-management.md for full implementation
    
    if not file_path:
        file_path = f"tasks/{task_list['project_name']}/current_tasks.json"
    
    os.makedirs(os.path.dirname(file_path), exist_ok=True)
    with open(file_path, 'w') as f:
        json.dump(task_list, f, indent=2)

def load_task_list(project_name: str = None, file_path: str = None) -> Dict:
    """Load task list from persistent storage."""
    # Implementation details in references/state-management.md
    pass

Full Implementation: See references/state-management.md

Step 5: Implement Task Execution Engine

Execute tasks autonomously with dependency management:

def execute_next_task(project_name: str) -> Dict:
    """Execute the next available task with dependency checking."""
    # See references/task-execution.md for full implementation
    
    task_list = load_task_list(project_name)
    
    # Find next executable task (dependencies met, status pending)
    next_task = find_next_executable_task(task_list)
    
    if not next_task:
        return {"status": "no_tasks_available"}
    
    # Execute task by category with API rotation support
    result = execute_task_by_category(next_task)
    
    # Update task status and save state
    update_task_status(next_task["id"], "completed" if result["success"] else "failed")
    
    return result

Full Implementation: See references/task-execution.md

Step 6: Set Up Learning and Memory System

Implement pattern recognition and continuous improvement:

def save_execution_pattern(task: Dict, execution_result: Dict, pattern_file: str = "memories/patterns.json"):
    """Save successful execution patterns for learning."""
    # See references/learning-system.md for full implementation
    
    pattern = {
        "task_category": task["category"],
        "task_type": task.get("type", "general"),
        "execution_approach": execution_result.get("approach"),
        "success_factors": execution_result.get("success_factors", []),
        "timestamp": datetime.now().isoformat()
    }
    
    # Save pattern for future reference
    patterns = load_json_file(pattern_file, [])
    patterns.append(pattern)
    save_json_file(pattern_file, patterns)

Full Implementation: See references/learning-system.md

Step 7: Agent Integration

Integrate with your specific AI agent framework:

# For any agent framework (Cursor, OpenCode, Claude, etc.)
def run_long_running_agent(prd_content: str, project_name: str):
    """Main entry point for long-running agent workflow."""
    
    # 1. Setup
    setup_project_structure(project_name)
    setup_api_rotation(load_api_config())
    
    # 2. Parse PRD
    task_list = parse_prd_to_tasks(prd_content, project_name)
    save_task_list(task_list)
    
    # 3. Execute tasks
    while has_pending_tasks(project_name):
        result = execute_next_task(project_name)
        
        if result["status"] == "no_tasks_available":
            break
            
        # Learn from execution
        if result.get("success"):
            save_execution_pattern(result["task"], result)
    
    # 4. Generate summary
    return generate_project_summary(project_name)

Agent Framework Integration

For Cursor, OpenCode, and other AI Agents:

  1. Load this skill when starting a new project or resuming work
  2. Call run_long_running_agent() with your PRD content
  3. Monitor progress through the generated task files
  4. Resume anytime by calling execute_next_task()

Example Workflow:

# Start new project
prd = "Your PRD content here..."
summary = run_long_running_agent(prd, "ecommerce-platform")

# Resume existing project  
result = execute_next_task("ecommerce-platform")

# Check status
status = get_project_status("ecommerce-platform")

Key Patterns Summary

PatternPurposeImplementation
PRD ParsingConvert specs to structured tasksparse_prd_to_tasks() function with regex parsing
API RotationIntelligent API key rotation and load balancingAPIRotationManager with weighted selection
Rate LimitingPrevent API quota exhaustionPer-endpoint usage tracking and throttling
Task State ManagementTrack progress across sessionsJSON file-based persistence in tasks/ directory
Autonomous ExecutionSelf-directed task processingexecute_next_task() with dependency checking
Cross-Session PersistenceResume work after interruptionFile-based state management
Dependency ManagementEnsure proper task orderingDependency analysis and validation
Progress TrackingMonitor and update statusupdate_task_status() with counters
Parallel ExecutionHandle independent tasks concurrentlyThreadPoolExecutor with file locking
Error RecoveryHandle failures gracefullyTry-catch with error logging and retry logic
Learning SystemImprove from execution patternsPattern and solution storage in memories/
Agent AgnosticWork with any AI agentStandard Python functions, no framework dependencies

File Structure

project-name/
├── tasks/project-name/
│   ├── current_tasks.json    # Current task list and status
│   └── task_history.json     # Completed task history
├── results/project-name/
│   ├── task_001/            # Individual task outputs
│   └── task_002/
├── memories/project-name/
│   ├── patterns.json        # Learned execution patterns
│   └── solutions.json       # Error solutions
└── logs/project-name/
    └── execution.log        # Detailed execution logs

Reference Files

For detailed implementations, see:

  • prd-processing.md - PRD parsing patterns, task extraction, structured generation
  • api-rotation.md - API rotation, rate limiting, load balancing, error handling
  • task-execution.md - Autonomous task processing, dependency management, status tracking
  • state-management.md - File-based persistence, cross-session continuity, data integrity
  • agent-integration.md - Integration patterns for different AI agents (Cursor, OpenCode, etc.)
  • parallel-execution.md - Concurrent task processing, thread safety, coordination patterns
  • error-handling.md - Error classification, recovery strategies, graceful degradation
  • learning-system.md - Pattern recognition, continuous improvement, memory management

Quick Start

  1. Parse your PRD: tasks = parse_prd_to_tasks(prd_content, "my-project")
  2. Start execution: run_long_running_agent(prd_content, "my-project")
  3. Monitor progress: Check files in tasks/my-project/
  4. Resume anytime: execute_next_task("my-project")

Agent Instructions

This skill works with any AI agent that can:

  • Read and write files
  • Execute Python functions
  • Maintain state across conversations
  • Handle JSON data structures

Simply load this skill and call the main functions with your PRD content to begin autonomous task execution with full persistence and recovery capabilities.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.