Wardrik. Server behaviour
(wardrik_protocol v0.1.0-rc.1)
Copy Markdown
A behaviour for what runs Wardrik's operations.
Wardrik.Agent, Wardrik.Tokens and the other typed modules call the server their
Wardrik.Scope names. Packages built on the protocol call those modules without depending on
the server. The wardrik hub implements it.
Summary
Callbacks
Answers the worker's call with the JSON-RPC message.
Returns the scope an API token's secret acts in on wardrik, or an error.
Sends input to agent and streams its answer, in order
Offers a worker's tools, as MCP's tools/list returns them, to the agents scope may serve.
Runs operation id with input, shaped as its input schema describes.
Runs the streamed operation id. Streams {event, cursor} pairs: stored events, then new ones as they arrive.
Callbacks
Answers the worker's call with the JSON-RPC message.
@callback authenticate(wardrik :: atom(), secret :: String.t()) :: {:ok, Wardrik.Scope.t()} | {:error, Wardrik.Error.t()}
Returns the scope an API token's secret acts in on wardrik, or an error.
@callback follow(Wardrik.Scope.t(), String.t() | struct(), term(), keyword()) :: Enumerable.t()
Sends input to agent and streams its answer, in order:
{:text, chunk}, any number of times.- One of
{:done, %Wardrik.Reply{}},{:waiting, interrupts}or{:failed, why}.
Raises Wardrik.Error if the agent can't be reached.
@callback offer(Wardrik.Scope.t(), tools :: [map()]) :: :ok | {:error, term()}
Offers a worker's tools, as MCP's tools/list returns them, to the agents scope may serve.
The calling process then receives:
{Wardrik.Workers, :call, call, name, arguments, meta}for each call to a tool.{Wardrik.Workers, :cancel, call}when a call is cancelled.
@callback run(Wardrik.Scope.t(), String.t(), map()) :: {:ok, term()} | {:error, Wardrik.Error.t()}
Runs operation id with input, shaped as its input schema describes.
@callback stream(Wardrik.Scope.t(), String.t(), map()) :: {:ok, Enumerable.t()} | {:error, Wardrik.Error.t()}
Runs the streamed operation id. Streams {event, cursor} pairs: stored events, then new ones as they arrive.