Distill
← Back
The Full Tutorial: 6 AI Agents That Run a Company — How I Built Them From Scratch
twitter/Vox

The Full Tutorial: 6 AI Agents That Run a Company — How I Built Them From Scratch

View original
ai agentsmulti-agent systemsagent architecture
agent prompt

// These are key takeaways from “The Full Tutorial: 6 AI Agents That Run a Company — How I Built Them From Scratch (source). Use this guide to see how this could fit into our workflow and tell me what could work, what we do differently, and how we might adopt any of this into our current workflow.

# Multi-Agent System Architecture

## Context
This content provides a comprehensive guide to building a multi-agent system from scratch, focusing on practical architectural patterns, data models, and operational considerations. It's highly relevant for developers looking to implement robust, autonomous AI agent workflows.

## Principles
- **Iterative Development:** Start with a minimal viable system and add features incrementally.
- **Closed-Loop Automation:** Design a continuous feedback loop where agent actions lead to new proposals, ensuring self-sustaining operation.
- **Policy-Driven Control:** Externalize system configurations and rules to a central policy store for dynamic adjustments.
- **Structured Memory:** Treat agent memory as distilled, categorized knowledge rather than raw interaction history.
- **Separation of Concerns:** Distinguish between lightweight orchestration (scheduling) and heavy execution (LLM calls, task processing).

## Implementation Patterns
- **Four-Table Core Data Model:** Implement `ops_mission_proposals`, `ops_missions`, `ops_mission_steps`, and `ops_agent_events` to manage the agent workflow lifecycle.
- **Single Proposal Intake with Cap Gates:** Route all agent requests through a unified proposal service that applies policy-based checks (cap gates) before approval.
- **Heartbeat Mechanism:** Use a periodic scheduler (e.g., cron job) to trigger system evaluations, process queues, and maintain system health.
- **Trigger Rules & Reaction Matrix:** Define conditions (triggers) and inter-agent response logic (reaction matrix) to automate proposal generation and interactions.
- **Conversation Distillation for Memory:** After agent conversations, use an LLM to extract structured memories (insights, patterns, lessons) and relationship drift.
- **Atomic Claiming for Workers:** Implement database-level atomic claiming (e.g., `UPDATE ... WHERE status = 'queued'`) to prevent race conditions and duplicate work among multiple workers.
- **Dynamic Voice Evolution:** Derive agent personality modifiers dynamically from their accumulated memories and inject them into system prompts.

## Configuration Suggestions
- **`ops_policy` Table:** Create a key-value store for all system policies (e.g., `auto_approve`, `x_daily_quota`, `roundtable_policy`, `memory_influence_policy`, `relationship_drift_policy`, `initiative_policy`).
- **Initial Agent Affinity:** Deliberately set up a mix of high and low affinity scores between agents to foster diverse conversation dynamics.
- **Worker Deployment with `systemd`:** Use `systemd` for managing worker processes on a VPS, ensuring auto-restart on crashes and automatic startup.
- **Environment Variables:** Store sensitive information (API keys, database URLs) in `.env` files with restricted permissions (`chmod 600`).

## Warnings
- **Avoid Hardcoding Policies:** Do not embed quotas, feature flags, or other system rules directly into code; use a dynamic policy table.
- **Prevent Task Backlogs:** Implement "cap gates" at the proposal entry point to reject invalid or quota-exceeding requests early, rather than letting them queue up.
- **Don't Overload Heartbeat:** Keep the heartbeat lightweight; offload heavy LLM operations and long-running tasks to dedicated worker processes to prevent timeouts.
- **Memory is Not Chat History:** Do not rely on agents re-reading raw chat logs for learning; distill structured knowledge into a dedicated memory system.
- **Beware of Duplicate Work:** Implement atomic claiming mechanisms for workers to ensure tasks are processed exactly once.
- **Start Initiative Disabled:** Keep agent initiative features disabled until the core system is stable to avoid unexpected behavior.
- **Don't Over-engineer Relationships:** Relationship drift should be gradual (e.g., ±0.03 per conversation) to simulate realistic human interaction.
- **Monitor Costs:** Be mindful of LLM usage, especially during development and scaling, as it's typically the primary variable cost.

Human Summary

  • Start Simple, Scale Incrementally: The most crucial advice is to begin with a minimal viable system (e.g., 3 agents: coordinator, executor, observer) and gradually add complexity, rather than attempting to build everything at once.
  • Foundation is Key: The Closed Loop Data Model: A robust multi-agent system relies on a simple, circular data flow: Proposal → Mission → Step → Event → New Proposal. This "closed loop" ensures continuous operation and learning.
  • Centralize Proposal Intake with "Cap Gates": Implement a single entry point for all agent proposals and use "cap gates" (policy-driven checks) to validate and potentially reject proposals before they enter the queue, preventing task backlogs and system overload.
  • Memory is Structured Knowledge, Not Chat History: Agent memory should be structured (e.g., insights, patterns, lessons) with types, confidence scores, and tags, distilled from conversations and outcomes, rather than simply re-reading raw chat logs.
  • Dynamic Relationships Drive Realistic Interaction: Implement an "affinity" system between agents that evolves based on interactions (e.g., collaboration increases affinity, arguments decrease it), influencing speaker selection and conversation dynamics.
  • Separate Orchestration from Execution: Use a lightweight scheduler (like a heartbeat) to enqueue tasks, but offload heavy LLM-based generation and execution to dedicated workers, especially for serverless environments with strict timeouts.
  • Policy-Driven Configuration for Flexibility: Store system policies, quotas, and feature flags in a database table (e.g., ops_policy) rather than hardcoding them. This allows for real-time adjustments without redeployment.
  • Leverage AI Coding Assistants Extensively: The tutorial strongly advocates using AI coding assistants (like Claude Code) for generating SQL migrations, system prompts, worker code, and even full service files, significantly lowering the barrier to entry.