GenAI.Approval.SubmitHost behaviour (GenAI Approval v0.1.0)

Copy Markdown View Source

Behaviour the host application implements to accept agent-submitted approval scripts (the v1 interop surface, PRD §10).

Configure the implementing module:

config :genai_approval, :submit_host, MyApp.ApprovalHost

When an agent calls the submit_approval_script MCP tool, the tool loads the script and asks the host for run options — this is where the host maps the script's declared endpoints to executors, resolves credential("id") references, picks the permission store/subject/session, and sets budgets. on_run/3 is the host's cue to surface the run to an operator (mount the LiveView, ping the voice surface, …). The tool call then parks until the run terminates and returns the sanitized §9 result to the agent.

Summary

Callbacks

A run has started — surface it to the operator.

Map a loaded script to GenAI.Approval.start_run/2 options.

Callbacks

on_run(run, run_id, meta)

(optional)
@callback on_run(run :: pid(), run_id :: String.t(), meta :: map()) :: :ok

A run has started — surface it to the operator.

run_options(script, meta)

@callback run_options(script :: GenAI.Approval.Script.t(), meta :: map()) ::
  {:ok, keyword()} | {:error, term()}

Map a loaded script to GenAI.Approval.start_run/2 options.

meta carries submission context (e.g. :session_id, :variables). Return {:error, reason} to refuse the submission (the agent sees a tool execution error).