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

View Source

Backend for native Elixir module execution.

Executes skills implemented as Elixir modules directly in the BEAM, providing type-safe, in-process execution with full access to the application's runtime context.

Usage

defmodule MyApp.Skills.Database do
  @behaviour Conjure.NativeSkill

  def __skill_info__ do
    %{
      name: "database",
      description: "Query the database",
      allowed_tools: [:execute, :read]
    }
  end

  def execute(query, _context), do: {:ok, run_query(query)}
  def read(table, _context, _opts), do: {:ok, get_schema(table)}
end

session = Conjure.Backend.Native.new_session([MyApp.Skills.Database], [])

{:ok, response, session} = Conjure.Backend.Native.chat(
  session,
  "What tables do we have?",
  &api_callback/1,
  []
)

How It Works

  1. Native skill modules implement Conjure.NativeSkill behaviour
  2. This backend generates Claude tool definitions from skill info
  3. When Claude returns tool_use blocks, this backend:
    • Maps tool names back to skill modules
    • Invokes the appropriate callback (execute/read/write/modify)
    • Returns results to Claude

Advantages Over Local Backend

  • No subprocess/shell overhead
  • Type-safe with compile-time checks
  • Direct access to application state (Ecto repos, caches, GenServers)
  • Better error handling with pattern matching

Options

  • :working_directory - Working directory for file operations
  • :timeout - Execution timeout in milliseconds (default: 30_000)
  • :max_iterations - Maximum tool-use iterations (default: 25)

See Also

Summary

Functions

Build a tool name to module mapping for dispatching.

Get all tool definitions for a list of native skill modules.

Functions

build_tool_map(skill_modules)

@spec build_tool_map([module()]) :: %{required(String.t()) => {module(), atom()}}

Build a tool name to module mapping for dispatching.

Returns a map from tool name to {module, callback_type}.

tool_definitions(skill_modules)

@spec tool_definitions([module()]) :: [map()]

Get all tool definitions for a list of native skill modules.

Returns a list of tool definitions suitable for passing to the Claude API.