Raxol.Agent.Directive (Raxol Agent v2.6.0)

Copy Markdown View Source

Agent-specific effect directives.

Each directive is a bare struct with a Raxol.Core.Runtime.Directive.Executor protocol implementation that the runtime invokes to perform the effect.

Built-in directives

DirectiveEffect
AsyncSpawn a task with a sender callback for multi-message replies
ShellRun a shell command via Port, return structured exit/output
SendAgentRoute a message to another agent by id (via Registry)

Re-exported from Raxol.Core.Runtime.Directive

These shared directives need no agent context; agent code can use them through this module's helpers for convenience or call the core module directly:

Examples

Directive.async(fn sender ->
  sender.({:progress, 50})
  sender.({:done, do_work()})
end)

Directive.shell("ls -la", timeout: 5_000)
Directive.send_agent("worker-1", {:task, payload})

Execution

Raxol.Core.Runtime.Directive.Executor.execute(directive, %{
  pid: self(),
  runtime_pid: runtime_pid
})

Result messages arrive at context.pid as {:command_result, payload}.

Summary

Functions

Construct an Async directive with a sender-callback function.

Construct a SendAgent directive.

Construct a Shell directive.

Types

Functions

async(fun)

Construct an Async directive with a sender-callback function.

schedule(interval_ms, payload)

Delegates to Raxol.Core.Runtime.Directive.schedule/2.

send_agent(target_id, message)

@spec send_agent(term(), term()) :: Raxol.Agent.Directive.SendAgent.t()

Construct a SendAgent directive.

shell(command, opts \\ [])

Construct a Shell directive.

Options:

  • :timeout - max execution time in ms (default: runtime default)
  • :cd - working directory
  • :env - environment variables as [{key, value}]

spawn(fun)

@spec spawn((-> any())) :: Raxol.Core.Runtime.Directive.Spawn.t()

Delegates to Raxol.Core.Runtime.Directive.spawn_task/1.

stop(reason \\ :normal)

Delegates to Raxol.Core.Runtime.Directive.stop/1.