NornsSdk.Client (norns_sdk v0.1.0)

Copy Markdown View Source

Client for interacting with Norns agents.

Sends messages, queries runs, manages conversations.

Usage

client = NornsSdk.Client.new("http://localhost:4000", api_key: "nrn_...")

# Fire and forget
{:ok, %{run_id: 42}} = NornsSdk.Client.send_message(client, "support-bot", "Hello!")

# Block until completion
{:ok, result} = NornsSdk.Client.send_message(client, "support-bot", "Hello!", wait: true)
result.output

Summary

Types

t()

@type t() :: %NornsSdk.Client{api_key: String.t(), base_url: String.t()}

Functions

create_agent(client, agent)

delete_conversation(client, agent, key)

ensure_agent(client, agent)

get_agent(client, id)

get_conversation(client, agent, key)

get_events(client, run_id)

get_run(client, run_id)

list_agents(client)

list_conversations(client, agent)

new(url, opts \\ [])

send_message(client, agent, content, opts \\ [])

stream(client, agent, content, opts \\ [])

@spec stream(t(), integer() | String.t(), String.t(), keyword()) ::
  {:ok, pid()} | {:error, term()}

Send a message and stream the run's events to a subscriber process.

Sends the message (fire-and-forget), then starts a NornsSdk.StreamClient that joins the run's channel and forwards each event to the subscriber's mailbox as:

{:norns_event, stream_pid, %NornsSdk.StreamEvent{type: type, data: data}}

The terminal events are "completed" and "error"; the stream process stops after forwarding one. If the socket closes first, the subscriber receives {:norns_closed, stream_pid, reason}. Returns {:ok, stream_pid}.

Options

  • :subscriber — pid to receive events (defaults to the calling process).
  • :conversation_key — multi-turn conversation key.

Example

{:ok, _pid} = NornsSdk.Client.stream(client, "support-bot", "Research quantum computing")

receive do
  {:norns_event, _pid, %NornsSdk.StreamEvent{type: "completed"} = ev} ->
    IO.puts(ev.data["output"])
end

update_agent(client, id, agent)