org.llm4s.pekko

package org.llm4s.pekko

Members list

Type members

Classlikes

trait AgentPekko

Apache Pekko Streams wrapper for Agent, the Pekko counterpart of AgentIO (cats-effect, fs2) and AgentZ (ZIO).

Apache Pekko Streams wrapper for Agent, the Pekko counterpart of AgentIO (cats-effect, fs2) and AgentZ (ZIO).

stream, streamResume and streamRecover run a turn as a Source of its events (AgentStreamItem.Event), then its result (AgentStreamItem.Done). The turn is started when the stream is materialized, once per materialization. Cancelling the stream - or stopping it early with take - cancels the turn: its model call and tool calls are interrupted and the thread is left for recover. 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 refused start (a blank query, a busy thread), a failed turn and a subscription that disconnects all fail the stream with an LLMException. A turn that commits no terminal event still ends the stream.

run, continueConversation, recover and resume return a Future, started and awaited on the ExecutionContext you pass (a blocking one: the wait blocks a thread). A Future cannot be cancelled; stream the turn when it has to be cancellable.

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

Attributes

Companion
object
Supertypes
class Object
trait Matchable
class Any
object AgentPekko

Attributes

Companion
trait
Supertypes
class Object
trait Matchable
class Any
Self type
AgentPekko.type

An item of an agent's event stream: each of the run's events, then its result.

An item of an agent's event stream: each of the run's events, then its result.

Attributes

Supertypes
trait Enum
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all

Apache Pekko Streams wrapper for LLMClient.

Apache Pekko Streams wrapper for LLMClient.

streamComplete is a Source of the provider's chunks; complete is a Future. The provider call blocks, so it never runs on a stream or actor dispatcher thread: a stream runs it on a thread of its own, and complete runs it on the ExecutionContext you pass, which should be a blocking one - for example system.dispatchers.lookup(Dispatchers.DefaultBlockingDispatcherId).

Cancelling a stream interrupts the provider's thread, which is how llm4s providers are cancelled: they keep the interrupt and return Left(CancelledError). A Future cannot be cancelled; use streamComplete when the call has to be.

An LLMError is carried by an LLMException, the failure of the stream or the Future.

Attributes

Companion
object
Supertypes
class Object
trait Matchable
class Any

Attributes

Companion
trait
Supertypes
class Object
trait Matchable
class Any
Self type
final class LLMException(val error: LLMError) extends RuntimeException

Carries an LLMError in a failed Pekko stream or Future, which can only fail with a Throwable. The error is the LLMError the provider, the tool or the runtime reported.

Carries an LLMError in a failed Pekko stream or Future, which can only fail with a Throwable. The error is the LLMError the provider, the tool or the runtime reported.

Attributes

Supertypes
class RuntimeException
class Exception
class Throwable
trait Serializable
class Object
trait Matchable
class Any
Show all