AgUiBackend

class AgUiBackend(endpoint: String, apiKey: String = "", tools: List<AgentTool> = emptyList(), approver: ToolApprover = ToolApprover.AlwaysApprove, context: List<Pair<String, String>> = emptyList(), threadId: String? = null, client: OkHttpClient = DefaultHttpClient, maxRuns: Int = 8, eventLog: AgUiEventLog? = null, clock: () -> Long = System::currentTimeMillis) : ChatBackend(source)

The AG-UI protocol (1.x): POST a RunAgentInput, receive the run's events over SSE. Served by Pydantic AI, LangGraph, CrewAI, Mastra, and the bundled server/main.py at /api/agui.

The agent runs server-side; this backend implements the client half of the protocol:

  • Frontend tools: tools are advertised in RunAgentInput.tools. When the agent calls one, the run finishes with the call pending; the tool runs here (after approver if it needs approval) and a follow-up run carries the tool message.

  • Interrupts (human in the loop): a run finishing with outcome: interrupt asks approver — to decide on a tool call (the resume payload is {approved, reason?, editedArgs?}, AG-UI's approve-with-edits pattern), or, without a tool call, for input matching the interrupt's responseSchema (ToolApprover.input) — then resumes with RunAgentInput.resume (resolved with the payload, or cancelled).

  • Subagents: SUBAGENT_STARTED and the events carrying its subagentRunId are folded into the delegating tool call's nested run.

  • Shared state: STATE_SNAPSHOT / STATE_DELTA (JSON Patch) become a state data part, sent back as RunAgentInput.state on the next turn; ACTIVITY_* become data parts named by their activityType; steps a chain-of-thought part.

  • Context: context entries (e.g. capability instructions) go into RunAgentInput.context.

Constructors

Link copied to clipboard
constructor(endpoint: String, apiKey: String = "", tools: List<AgentTool> = emptyList(), approver: ToolApprover = ToolApprover.AlwaysApprove, context: List<Pair<String, String>> = emptyList(), threadId: String? = null, client: OkHttpClient = DefaultHttpClient, maxRuns: Int = 8, eventLog: AgUiEventLog? = null, clock: () -> Long = System::currentTimeMillis)

Types

Link copied to clipboard
object Companion

Functions

Link copied to clipboard
open override fun stream(history: List<Message>): Flow<ChatEvent>