AgentCall.AgentTool (agent_call v0.1.0)

Copy Markdown View Source

Runs a complete inner agent and returns its final text as a tool result.

The caller writes an ordinary ToolCall module whose function calls run/4. The helper appends input to the caller's request, runs AgentCall.run/3, and maps the inner outcome to a text result or a tagged error. It is a synchronous function: it creates no process, stores no state and derives no tool schema. It runs in the outer tool's task, so it may block that task; the outer tool_opts[:timeout] bounds it.

input is a string, which becomes one user LlmCall.Message, or a list of messages appended to request.messages. Any other input is {:error, {:input, :invalid}}. The request is copied; the caller's struct is not changed.

The options are the inner AgentCall.run/3 options plus on_pending: and on_result:. The helper-only keys are not forwarded to the inner run. on_pending: is a control callback invoked with an inner %AgentCall.Pending{}: it returns the decision to resume with or {:error, reason} to stop. It must not call AgentCall.resume/3 on that pending itself, which would resume the pending twice. A callback failure or malformed return becomes {:error, {:on_pending, reason}}; without the callback, an inner pause is {:error, {:pending, kind}}. on_result: observes an inner terminal %AgentCall.Result{}; a failure in that observer is ignored. on_event: is forwarded to every inner run and resume, and the inner run_id: is supplied only to the first run.

Summary

Types

The inner agent's input: one user message from a string, or messages to append to the request.

The nested-pause control callback or nil.

The inner-result observation callback or nil.

The decision an on_pending: callback will return for an inner pause.

Functions

Runs request with input appended and maps the inner outcome.

Types

input()

@type input() :: String.t() | [LlmCall.Message.t()]

The inner agent's input: one user message from a string, or messages to append to the request.

on_pending()

@type on_pending() :: (AgentCall.Pending.t() -> pending_decision()) | nil

The nested-pause control callback or nil.

on_result()

@type on_result() :: (AgentCall.Result.t() -> any()) | nil

The inner-result observation callback or nil.

pending_decision()

@type pending_decision() ::
  {:approval, :granted | :denied}
  | {:input, {:answer, term()} | {:cancel, term()}}
  | {:error, term()}

The decision an on_pending: callback will return for an inner pause.

Functions

run(client, request, input, opts)

@spec run(LlmCall.Client.t(), LlmCall.Request.t(), input(), keyword()) ::
  {:ok, String.t()} | {:error, term()}

Runs request with input appended and maps the inner outcome.

{:ok, result} becomes {:ok, text}; {:exhausted, result} becomes {:error, {:exhausted, halt_reason, text}}; an inner pause without on_pending: becomes {:error, {:pending, kind}}; and an %AgentCall.Error{} becomes {:error, {:inner, kind, message}}. Text is LlmCall.Response.text(result.response), or "" when there is no response. An inner pause with on_pending: is resumed until the inner run reaches a terminal outcome; the callback's {:error, reason} and a callback failure are terminal too.