Conjure.Executor behaviour (Conjure v0.1.1-alpha)
View SourceBehaviour for tool execution backends.
Executors are responsible for running tool operations (bash commands, file reads/writes) in an execution environment. Different executors provide different levels of isolation:
Conjure.Executor.Local- Direct execution on host (no isolation)Conjure.Executor.Docker- Container-isolated execution
Implementing a Custom Executor
To create a custom executor, implement all required callbacks:
defmodule MyApp.FirecrackerExecutor do
@behaviour Conjure.Executor
@impl true
def init(context) do
# Start Firecracker microVM
{:ok, %{context | vm_id: vm_id}}
end
@impl true
def bash(command, context) do
# Execute in microVM
{:ok, output}
end
@impl true
def view(path, context, opts) do
# Read from microVM
{:ok, content}
end
@impl true
def create_file(path, content, context) do
{:ok, "File created"}
end
@impl true
def str_replace(path, old_str, new_str, context) do
{:ok, "File updated"}
end
@impl true
def cleanup(context) do
# Shutdown microVM
:ok
end
endResult Types
All execution callbacks return:
{:ok, output}- Successful execution with string output{:ok, output, files}- Execution with output and generated files{:error, reason}- Execution failed
Summary
Callbacks
Execute a bash command.
Cleanup the execution environment.
Create a new file with content.
Initialize the execution environment.
Replace a string in a file.
Read a file or directory listing.
Functions
Executes a tool call using the specified executor.
Types
Callbacks
@callback bash(command :: String.t(), context :: Conjure.ExecutionContext.t()) :: result()
Execute a bash command.
@callback cleanup(context :: Conjure.ExecutionContext.t()) :: :ok
Cleanup the execution environment.
Called when the session ends to clean up resources.
@callback create_file( path :: Path.t(), content :: String.t(), context :: Conjure.ExecutionContext.t() ) :: result()
Create a new file with content.
@callback init(context :: Conjure.ExecutionContext.t()) :: {:ok, Conjure.ExecutionContext.t()} | {:error, term()}
Initialize the execution environment.
Called once per session to set up the execution environment. For stateless executors, this can be a no-op that returns the context unchanged. For container-based executors, this starts the container.
@callback str_replace( path :: Path.t(), old_str :: String.t(), new_str :: String.t(), context :: Conjure.ExecutionContext.t() ) :: result()
Replace a string in a file.
@callback view( path :: Path.t(), context :: Conjure.ExecutionContext.t(), opts :: keyword() ) :: result()
Read a file or directory listing.
Options
:view_range-[start_line, end_line]for partial file reads
Functions
@spec execute(Conjure.ToolCall.t(), Conjure.ExecutionContext.t(), module()) :: result()
Executes a tool call using the specified executor.
This is a convenience function that dispatches to the appropriate executor callback based on the tool name.