agent-loop

Implements Atrox agent generation loops with arc_state transactions, agent_queue cron jobs, and Claude API calls.

Updated Apr 5, 2026
One-click install
npx skills add https://github.com/marumo333/atrox --skill agent-loop-marumo333
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: agent-loop
Source: https://github.com/marumo333/atrox/tree/main/.claude/skills/agent-loop
Command: npx skills add https://github.com/marumo333/atrox --skill agent-loop-marumo333

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires @anthropic-ai/sdk.

What problem does it solve? Building an autonomous fiction-generation agent requires strict coordination between prompt assembly, database state updates, job queues, and the Claude API. This Skill enforces the correct implementation patterns for Atrox's agent loop so episodes are generated reliably without race conditions, partial writes, or uncontrolled retries. ## Core Features & Use Cases - Prompt Assembly Order: Defines a fixed 7-section prompt structure (character DNA, style rules, arc state, recurring entities, style drift, reader comments, generation instruction) that must not be reordered. - Transactional State Updates: Ensures episodes inserts and arc_state updates happen in a single database transaction, updating all fields including world_state, recurring_entities, style_drift, and emotional_log. - Queue-Based Generation: Manages agent_queue jobs via cron pickup with SELECT FOR UPDATE SKIP LOCKED to prevent concurrent execution, and stops on failure without automatic retries. - Use Case: When implementing the weekly episode generation cron for an Atrox arc, follow this Skill to pick up a pending job, call the Claude API with the assembled prompt, persist results transactionally, and enqueue the next week's job. ## Quick Start Implement the weekly episode generation job for an Atrox arc following the agent-loop patterns for prompt building, queue management, and transactional state updates.

Frequently Asked Questions about agent-loop

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I implement a Claude API generation loop with a job queue?▼

Claim one pending job inside a transaction using SELECT FOR UPDATE with SKIP LOCKED, mark it running, then call the Claude API. On success mark the job done and enqueue the next scheduled job; on failure mark it failed and stop without retrying.

How to build a prompt for character-driven story generation?▼

Assemble the prompt in a fixed order: character persona first, then style rules, current arc world state, recurring entities, style drift log, reader comments last, and finally the generation instruction. Join sections with a separator and never reorder them.

Should Claude API be called directly from an HTTP request handler?▼

No. All generation must go through the agent_queue and be picked up by a cron job. This decouples user-facing requests from long-running generation and enables controlled scheduling and failure handling.

How do I prevent concurrent cron workers from processing the same job?▼

Use SELECT ... FOR UPDATE with SKIP LOCKED inside a transaction when fetching the pending job, and immediately update its status to running. Locked rows are skipped by other workers, preventing duplicate generation.

Why must episode inserts and arc_state updates share one transaction?▼

Splitting them risks partial writes where an episode exists but the arc state is stale, or vice versa. A single transaction guarantees episode_count, world_state, recurring_entities, style_drift, and emotional_log stay consistent with the inserted episode.

What happens when episode generation fails in the agent queue?▼

The job status is set to failed and processing stops. The system deliberately does not auto-retry, so failed jobs require manual inspection and re-enqueueing rather than risking repeated broken generations.