Conjure.Backend behaviour (Conjure v0.1.1-alpha)

View Source

Behaviour for execution backends.

This behaviour defines the unified interface that all execution backends must implement, enabling pluggable execution strategies.

Available Backends

BackendModuleDescription
LocalConjure.Backend.LocalBash commands on host
DockerConjure.Backend.DockerBash commands in container
AnthropicConjure.Backend.AnthropicHosted execution via Skills API
NativeConjure.Backend.NativeElixir modules in BEAM

Example

# Using a backend directly
session = Conjure.Backend.Local.new_session(skills, [])
{:ok, response, session} = Conjure.Backend.Local.chat(
  session,
  "Hello",
  &api_callback/1,
  []
)

Implementing a Custom Backend

defmodule MyApp.Backend.Custom do
  @behaviour Conjure.Backend

  @impl true
  def backend_type, do: :custom

  @impl true
  def new_session(skills, opts) do
    # Create session state
  end

  @impl true
  def chat(session, message, api_callback, opts) do
    # Execute chat turn
  end
end

See Also

Summary

Callbacks

Get the backend type identifier.

Create a new session for this backend.

Functions

List all available backend types.

Get the backend module for a given type.

Types

api_callback()

@type api_callback() :: ([map()] -> {:ok, map()} | {:error, term()})

chat_result()

@type chat_result() :: {:ok, response :: map(), session()} | {:error, term()}

session()

@type session() :: Conjure.Session.t()

Callbacks

backend_type()

@callback backend_type() :: atom()

Get the backend type identifier.

Returns an atom identifying this backend (e.g., :local, :docker, :anthropic, :native).

chat(session, message, api_callback, opts)

@callback chat(session(), message :: String.t(), api_callback(), opts :: keyword()) ::
  chat_result()

Execute a chat turn.

Sends a message and returns the response along with updated session state.

Parameters

  • session - Current session state
  • message - User message to send
  • api_callback - Function to call the LLM API
  • opts - Additional options for this turn

Returns

  • {:ok, response, updated_session} - On success
  • {:error, error} - On failure

new_session(skills, opts)

@callback new_session(skills :: term(), opts :: keyword()) :: session()

Create a new session for this backend.

Parameters

  • skills - Skills to use (format depends on backend)
  • opts - Backend-specific options

Returns

A new session struct configured for this backend.

Functions

available()

@spec available() :: [atom()]

List all available backend types.

get(arg1)

@spec get(atom()) :: module() | nil

Get the backend module for a given type.

Example

Conjure.Backend.get(:local)
# => Conjure.Backend.Local

Conjure.Backend.get(:native)
# => Conjure.Backend.Native