Lux.Agent.Loaders.Json (Lux v0.5.0)

View Source

Handles loading agent configurations from JSON sources.

Summary

Functions

Loads agent configuration(s) from a JSON source. The source can be

Parses a JSON string into a Config struct. Returns {:ok, Config.t()} if successful, {:error, reason} otherwise.

Functions

load(sources)

@spec load(String.t() | [String.t()]) ::
  {:ok, [Lux.Agent.Config.t()]} | {:error, term()}

Loads agent configuration(s) from a JSON source. The source can be:

  • A JSON string
  • A path to a JSON file
  • A path to a directory containing JSON files
  • A list of JSON file paths

Returns:

  • {:ok, [Config.t()]} for successful loads (always returns a list)
  • {:error, term()} on failure

Examples

# Load from a single JSON string
{:ok, [config]} = Json.load(~s({"name": "Test Agent", ...}))

# Load from a single file
{:ok, [config]} = Json.load("path/to/agent.json")

# Load from a directory
{:ok, configs} = Json.load("path/to/agents/")

# Load from multiple files
{:ok, configs} = Json.load(["agent1.json", "agent2.json"])

parse(json)

@spec parse(String.t()) :: {:ok, Lux.Agent.Config.t()} | {:error, term()}

Parses a JSON string into a Config struct. Returns {:ok, Config.t()} if successful, {:error, reason} otherwise.