LemonCliRunners.KimiSubagent (lemon_cli_runners v0.1.0)

View Source

High-level API for using Kimi (Kimi CLI) as a collaborating subagent.

This module provides a convenient interface for spawning Kimi CLI sessions and interacting with them over time. Unlike one-shot LLM calls, Kimi subagents maintain state across multiple prompts when a resume token is provided.

Summary

Types

A Kimi subagent session

Normalized event from the subagent

Functions

Collect the final answer from the session.

Continue an existing session with a follow-up prompt.

Get the event stream as an enumerable of normalized events.

Resume an existing Kimi session with a new prompt.

Return the resume token for a session if available.

Run a Kimi task synchronously and return the answer.

Start a new Kimi subagent session.

Types

session()

@type session() :: %{
  pid: pid(),
  stream: LemonAgent.EventStream.t(),
  resume_token: LemonCore.ResumeToken.t() | nil,
  token_agent: pid() | nil,
  cwd: String.t()
}

A Kimi subagent session

subagent_event()

@type subagent_event() ::
  {:started, LemonCore.ResumeToken.t()}
  | {:action, action :: map(), phase :: atom(), opts :: keyword()}
  | {:completed, answer :: String.t(), opts :: keyword()}
  | {:error, reason :: term()}

Normalized event from the subagent

Functions

collect_answer(session)

@spec collect_answer(session()) :: String.t()

Collect the final answer from the session.

continue(session, prompt, opts \\ [])

@spec continue(session(), String.t(), keyword()) ::
  {:ok, session()} | {:error, term()}

Continue an existing session with a follow-up prompt.

events(session)

@spec events(session()) :: Enumerable.t()

Get the event stream as an enumerable of normalized events.

resume(token, opts)

@spec resume(
  LemonCore.ResumeToken.t(),
  keyword()
) :: {:ok, session()} | {:error, term()}

Resume an existing Kimi session with a new prompt.

resume_token(session)

@spec resume_token(session()) :: LemonCore.ResumeToken.t() | nil

Return the resume token for a session if available.

run!(opts)

@spec run!(keyword()) :: String.t()

Run a Kimi task synchronously and return the answer.

start(opts)

@spec start(keyword()) :: {:ok, session()} | {:error, term()}

Start a new Kimi subagent session.