AgentZ

org.llm4s.zio.AgentZ
See theAgentZ companion object
trait AgentZ

ZIO wrapper for Agent.

Lifts every Result[AgentResult] into ZIO[Any, LLMError, AgentResult]. run and continueConversation start the turn on ZIO's blocking pool and then await it, so interrupting the fiber cancels the turn itself (AgentRun.cancel) and returns once it has ended: its model call and tool calls are interrupted, and the thread is left for recover. recover and resume do the same through Agent.startRecover and Agent.startResume.

stream, streamResume and streamRecover run a turn as a ZStream of its events (AgentStreamItem.Event), then its result (AgentStreamItem.Done); interrupting the stream cancels the turn as interrupting run does. Stopping early (take(n), runHead) also cancels the turn. A consumer too slow for the stream's buffer never holds the run up: it loses live events (text deltas, tool progress) and receives one StreamEvent.LiveGap with their count where they were dropped; durable events are never dropped, and the run carries on.

A model call that throws instead of returning Left ends the turn with a GraphError.NodeFailed whose cause is the LLMError the runtime made of the throwable; it fails the effect with that error, not as a defect.

Intentionally a thin wrapper: build the Agent with its tools, middleware (guardrails), handoffs and options through Agent.builder, or LLMClientZ.agent.

Attributes

Companion
object
Graph
Supertypes
class Object
trait Matchable
class Any

Members list

Value members

Abstract methods

def continueConversation(previous: AgentResult, query: String, config: RunConfig): ZIO[Any, LLMError, AgentResult]

The next turn on previous's thread; see Agent.continueConversation.

The next turn on previous's thread; see Agent.continueConversation.

Attributes

def recover(threadId: ThreadId, config: RunConfig): ZIO[Any, LLMError, AgentResult]

Continues threadId's failed or interrupted run; see Agent.recover.

Continues threadId's failed or interrupted run; see Agent.recover.

Attributes

def resume(threadId: ThreadId, answers: Map[InterruptId, Value], config: RunConfig): ZIO[Any, LLMError, AgentResult]

Answers pending approvals and questions and continues; see Agent.resume.

Answers pending approvals and questions and continues; see Agent.resume.

Attributes

def run(query: String, config: RunConfig): ZIO[Any, LLMError, AgentResult]

One turn on a new thread; see Agent.run.

One turn on a new thread; see Agent.run.

Attributes

def stream(threadId: ThreadId, query: String, config: RunConfig): ZStream[Any, LLMError, AgentStreamItem]

One turn on threadId, as a stream: every event of the turn (Agent.stream), then Done(result). A refused start or a failed turn fails the stream with the LLMError; so does a subscription that disconnects (its listener failed), which also cancels the run. A slow consumer loses live events and gets a StreamEvent.LiveGap instead; it does not cancel the run. Interrupting the stream, or stopping it early (take(n), runHead), cancels the turn and returns once it has ended, leaving the thread for recover.

One turn on threadId, as a stream: every event of the turn (Agent.stream), then Done(result). A refused start or a failed turn fails the stream with the LLMError; so does a subscription that disconnects (its listener failed), which also cancels the run. A slow consumer loses live events and gets a StreamEvent.LiveGap instead; it does not cancel the run. Interrupting the stream, or stopping it early (take(n), runHead), cancels the turn and returns once it has ended, leaving the thread for recover.

Attributes

def streamRecover(threadId: ThreadId, config: RunConfig): ZStream[Any, LLMError, AgentStreamItem]

recover as a stream; see stream.

recover as a stream; see stream.

Attributes

def streamResume(threadId: ThreadId, answers: Map[InterruptId, Value], config: RunConfig): ZStream[Any, LLMError, AgentStreamItem]

resume as a stream; see stream.

resume as a stream; see stream.

Attributes