WardrikCore. Middleware behaviour
(wardrik_core v0.1.0-rc.1)
Copy Markdown
Wraps every step of a turn: the turn itself, each model call, and each tool call.
Use it when every call needs the same treatment, such as policy, tracing, retries or a system prompt.
defmodule MyApp.NoShell do
@behaviour WardrikCore.Middleware
@impl true
def call(%{step: {:tool_call, %{name: "shell"}}} = context, _next, _opts),
do: {:ok, %{context | response: {:error, "No shell."}}}
def call(context, next, _opts), do: next.(context)
endGive it to an agent as middleware: [MyApp.NoShell] or middleware: [{MyApp.NoShell, opts}].
The first in the list runs outermost.
Return values
next.(context)- carries on.{:ok, context}- answers the step yourself, withcontext.responseas the answer.{:park, reason, context}- waits for a person. SeeWardrikCore.resume/3.{:error, reason}- ends the step.
Summary
Callbacks
Handles one step. Call next to carry on, or return a result to stop.