Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions lib/jido.ex
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,66 @@ defmodule Jido do

@type agent_id :: String.t() | atom()

# Default instance name for scripts/Livebook
@default_instance Jido.Default

@doc """
Returns the default Jido instance name.

Used by `Jido.start/1` for scripts and Livebook quick-start.
"""
@spec default_instance() :: atom()
def default_instance, do: @default_instance

@doc """
Start the default Jido instance for scripts and Livebook.

This is an idempotent convenience function - safe to call multiple times
(returns `{:ok, pid}` even if already started).

## Examples

# In a script or Livebook
{:ok, _} = Jido.start()
{:ok, pid} = Jido.start_agent(Jido.default_instance(), MyAgent)

# With custom options
{:ok, _} = Jido.start(max_tasks: 2000)

## Options

Same as `start_link/1`, but `:name` defaults to `Jido.Default`.
"""
@spec start(keyword()) :: {:ok, pid()} | {:error, term()}
def start(opts \\ []) do
opts = Keyword.put_new(opts, :name, @default_instance)

case start_link(opts) do
{:ok, pid} -> {:ok, pid}
{:error, {:already_started, pid}} -> {:ok, pid}
other -> other
end
end

@doc """
Stop a Jido instance.

Defaults to stopping the default instance (`Jido.Default`).

## Examples

Jido.stop()
Jido.stop(MyApp.Jido)

"""
@spec stop(atom()) :: :ok
def stop(name \\ @default_instance) do
case Process.whereis(name) do
nil -> :ok
pid -> Supervisor.stop(pid)
end
end

@doc """
Starts a Jido instance supervisor.

Expand Down
2 changes: 0 additions & 2 deletions lib/jido/agent_server.ex
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,6 @@ defmodule Jido.AgentServer do

state = state.lifecycle.mod.init(lifecycle_opts, state)

Logger.debug("AgentServer #{state.id} initialized, status: idle")
{:noreply, State.set_status(state, :idle)}
end

Expand Down Expand Up @@ -815,7 +814,6 @@ defmodule Jido.AgentServer do
end
end)

Logger.debug("AgentServer #{state.id} terminating: #{inspect(reason)}")
:ok
end

Expand Down
14 changes: 0 additions & 14 deletions lib/jido/discovery.ex
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,6 @@ defmodule Jido.Discovery do
Task.async(fn ->
catalog = build_catalog()
:persistent_term.put(@catalog_key, catalog)

Logger.info(
"[Jido.Discovery] Catalog initialized with #{count_components(catalog)} components"
)

:ok
end)
end
Expand All @@ -105,10 +100,8 @@ defmodule Jido.Discovery do
"""
@spec refresh() :: :ok
def refresh do
Logger.info("[Jido.Discovery] Refreshing catalog...")
catalog = build_catalog()
:persistent_term.put(@catalog_key, catalog)
Logger.info("[Jido.Discovery] Catalog refreshed with #{count_components(catalog)} components")
:ok
end

Expand Down Expand Up @@ -240,13 +233,6 @@ defmodule Jido.Discovery do
}
end

defp count_components(catalog) do
catalog.components
|> Map.values()
|> Enum.map(&length/1)
|> Enum.sum()
end

defp discover_components(metadata_fun) do
loaded_applications()
|> Enum.flat_map(&modules_for/1)
Expand Down
Loading