Jido.AI.CLI.Adapter behaviour (Jido AI v2.2.0)

Copy Markdown View Source

Behavior for CLI adapters that drive different agent types.

Adapters encapsulate the specifics of how to:

  • Start an agent
  • Submit a query
  • Wait for completion
  • Extract the result

This keeps the Mix task clean and allows new agent types (CoT, ToT, etc.) to be added by implementing this behavior.

Built-in Adapters

Custom Agents

Agent modules can optionally implement cli_adapter/0 to specify their adapter:

defmodule MyApp.CustomAgent do
  use Jido.AI.Agent, ...

  def cli_adapter, do: Jido.AI.Reasoning.ReAct.CLIAdapter
end

If not implemented, the CLI will infer the adapter from --type or default to ReAct.

Summary

Callbacks

Wait for the agent to complete and return the result.

Create an ephemeral agent module with the given configuration. Returns the module name. Only called when --agent is not provided.

Start an agent and return its pid.

Stop the agent process.

Submit a query to the running agent.

Functions

Resolve the adapter module for an agent type or agent module.

Types

config()

@type config() :: map()

result()

@type result() :: %{answer: String.t(), meta: map()}

Callbacks

await(pid, timeout_ms, config)

@callback await(pid(), timeout_ms :: non_neg_integer(), config()) ::
  {:ok, result()} | {:error, term()}

Wait for the agent to complete and return the result.

create_ephemeral_agent(config)

@callback create_ephemeral_agent(config()) :: module()

Create an ephemeral agent module with the given configuration. Returns the module name. Only called when --agent is not provided.

start_agent(jido_instance, agent_module, config)

@callback start_agent(jido_instance :: atom(), agent_module :: module(), config()) ::
  {:ok, pid()} | {:error, term()}

Start an agent and return its pid.

stop(pid)

@callback stop(pid()) :: :ok

Stop the agent process.

submit(pid, query, config)

@callback submit(pid(), query :: String.t(), config()) :: :ok | {:error, term()}

Submit a query to the running agent.

Functions

resolve(type, agent_module)

@spec resolve(type :: String.t() | nil, agent_module :: module() | nil) ::
  {:ok, module()} | {:error, term()}

Resolve the adapter module for an agent type or agent module.