LlmBroker

class LlmBroker(gateway: LlmGateway, tracer: Tracer = NullTracer, toolRunner: ToolRunner = SerialToolRunner(), json: Json = DEFAULT_JSON)

Coordinator above an LlmGateway that handles tool execution and provides a Kotlin-idiomatic chat surface.

The broker is the primary integration point for application code. It:

  • Forwards single-shot, streaming, and structured-output requests to the gateway.

  • Dispatches tool calls through a ToolRunner (serial by default) and recursively re-prompts the LLM with the tool results.

  • Honours CompletionConfig.maxToolIterations as a hard recursion ceiling.

  • Records observability hooks to a Tracer (no-op by default).

The broker is stateless from the caller's point of view: each call carries its own message list. Use ChatSession (Phase 2) when you want managed conversation state.

Constructors

Link copied to clipboard
constructor(gateway: LlmGateway, tracer: Tracer = NullTracer, toolRunner: ToolRunner = SerialToolRunner(), json: Json = DEFAULT_JSON)

Types

Link copied to clipboard
object Companion

Functions

Link copied to clipboard
suspend fun complete(model: String, messages: List<LlmMessage>, tools: List<LlmTool> = emptyList(), config: CompletionConfig = CompletionConfig(), correlationId: String? = null): LlmGatewayResponse
Link copied to clipboard
inline suspend fun <T> completeJson(model: String, messages: List<LlmMessage>, config: CompletionConfig = CompletionConfig(), correlationId: String? = null): T
Link copied to clipboard
suspend fun generateResponse(model: String, messages: List<LlmMessage>, tools: List<LlmTool> = emptyList(), config: CompletionConfig = CompletionConfig(), correlationId: String? = null): LlmGatewayResponse

Return one native response without dispatching tools or changing context.

Link copied to clipboard
fun generateStreamEvents(model: String, messages: List<LlmMessage>, config: CompletionConfig = CompletionConfig(), correlationId: String? = null): Flow<CompletionStreamEvent>

Stream one turn as CompletionStreamEvents with terminal completion evidence.

Link copied to clipboard
fun stream(model: String, messages: List<LlmMessage>, tools: List<LlmTool> = emptyList(), config: CompletionConfig = CompletionConfig(), correlationId: String? = null): Flow<StreamEvent>