Powered by AppSignal & Oban Pro

Jidoka: Plugins

livebook/13_plugins.livemd

Jidoka: Plugins

Run in Livebook

Plugins package deeper runtime extensions. In the first Jidoka surface, the important contract is simple: a plugin can publish stable action-backed tools.

Setup

Mix.install(
  [
    {:jidoka, git: "https://github.com/mikehostetler/jidoka.git", ref: "924a486f3c1b7e7a943cb3d5ceee0de65f158467"},
    {:kino, "~> 0.19.0"}
  ],
  config: [
    jidoka: [
      model_aliases: %{fast: "anthropic:claude-haiku-4-5"}
    ]
  ]
)
Jidoka.Kino.setup()

Define A Plugin

defmodule LivebookDemo.Plugins.Tools.MultiplyNumbers do
  use Jidoka.Tool,
    name: "plugin_multiply_numbers",
    description: "Multiplies two integers.",
    schema: Zoi.object(%{a: Zoi.integer(), b: Zoi.integer()})

  @impl true
  def run(%{a: a, b: b}, _context), do: {:ok, %{product: a * b}}
end

defmodule LivebookDemo.Plugins.MathPlugin do
  use Jidoka.Plugin,
    description: "Provides math tools for Jidoka agents.",
    tools: [LivebookDemo.Plugins.Tools.MultiplyNumbers]
end

defmodule LivebookDemo.Plugins.Agent do
  use Jidoka.Agent

  agent do
    id :livebook_plugin_agent
  end

  defaults do
    model :fast
    instructions "You can use plugin-provided tools."
  end

  capabilities do
    plugin LivebookDemo.Plugins.MathPlugin
  end
end
%{
  plugin_name: LivebookDemo.Plugins.MathPlugin.name(),
  plugin_tools: LivebookDemo.Plugins.MathPlugin.actions(),
  agent_plugins: LivebookDemo.Plugins.Agent.plugin_names(),
  agent_tool_names: LivebookDemo.Plugins.Agent.tool_names()
}

Run the plugin-provided tool directly.

multiply_tool =
  Enum.find(LivebookDemo.Plugins.Agent.tools(), fn tool ->
    tool.name() == "plugin_multiply_numbers"
  end)

multiply_tool.run(%{a: 6, b: 7}, %{})

Optional Provider Turn

{:ok, pid} =
  Jidoka.Kino.start_or_reuse("livebook-plugin-agent", fn ->
    LivebookDemo.Plugins.Agent.start_link(id: "livebook-plugin-agent")
  end)

Jidoka.Kino.chat("Plugin tool chat", fn ->
  LivebookDemo.Plugins.Agent.chat(pid, "Use plugin_multiply_numbers to multiply 6 and 7. Reply with only the product.")
end)