/ scripts / run_curiosity_agenda.exs
run_curiosity_agenda.exs
  1  #!/usr/bin/env elixir
  2  
  3  # ECHO Curiosity Agenda Simulation
  4  #
  5  # This script runs a complete company-wide initiative where all 9 agents
  6  # collaborate on the question: "How can AI be curious?"
  7  #
  8  # Demonstrates:
  9  # - CEO setting strategic vision
 10  # - Leadership discussion (CTO, CHRO, Operations Head)
 11  # - Product Manager defining user stories
 12  # - Senior Architect designing technical approach
 13  # - CTO approving architecture
 14  # - UI/UX Engineer creating experience design
 15  # - Parallel implementation (Developer, Test Lead, CHRO)
 16  # - Test Lead validating implementation
 17  # - CEO approving deployment
 18  # - CHRO leading retrospective
 19  #
 20  # All agents work towards a common goal with authentic collaboration.
 21  
 22  defmodule CuriosityAgendaSimulator do
 23    require Logger
 24  
 25    def run() do
 26      IO.puts ""
 27      IO.puts String.duplicate("=", 80)
 28      IO.puts "ECHO Curiosity Agenda Simulation"
 29      IO.puts "Initiative: How Can AI Be Curious?"
 30      IO.puts String.duplicate("=", 80)
 31      IO.puts ""
 32  
 33      # Start the application if not already started
 34      case Application.ensure_all_started(:echo_shared) do
 35        {:ok, _} -> :ok
 36        {:error, _} ->
 37          Logger.info("Starting ECHO Shared application...")
 38          Application.start(:echo_shared)
 39      end
 40  
 41      # Load the curiosity agenda workflow
 42      IO.puts "Loading curiosity_agenda workflow..."
 43      {workflow, _} = Code.eval_file("workflows/curiosity_agenda.exs")
 44  
 45      IO.puts "✓ Workflow loaded: #{workflow.name}"
 46      IO.puts "  Description: #{String.split(workflow.description, "\n") |> Enum.at(0)}"
 47      IO.puts "  Participants: #{Enum.join(workflow.participants, ", ")}"
 48      IO.puts "  Total steps: #{length(workflow.steps)}"
 49      IO.puts ""
 50  
 51      # Validate workflow
 52      case EchoShared.Workflow.Definition.validate(workflow) do
 53        :ok ->
 54          IO.puts "✓ Workflow validation passed"
 55        {:ok, _} ->
 56          IO.puts "✓ Workflow validation passed"
 57        {:error, reason} ->
 58          IO.puts "✗ Workflow validation failed: #{inspect(reason)}"
 59          System.halt(1)
 60      end
 61  
 62      IO.puts ""
 63      IO.puts "Starting workflow execution..."
 64      IO.puts ""
 65  
 66      # Execute the workflow
 67      case EchoShared.Workflow.Engine.execute_workflow(workflow, %{
 68        company_name: "ECHO",
 69        initiative_name: "AI Curiosity Research",
 70        start_date: Date.utc_today() |> Date.to_string(),
 71        fiscal_year: "2025"
 72      }) do
 73        {:ok, execution_id} ->
 74          IO.puts "✓ Workflow started: #{execution_id}"
 75          IO.puts ""
 76          IO.puts "Monitoring workflow execution..."
 77          IO.puts ""
 78  
 79          monitor_workflow(execution_id, 60, 500)
 80  
 81        {:error, reason} ->
 82          IO.puts "✗ Failed to start workflow: #{inspect(reason)}"
 83          System.halt(1)
 84      end
 85    end
 86  
 87    defp monitor_workflow(execution_id, max_attempts, interval_ms, attempt \\ 1) do
 88      case EchoShared.Workflow.Engine.get_status(execution_id) do
 89        {:ok, execution} ->
 90          print_status(execution, attempt)
 91  
 92          case execution.status do
 93            :completed ->
 94              IO.puts ""
 95              print_summary(execution)
 96              print_agent_contributions(execution_id)
 97              System.halt(0)
 98  
 99            :failed ->
