Raxol.Agent.ProcessBehaviour behaviour (Raxol Agent v2.6.0)

Copy Markdown View Source

Behaviour for agents running in the observe/think/act loop (Agent.Process).

Formalizes the callbacks that Agent.Process modules implement. Using this behaviour gives compile-time warnings for missing callbacks.

Summary

Callbacks

Execute an action. Returns updated state.

Snapshot state for crash recovery.

Initialize agent state from options.

Observe events and produce an observation map.

Called when pilot releases.

Called when pilot takes over.

Handle a directive from the orchestrator or pilot.

Restore state from a snapshot.

Decide what to do based on the observation.

Types

action()

@type action() :: term()

directive()

@type directive() :: term()

events()

@type events() :: [term()]

observation()

@type observation() :: map()

state()

@type state() :: map()

Callbacks

act(action, state)

@callback act(action(), state()) :: {:ok, state()} | {:error, term(), state()}

Execute an action. Returns updated state.

context_snapshot(state)

(optional)
@callback context_snapshot(state()) :: map()

Snapshot state for crash recovery.

init(keyword)

@callback init(keyword()) :: {:ok, state()} | state()

Initialize agent state from options.

observe(events, state)

@callback observe(events(), state()) :: {:ok, observation(), state()}

Observe events and produce an observation map.

on_resume(state)

(optional)
@callback on_resume(state()) :: {:ok, state()}

Called when pilot releases.

on_takeover(state)

(optional)
@callback on_takeover(state()) :: {:ok, state()}

Called when pilot takes over.

receive_directive(directive, state)

@callback receive_directive(directive(), state()) :: {:ok, state()} | {:defer, state()}

Handle a directive from the orchestrator or pilot.

restore_context(map)

(optional)
@callback restore_context(map()) :: {:ok, state()} | :error

Restore state from a snapshot.

think(observation, state)

@callback think(observation(), state()) ::
  {:act, action(), state()} | {:wait, state()} | {:ask_pilot, term(), state()}

Decide what to do based on the observation.

Returns:

  • {:act, action, new_state} -- execute an action
  • {:wait, new_state} -- do nothing this tick
  • {:ask_pilot, question, new_state} -- escalate to human