Wardrik.Server behaviour (wardrik_protocol v0.1.0-rc.6)

Copy Markdown

A behaviour for what runs Wardrik's operations. Wardrik implements it.

Wardrik.Agent and the other operation modules call the server in their Wardrik.Scope. So packages call them without depending on wardrik. WardrikTesting.Server implements it for tests.

Summary

Callbacks

Answers the worker's call with the JSON-RPC message.

Sends the input to the agent and streams its answer

Offers a worker's tools, as MCP's tools/list returns them. The calling process then receives

Runs the request's operation.

Runs the request's streamed operation. Streams {event, cursor}: kept events, then new ones.

Callbacks

answer(call, message)

@callback answer(call :: term(), message :: map()) :: :ok

Answers the worker's call with the JSON-RPC message.

follow(t, opts)

@callback follow(Wardrik.Server.Follow.t(), opts :: keyword()) :: Enumerable.t()

Sends the input to the agent and streams its answer:

  1. {:text, chunk}, any number of times.
  2. One of {:done, %Wardrik.Reply{}}, {:waiting, interrupts} or {:failed, why}.

Raises Wardrik.Error if the agent can't be reached.

offer(t, tools)

@callback offer(Wardrik.Scope.t(), tools :: [map()]) :: :ok | {:error, term()}

Offers a worker's tools, as MCP's tools/list returns them. 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.

run(t)

@callback run(Wardrik.Server.Request.t()) :: {:ok, term()} | {:error, Wardrik.Error.t()}

Runs the request's operation.

stream(t)

@callback stream(Wardrik.Server.Request.t()) ::
  {:ok, Enumerable.t()} | {:error, Wardrik.Error.t()}

Runs the request's streamed operation. Streams {event, cursor}: kept events, then new ones.