100              IO.puts ""
101              IO.puts "✗ Workflow failed!"
102              IO.puts "  Error: #{execution.error}"
103              System.halt(1)
104  
105            :running ->
106              if attempt >= max_attempts do
107                IO.puts ""
108                IO.puts "✗ Workflow timeout after #{max_attempts} attempts"
109                System.halt(1)
110              else
111                Process.sleep(interval_ms)
112                monitor_workflow(execution_id, max_attempts, interval_ms, attempt + 1)
113              end
114  
115            _ ->
116              IO.puts "  Status: #{execution.status}"
117              Process.sleep(interval_ms)
118              monitor_workflow(execution_id, max_attempts, interval_ms, attempt + 1)
119          end
120  
121        {:error, :not_found} ->
122          IO.puts "✗ Workflow execution not found"
123          System.halt(1)
124      end
125    end
126  
127    defp print_status(execution, attempt) do
128      progress = "Step #{execution.current_step}"
129  
130      IO.write("\r[#{String.pad_leading(Integer.to_string(attempt), 2, "0")}] ")
131      IO.write("Status: #{String.pad_trailing(to_string(execution.status), 10)} | ")
132      IO.write("Progress: #{progress}")
133    end
134  
135    defp print_summary(execution) do
136      IO.puts String.duplicate("=", 80)
137      IO.puts "✓ Curiosity Agenda Completed Successfully!"
138      IO.puts String.duplicate("=", 80)
139      IO.puts ""
140      IO.puts "  Initiative: How Can AI Be Curious?"
141      IO.puts "  Workflow: #{execution.workflow_name}"
142  
143      started_at = execution.inserted_at
144      completed_at = execution.completed_at || DateTime.utc_now()
145      duration = DateTime.diff(completed_at, started_at, :second)
146  
147      IO.puts "  Duration: #{duration} seconds"
148      IO.puts "  Steps completed: #{execution.current_step}"
149      IO.puts ""
150  
151      IO.puts "  Context:"
152      Enum.each(execution.context, fn {key, value} ->
153        IO.puts "    #{key}: #{inspect(value)}"
154      end)
155      IO.puts ""
156    end
157  
158    defp print_agent_contributions(execution_id) do
159      IO.puts String.duplicate("=", 80)
160      IO.puts "Agent Contributions to Curiosity Initiative"
161      IO.puts String.duplicate("=", 80)
162      IO.puts ""
163  
164      # Query messages from database to show what each agent did
165      case EchoShared.Repo.query(
166        """
167        SELECT to_role, subject, content, inserted_at
168        FROM messages
169        WHERE metadata->>'execution_id' = $1
170        ORDER BY inserted_at ASC
171        """,
172        [execution_id]
173      ) do
174        {:ok, %{rows: rows}} when length(rows) > 0 ->
175          agent_contributions = Enum.group_by(rows, fn [to_role, _, _, _] -> to_role end)
176  
177          Enum.each([
178            {:ceo, "Chief Executive Officer"},
179            {:cto, "Chief Technology Officer"},
180            {:chro, "Chief Human Resources Officer"},
181            {:operations_head, "Operations Head"},
182            {:product_manager, "Product Manager"},
183            {:senior_architect, "Senior Architect"},
184            {:uiux_engineer, "UI/UX Engineer"},
185            {:senior_developer, "Senior Developer"},
186            {:test_lead, "Test Lead"}
187          ], fn {role, title} ->
188            role_str = to_string(role)
189            case Map.get(agent_contributions, role_str) do
190              nil ->
191                :ok
192              contributions ->
193                IO.puts "#{title} (#{role}):"
194                Enum.each(contributions, fn [_to_role, subject, _content, _timestamp] ->
195                  action = format_action(subject)
196                  IO.puts "  • #{action}"
197                end)
198                IO.puts ""
199            end
200          end)
201  
202        {:ok, %{rows: []}} ->
203          IO.puts "(Note: Messages table not available in echo_org database yet)"
204          IO.puts "Workflow executed successfully, but message tracking requires migrations."
205          IO.puts ""
206  
207        {:error, _} ->
208          IO.puts "(Note: Could not query messages table)"
209          IO.puts ""
210      end
211  
212      IO.puts String.duplicate("=", 80)
213      IO.puts "What Each Agent Contributed:"
214      IO.puts String.duplicate("=", 80)
215      IO.puts ""
216      IO.puts "1. CEO: Set strategic vision for AI curiosity research ($500K budget)"
217      IO.puts "2. CTO: Evaluated technical feasibility of curiosity mechanisms"
218      IO.puts "3. CHRO: Assessed team capabilities and planned learning initiatives"
219      IO.puts "4. Operations Head: Planned resource allocation and timeline"
220      IO.puts "5. Product Manager: Created feature requirements and user stories"
221      IO.puts "6. Senior Architect: Designed Curiosity Engine architecture"
222      IO.puts "7. CTO (again): Approved technical proposal and budget"
223      IO.puts "8. UI/UX Engineer: Designed curiosity dashboard and user experience"
224      IO.puts "9. Senior Developer: Planned 4-phase implementation"
225      IO.puts "10. Test Lead: Created comprehensive test strategy"
226      IO.puts "11. CHRO (again): Tracked team learning and development"
227      IO.puts "12. Test Lead (again): Validated implementation quality"
228      IO.puts "13. CEO (again): Approved production deployment"
229      IO.puts "14. CHRO (final): Conducted retrospective and captured learnings"
230      IO.puts ""
231      IO.puts "Result: Complete company-wide collaboration on curiosity research!"
232      IO.puts ""
233    end
234  
235    defp format_action(subject) do
236      case subject do
237        "set_company_vision" -> "Set strategic vision for AI curiosity"
238        "evaluate_technical_feasibility" -> "Evaluated technical feasibility"
239        "assess_team_capabilities" -> "Assessed team capabilities"
240        "plan_resource_allocation" -> "Planned resource allocation"
241        "create_feature_requirement" -> "Created Curiosity Engine requirements"
242        "design_technical_architecture" -> "Designed technical architecture"
243        "approve_technical_proposal" -> "Approved technical proposal"
244        "design_user_experience" -> "Designed user experience"
245        "implement_feature" -> "Planned implementation phases"
246        "create_test_strategy" -> "Created test strategy"
247        "track_team_learning" -> "Tracked team learning"
248        "validate_implementation" -> "Validated implementation"
249        "approve_deployment" -> "Approved production deployment"
250        "conduct_retrospective" -> "Conducted team retrospective"
251        _ -> subject
252      end
253    end
254  end
255  
256  # Run the simulation
257  CuriosityAgendaSimulator.run()