Powered by AppSignal & Oban Pro

Lesson 08 Livebook: Autonomy After Light-Lag

08_autonomy_after_lightlag.livemd

Lesson 08 Livebook: Autonomy After Light-Lag

The bridge has run out of time. The frontier probe still has to choose.

Mix.install([
  {:helios_fleet, path: "../08_autonomy_after_lightlag"}
])

Application.ensure_all_started(:helios_fleet)

Helpers

defmodule Lesson08Helpers do
  alias HeliosFleet.Runtime

  def unique_agent_id(prefix) do
    "#{prefix}-#{System.unique_integer([:positive])}"
  end

  def safe_stop_family(parent_id) do
    child_ids = [
      "#{parent_id}/khepri/port_relay",
      "#{parent_id}/khepri/starboard_relay",
      "#{parent_id}/menhit/port_relay",
      "#{parent_id}/menhit/starboard_relay",
      "#{parent_id}/khepri",
      "#{parent_id}/menhit"
    ]

    Enum.each(child_ids, fn child_id ->
      case Runtime.whereis(child_id) do
        nil -> :ok
        _pid -> Runtime.stop_agent(child_id)
      end
    end)

    case Runtime.whereis(parent_id) do
      nil -> :ok
      _pid -> Runtime.stop_agent(parent_id)
    end
  end
end

Release Intent To Khepri

alias HeliosFleet
alias Jido.AgentServer
alias Jido.Signal

vessel_id = Lesson08Helpers.unique_agent_id("orpheus")
{:ok, pid} = HeliosFleet.start_command_vessel(vessel_id)

{:ok, _vessel} =
  AgentServer.call(
    pid,
    Signal.new!(
      "fleet.command.mesh_deployment_requested",
      %{
        mesh_id: "mesh-icefall",
        target: "ice fragment 6R"
      },
      source: "/orpheus/bridge"
    )
  )

Process.sleep(50)
{:ok, command_state} = AgentServer.state(pid)
khepri_pid = command_state.children.khepri.pid

{:ok, _probe} =
  AgentServer.call(
    khepri_pid,
    Signal.new!(
      "fleet.probe.telemetry_drift_detected",
      %{
        telemetry_age_s: 480,
        ephemeris_error_km: 23
      },
      source: "/nav/core"
    )
  )

{:ok, _probe} =
  AgentServer.call(
    khepri_pid,
    Signal.new!("fleet.probe.health_report_requested", %{}, source: "/orpheus/bridge")
  )

Process.sleep(200)

{:ok, _vessel} =
  AgentServer.call(
    pid,
    Signal.new!(
      "fleet.command.autonomy_release_requested",
      %{
        intent: "protect contact truth before intercept",
        autonomy_target: "khepri",
        command_window_s: 900
      },
      source: "/orpheus/bridge"
    )
  )

Process.sleep(50)

{:ok, updated_command_state} = AgentServer.state(pid)
{:ok, updated_probe_state} = AgentServer.state(khepri_pid)

Lesson08Helpers.safe_stop_family(vessel_id)

%{
  autonomy_packets: updated_command_state.agent.state.autonomy_packets,
  autonomy_decisions: updated_probe_state.agent.state.autonomy_decisions
}