/ apps / echo_shared / scripts / seed_memories.exs
seed_memories.exs
  1  #!/usr/bin/env elixir
  2  
  3  # Seed Sample Memories - Demonstrates parallel agent memory access
  4  # Usage: mix run shared/scripts/seed_memories.exs
  5  
  6  alias EchoShared.Repo
  7  alias EchoShared.Schemas.Memory
  8  
  9  defmodule SeedMemories do
 10    @moduledoc """
 11    Seeds the database with sample organizational memories from various agents.
 12    Demonstrates how agents running in parallel access shared memory.
 13    """
 14  
 15    def run do
 16      IO.puts("\n" <> IO.ANSI.blue() <> "Seeding ECHO Organizational Memory..." <> IO.ANSI.reset())
 17      IO.puts("─────────────────────────────────────────\n")
 18  
 19      # Clear existing memories (optional)
 20      clear_choice = IO.gets("Clear existing memories? (y/N): ") |> String.trim()
 21      if String.downcase(clear_choice) == "y" do
 22        Repo.delete_all(Memory)
 23        IO.puts(IO.ANSI.yellow() <> "Cleared existing memories" <> IO.ANSI.reset())
 24      end
 25  
 26      # Sample memories from different agents
 27      memories = [
 28        # CEO memories - Strategic
 29        %{
 30          key: "company_mission_2025",
 31          content: "Build the world's most advanced AI-powered organizational framework. Empower teams with autonomous agents that enhance human decision-making.",
 32          tags: ["strategy", "mission", "vision"],
 33          created_by_role: "ceo"
 34        },
 35        %{
 36          key: "q1_strategic_priorities",
 37          content: "1. Complete Phase 4 workflows, 2. Launch beta with 10 pilot customers, 3. Achieve 99.9% system uptime, 4. Expand engineering team by 5 members",
 38          tags: ["strategy", "okr", "q1-2025"],
 39          created_by_role: "ceo"
 40        },
 41  
 42        # CTO memories - Technical
 43        %{
 44          key: "tech_stack_decision_2025",
 45          content: "Primary stack: Elixir/OTP for agent runtime, PostgreSQL for persistence, Redis for message bus. Rationale: Fault tolerance, concurrency, and proven scalability.",
 46          tags: ["technology", "architecture", "decision"],
 47          created_by_role: "cto"
 48        },
 49        %{
 50          key: "infrastructure_guidelines",
 51          content: "All agents must be independently deployable. Use MCP protocol for standardization. Implement circuit breakers for external dependencies. Target 99.9% uptime SLA.",
 52          tags: ["infrastructure", "best-practices", "sla"],
 53          created_by_role: "cto"
 54        },
 55  
 56        # Senior Architect memories - Design
 57        %{
 58          key: "workflow_engine_design",
 59          content: "Workflow engine uses declarative DSL for multi-agent orchestration. Supports parallel execution, conditional branching, and human-in-the-loop approval. Built on OTP GenServer for fault tolerance.",
 60          tags: ["architecture", "workflows", "design"],
 61          created_by_role: "senior_architect"
 62        },
 63        %{
 64          key: "message_bus_pattern",
 65          content: "Inter-agent communication via Redis pub/sub. Private channels per agent (messages:role), broadcast channel (messages:all), leadership channel (messages:leadership). All messages persisted to PostgreSQL for audit trail.",
 66          tags: ["architecture", "messaging", "patterns"],
 67          created_by_role: "senior_architect"
 68        },
 69  
 70        # Product Manager memories - Product
 71        %{
 72          key: "feature_priority_matrix",
 73          content: "High priority: Workflow automation, AI-assisted decision-making, real-time collaboration. Medium: Advanced analytics, custom integrations. Low: UI customization, mobile apps.",
 74          tags: ["product", "roadmap", "priorities"],
 75          created_by_role: "product_manager"
 76        },
 77        %{
 78          key: "user_feedback_summary",
 79          content: "Pilot users love autonomous decision-making but want more visibility into agent reasoning. Feature request: explainable AI, decision audit trails, and rollback capabilities.",
 80          tags: ["product", "feedback", "user-research"],
 81          created_by_role: "product_manager"
 82        },
 83  
 84        # CHRO memories - People
 85        %{
 86          key: "team_composition_2025",
 87          content: "Current: 3 engineers, 1 product manager, 1 designer. Hiring plan: 5 senior engineers (Q1), 2 product managers (Q2), 1 DevOps engineer (Q1).",
 88          tags: ["hiring", "team", "headcount"],
 89          created_by_role: "chro"
 90        },
 91  
 92        # Operations Head memories - Operations
 93        %{
 94          key: "monitoring_setup",
 95          content: "Monitoring stack: Prometheus for metrics, Grafana for dashboards, PagerDuty for alerts. Key metrics: agent uptime, message latency, decision throughput, database query time.",
 96          tags: ["operations", "monitoring", "infrastructure"],
 97          created_by_role: "operations_head"
 98        },
 99  
100        # Senior Developer memories - Implementation
101        %{
102          key: "coding_standards",
103          content: "Follow Elixir style guide. Use dialyzer for type checking. Minimum 80% test coverage. All public functions must have @doc and @spec. Use with for happy path error handling.",
104          tags: ["development", "standards", "best-practices"],
105          created_by_role: "senior_developer"
106        },
107  
108        # Test Lead memories - Quality
109        %{
110          key: "testing_strategy",
111          content: "Three-tier testing: Unit tests for individual components, integration tests for multi-agent workflows, system tests for load/failover. Use ExUnit, property-based testing with StreamData.",
112          tags: ["testing", "quality", "strategy"],
113          created_by_role: "test_lead"
114        },
115  
116        # Shared learnings
117        %{
118          key: "incident_2024_12_15_postmortem",
119          content: "Database connection pool exhaustion during load test. Root cause: Missing connection timeout configuration. Fix: Added pool_size: 20, timeout: 15000. Prevention: Load testing before production deployment.",
120          tags: ["incident", "postmortem", "lessons-learned"],
121          created_by_role: "operations_head"
122        }
123      ]
124  
125      # Insert memories
126      inserted = Enum.map(memories, fn attrs ->
127        case %Memory{}
128             |> Memory.changeset(attrs)
129             |> Repo.insert() do
130          {:ok, memory} ->
131            IO.puts(IO.ANSI.green() <> "✓ " <> IO.ANSI.reset() <> "#{memory.key} (by #{memory.created_by_role})")
132            memory
133  
134          {:error, changeset} ->
135            IO.puts(IO.ANSI.red() <> "✗ Failed: #{attrs.key}" <> IO.ANSI.reset())
136            IO.inspect(changeset.errors)
137            nil
138        end
139      end)
140      |> Enum.reject(&is_nil/1)
141  
142      IO.puts("\n" <> IO.ANSI.blue() <> "═════════════════════════════════════════" <> IO.ANSI.reset())
143      IO.puts(IO.ANSI.green() <> "✓ Seeded #{length(inserted)} memories" <> IO.ANSI.reset())
144      IO.puts(IO.ANSI.blue() <> "═════════════════════════════════════════" <> IO.ANSI.reset())
145  
146      IO.puts("\n" <> IO.ANSI.cyan() <> "Next steps:" <> IO.ANSI.reset())
147      IO.puts("  1. View all memories: mix run scripts/memory_viewer.exs list")
148      IO.puts("  2. View by agent: mix run scripts/memory_viewer.exs by-agent")
149      IO.puts("  3. Search memories: mix run scripts/memory_viewer.exs search 'workflow'")
150      IO.puts("  4. View by tag: mix run scripts/memory_viewer.exs by-tag architecture")
151      IO.puts("")
152    end
153  end
154  
155  SeedMemories.run()