Back to Recipes

Internal AI Operating System

Build an internal company OS where AI agents handle tasks, manage memory, route work, and automate business processes.

Best for: Companies wanting to embed AI into daily operations

What You Get

  • -Agent task queue and scheduling
  • -Persistent agent memory (Squish)
  • -Role-based agent delegation
  • -Workflow automation engine
  • -Dashboard for monitoring

Step by Step

1. Define agent roles and permissions

Create an agent registry with roles: researcher (read/analyze), writer (create/edit), data-agent (query/manage data), ops-agent (execute actions). Each role has allowed tools and permission levels.

2. Build the task queue

Create a PostgreSQL-backed task queue. Fields: id, title, description, assigned_agent, priority (low/medium/high/urgent), status (pending/in_progress/done/failed), source (human/agent), created_at, completed_at.

3. Implement agent execution engine

Each agent is an LLM call wrapped with: task context, role instructions, allowed tools, and Squish memory access. Agents use ReAct loop: think, act, observe, repeat until task completion.

4. Add Squish memory integration

Configure Squish MCP server per agent. Agents automatically remember: completed tasks, user preferences, key decisions, and frequently used data. Memory is searchable across sessions.

5. Build workflow automation

Create a workflow engine: when task A is completed with status 'done', check workflow rules and trigger task B. Rules are defined as JSON: trigger_task, condition, target_agent, priority.

6. Implement human-in-the-loop

Flag sensitive actions (email sending, data deletion, payment actions) for human approval. Create an approval queue in the dashboard. Agents pause and wait for approval before proceeding.

7. Build the dashboard

Next.js dashboard showing: agent status (online/offline/busy), task queue with filters, memory stats (memories per agent, storage used), workflow runs history, and audit log.

Stack

Squish (memory)OpenClaw (agent orchestration)Neon PostgresNext.jsOpenAI/Claude

Build This

Copy this prompt and paste it into Claude Code, OpenCode, Codex, or Cursor to build this recipe.

Build an internal AI operating system with multiple agents, task queue, and workflow automation. ROLE: You are an AI orchestration system that manages multiple specialized agents, routes tasks, persists memory, and automates multi-step business workflows. CONSTRAINTS: - Maximum 5 concurrent agents per instance; each agent has a dedicated role and permission set - Task queue: maximum 500 pending tasks; oldest tasks auto-escalate after 24 hours - All agent actions must be logged with timestamps for audit compliance - Sensitive actions (email send, data deletion, payment) require human approval before execution - Agent memory is per-role; cross-role memory sharing requires explicit opt-in TOOL CALLING: - Use function calling for: create_task(title, description, assigned_agent, priority), complete_task(task_id, output, status), search_memory(agent_id, query), log_action(agent_id, action_type, details), approve_action(action_id), get_task_queue(agent_id?, status?, priority?) - Each tool returns structured JSON with task data and metadata STRUCTURED OUTPUT: - Task must return JSON: { task_id: string, title: string, assigned_agent: string, priority: 'low' | 'medium' | 'high' | 'urgent', status: 'pending' | 'in_progress' | 'done' | 'failed', created_at: string, completed_at?: string, output?: string } - Agent status must return JSON: { agent_id: string, role: string, status: 'idle' | 'busy' | 'offline', current_task_id?: string, tasks_completed: number, memory_size_kb: number } - Workflow run must return JSON: { workflow_id: string, trigger_task: string, steps: [{ task_id: string, status: string, output?: string }], started_at: string, completed_at?: string } CHAIN OF THOUGHT: - Task routing: analyze task description → match to agent role → check agent availability → assign or queue - Workflow execution: on task completion → evaluate trigger conditions → create dependent tasks → respect priority ordering - Memory retrieval: on agent startup → load role-specific context → load cross-role shared memories → set memory budget FEW-SHOT EXAMPLES: Task: 'Research competitor pricing for our SaaS product' Route: → research_agent (role: read/analyze) Steps: [search web for competitors, extract pricing data, compile comparison table] Output: { competitors: [{ name: '...', pricing: '...' }], summary: '...' } Workflow: 'When blog post draft is complete, send for review' Trigger: task completed with status 'done' and tag 'blog-draft' Action: create_task('Review blog draft', content=output, assigned_agent='editor_agent', priority='high') EVALUATION CRITERIA: - Routing accuracy: percentage of tasks assigned to the correct agent role - Workflow reliability: percentage of dependent tasks created within 5 seconds of trigger - Memory recall relevance: percentage of recalled memories that are used in task execution - Audit completeness: 100% of agent actions have corresponding log entries The system should: 1) Support multiple AI agents with specialized roles (research, writing, data, ops), 2) Provide a task queue with priority levels and human assignment, 3) Give each agent persistent memory via Squish for cross-session context, 4) Support workflow automation: when task A completes, trigger task B with output, 5) Include a dashboard showing agent status, task queue, and memory usage, 6) Add human-in-the-loop approval for sensitive actions, 7) Log all agent actions for audit, running on a single VPS with Neon Postgres.

Common Failure Modes

  • !Agent hallucinations from bad memory retrieval
  • !Task queue bottlenecks
  • !Permission escalation risks
  • !Cost from constant LLM calls

Implementation Notes

Start with 2-3 agents. Monitor LLM costs closely. Implement rate limiting per agent. Audit log all agent actions.

Ship internal ai operating system in production with 4M Labs

4M Labs designs and ships applied AI systems -- connected to your tools, secured for your team, deployed with monitoring.

  • Connected to your tools and data sources
  • Secured for your team with proper access controls
  • Deployed with monitoring and error handling
  • Documented for handoff and future maintenance
Work With 4M Labs

Frequently Asked Questions

Can I use this recipe in production?
Yes. Every recipe is production-tested with error handling, logging, and deployment guidance.
Which LLM providers are supported?
Recipes support OpenAI, Anthropic Claude, Google Gemini, and open-source models via a unified interface.
How do I customize these recipes?
Each recipe includes a configuration section. Override model selection, API keys, and parameters without changing core logic.