EventHandlers

org.llm4s.agent.graph.EventHandlers
See theEventHandlers companion object
final class EventHandlers[+R] extends StreamEvent => Unit

Typed handlers for a run's events, each registered with its EventType, so that a selection of mixed event types keeps each payload's type:

val handlers = EventHandlers
 .on(AgentEvents.TextDelta)(d => print(d.text))
 .on(Checked)(c => println(s"checked ${c.path}"))
 .otherwise {
   case StreamEvent.LiveGap(n) => println(s"[$n live events lost]")
   case _                      => ()
 }
agent.stream(threadId, query)(handlers)

An event is looked up once by its name and version - a durable RunEvent.Custom or a StreamEvent.Live alike - and its payload decoded once, by the one type registered for them. R is what a handler returns: Unit for a listener, or a caller's own type, to turn a run's events into a stream of one ADT (on(Checked)(MyEvent.Checked(_)), the effect modules' events).

An EventHandlers is a listener (StreamEvent => Unit): pass it to Agent.stream, AgentRun.subscribe or GraphRuntime.subscribe. As a listener it runs dispatch and discards the result; a handler that throws is a listener that throws.

Attributes

Companion
object
Graph
Supertypes
trait StreamEvent => Unit
class Object
trait Matchable
class Any

Members list

Value members

Concrete methods

def apply(event: StreamEvent): Unit

Runs dispatch, discarding its result.

Runs dispatch, discarding its result.

Attributes

def dispatch(event: StreamEvent): Option[R]

The result of the handler for event: the one registered for its name and version, given the decoded payload, or else otherwise's; None when neither takes it.

The result of the handler for event: the one registered for its name and version, given the decoded payload, or else otherwise's; None when neither takes it.

Attributes

def on[A, R2 >: R](eventType: EventType[A])(handler: A => R2): EventHandlers[R2]

These handlers, with handler for events of eventType's name and version; it replaces a handler already registered for them.

These handlers, with handler for events of eventType's name and version; it replaces a handler already registered for them.

Attributes

def otherwise[R2 >: R](handler: StreamEvent => R2): EventHandlers[R2]

These handlers, with handler for every event no handler takes: a kernel event, a LiveGap, a Disconnected, an event of an unregistered name or version, or a payload that does not decode. Without it those are skipped. It replaces an earlier otherwise.

These handlers, with handler for every event no handler takes: a kernel event, a LiveGap, a Disconnected, an event of an unregistered name or version, or a payload that does not decode. Without it those are skipped. It replaces an earlier otherwise.

Attributes

override def toString: String

Returns a string representation of the object.

Returns a string representation of the object.

The default representation is platform dependent.

Attributes

Returns

a string representation of the object.

Definition Classes
Function1 -> Any

Inherited methods

def andThen[A](g: Unit => A): StreamEvent => A

Attributes

Inherited from:
Function1
def compose[A](g: A => StreamEvent): A => Unit

Attributes

Inherited from:
Function1