Ergonomic iex-flavoured frontend to GenAgentEnsemble.
This module is meant to be aliased in .iex.exs:
alias GenAgentEnsemble.IEx, as: EIt delegates every core ensemble operation (list/0, tell/2,
ask/2, etc.) to GenAgentEnsemble and adds a handful of
helpers that make casual REPL work nicer: unwrapping the most
useful field of a %GenAgent.Response{} (the text), blocking
on a tell token, draining a pool to plain {token, text} pairs.
For programmatic use from library code, call GenAgentEnsemble
directly -- this module is a humans-at-the-prompt convenience.
Example
iex> E.list()
["echo", "solo"]
iex> E.ask!("solo", "one-sentence summary of GenServer")
"A GenServer is a generic server process..."
iex> E.ask("solo", "give me markdown") |> E.puts()
# Markdown content
# ...
:ok
iex> {:ok, tok} = E.tell("qa-pool", "ask one")
iex> E.await("qa-pool", tok).text
"..."
Summary
Functions
Blocking ask that returns the response text directly, or raises.
Poll name/token until the token completes or timeout elapses.
Drain inbox/1 and unwrap each entry to {token, text} (or
{token, {:error, reason}} for failed tokens).
Print the response text to stdout. Accepts a %Response{} or an
{:ok, response} tuple. Handy for multi-line markdown output.
Extract the text field from a %GenAgent.Response{} or an
{:ok, response} tuple. Raises on {:error, reason}.
Functions
Blocking ask that returns the response text directly, or raises.
The iex equivalent of "just give me the answer." Raises on error
so mistakes don't silently become empty strings. Accepts the same
opts as ask/3 (e.g. timeout: 60_000, agent: "alice").
@spec await(String.t(), String.t(), timeout()) :: GenAgent.Response.t()
Poll name/token until the token completes or timeout elapses.
Returns the %Response{} on success; raises on error or timeout.
The iex counterpart to GenAgentEnsemble.ask/3 for cases where
the prompt was fired with tell/2 and the caller now wants a
blocking wait.
Drain inbox/1 and unwrap each entry to {token, text} (or
{token, {:error, reason}} for failed tokens).
The quickest way to see what a Pool session has produced.
@spec puts(GenAgent.Response.t() | {:ok, GenAgent.Response.t()} | {:error, term()}) :: :ok
Print the response text to stdout. Accepts a %Response{} or an
{:ok, response} tuple. Handy for multi-line markdown output.
@spec text(GenAgent.Response.t() | {:ok, GenAgent.Response.t()} | {:error, term()}) :: String.t()
Extract the text field from a %GenAgent.Response{} or an
{:ok, response} tuple. Raises on {:error, reason}.
Useful in pipes: E.ask("solo", q) |> E.text() |> String.length().