AgentHarness

class AgentHarness(model: ModelBinding, capabilities: suspend () -> List<Capability> = { emptyList() }, localSubAgents: suspend () -> List<LocalSubAgent> = { emptyList() }, remoteSubAgents: suspend () -> List<SubAgent> = { emptyList() }, maxDepth: Int = 2)(source)

An in-app agent: a model plus capabilities (tools, skills, MCP servers…), served as a ChatBackend for dev.ai.elements.core.chat.ChatController — the Kotlin counterpart of a Pydantic AI agent with Harness capabilities.

Every turn re-reads the providers (they are suspend so they can reflect the user's current settings and do I/O such as listing MCP tools). Sub-agents are exposed through SubAgents (delegate_task): localSubAgents run on this harness with its capabilities, remoteSubAgents are ready-made (e.g. A2A agents from ai-elements-a2a). Delegation is limited to maxDepth levels, counting the top-level run, like Harness' max_depth.

val harness = AgentHarness(
model = profile.model(apiKey),
capabilities = { listOf(Skills.from(library), mcpServers.toolset()) },
localSubAgents = { listOf(LocalSubAgent("researcher", "Researches topics", "Be thorough.")) },
)
val chat = ChatController(backend = harness::backend, scope = viewModelScope)

Constructors

Link copied to clipboard
constructor(model: ModelBinding, capabilities: suspend () -> List<Capability> = { emptyList() }, localSubAgents: suspend () -> List<LocalSubAgent> = { emptyList() }, remoteSubAgents: suspend () -> List<SubAgent> = { emptyList() }, maxDepth: Int = 2)

Functions

Link copied to clipboard

The backend of the next turn; pass it as ChatController(backend = harness::backend).

Link copied to clipboard
suspend fun AgentHarness.runHeadless(prompt: String, approver: ToolApprover = ToolApprover { false }): Message

runHeadless on this harness. Nobody can approve tools here, so calls that need approval are denied unless approver says otherwise.