PublisherRunner

Java-friendly wrapper around a Runner. A run is exposed as a Reactive Streams Publisher of events, so Java callers never touch Flow; collect it with AsyncJavaHelpers.collect/forEach or any Reactive Streams consumer. Session management is not a runner concern: to call the session service from Java, create it wrapped in a CompletableFutureSessionService and build the runner with the wrapper's asKotlinSessionService().

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard

Functions

Link copied to clipboard

The wrapped engine runner, for code that has dropped into Kotlin.

Link copied to clipboard
open override fun close()

Closes the runner and cancels pending rewinds, but not runs in flight; cancel their subscriptions first.

Link copied to clipboard
fun rewindAsync(userId: String, sessionId: String, rewindBeforeInvocationId: String, coroutineContext: CoroutineContext = EmptyCoroutineContext): CompletableFuture<Void?>

Rewinds the session to before rewindBeforeInvocationId; see Runner.rewindAsync. The returned future completes once the rewind has been applied. The rewind runs in the caller's OpenTelemetry context and in coroutineContext, as in runAsync.

Link copied to clipboard
fun runAsync(userId: String, sessionId: String, invocationId: String? = null, newMessage: Content? = null, stateDelta: Map<String, Any>? = null, runConfig: RunConfig? = null, coroutineContext: CoroutineContext = EmptyCoroutineContext): Publisher<Event>

Runs the agent, streaming its events; set invocationId to resume an interrupted invocation. The run, including tool calls and the subscriber's onNext, executes on Dispatchers.IO in the OpenTelemetry context current at this call, with coroutineContext added: pass MDCContext() from kotlinx-coroutines-slf4j to carry the caller's MDC, or a dispatcher to use instead of IO. A Job in coroutineContext has no effect, so cancel the run through its subscription.

Link copied to clipboard
fun runLive(userId: String, sessionId: String, liveRequestQueue: LiveRequestQueue, runConfig: RunConfig? = null, coroutineContext: CoroutineContext = EmptyCoroutineContext): Publisher<Event>

Experimental: runs the root agent or node live, streaming the whole run's events (see Runner.runLive). Each subscription starts its own run, which ends as Runner.runLive describes, and a second one reading the same queue at once fails; cancelling the subscription closes any connection and leaves the queue open. As in runAsync, the run and onNext execute on Dispatchers.IO, not on the thread that sends to the queue, in the OpenTelemetry context current at this call, with coroutineContext added; hand slow work in onNext to your own executor.