Skip to main content

Installation

Initialisation


kairn.invoke()

Run an agent for a user. Waits for the full response.
Returns InvokeResult:
string
The agent’s final text response.
string
Unique ID for this invocation — use for audit log lookup.
Record<string, string>
Memory keys written during this turn.
ToolCall[]
All tool calls the agent made during this turn.
"completed" | "failed"
Final status of the invocation.
number
Input tokens consumed.
number
Output tokens generated.
number
Wall-clock time for the full invocation.

kairn.stream()

Stream an agent invocation as typed events. Same params as invoke.
Event types:

Next.js App Router streaming


kairn.invokeAsync()

Queue an agent invocation as a background job. Returns a JobHandle immediately — no connection held open, no timeout risk. Best for long-running tasks, automations, and workflow triggers.
Params — same as invoke(), plus:
string
Optional URL to POST the result to when the job completes. Useful when you don’t want to poll — Kairn pushes the result to you.
Returns JobHandle:

job.jobId

The unique job ID. Store this if you need to look up the result from a different process.

job.poll() → AsyncJob

Check the current status once.

job.wait(options?) → InvokeResult

Auto-polls until the job reaches a terminal state, then returns the full result. Throws KairnError on failure or timeout.

Common patterns

Fire and store for later:
With webhook — no polling needed:

kairn.jobs

Look up any async job by ID. Useful when you stored the job_id and need to check it from a different process or request.

.get(jobId) → AsyncJob

AsyncJob fields:
string
Unique job ID.
"pending" | "running" | "completed" | "failed"
Current state. Poll until completed or failed.
string | undefined
The agent’s response. Only present when status === 'completed'.
string | undefined
Error message. Only present when status === 'failed'.
Record<string, string> | undefined
Memory keys written during the run. Only present when completed.
number | undefined
number | undefined
number | undefined

kairn.memory

.get(userId, role) → MemoryMap

.get(userId) → MemorySummary

.set(userId, role, delta)

Write keys to memory. Set a key to null to delete it.

.delete(userId)

Wipes all memory for a user across all roles. Use on account deletion.

kairn.souls

.list() → Soul[]

.create(params) → Soul

string
required
Internal name — used in invoke calls as agent.
string
Human-readable label shown in the dashboard.
string
The soul’s identity, personality, and instructions (markdown). This becomes the agent’s system prompt.
string
Model identifier e.g. anthropic/claude-sonnet-4-6, openai/gpt-4o.
string[]
Tools this soul may use. Options: bash, read, write, edit, web_search.

.update(name, params) → Soul


kairn.skills

Manage custom skills: instruction-only (prompt injection) or webhook tools. Souls reference skills via allowed_skills.

.list() → Skill[]

.create(params) → Skill

string
required
Internal name — lowercase letters, digits, underscores. Used in soul allowed_skills.
string
required
Human-readable label.
string
Behavioral guide injected into the system prompt. At least one of instructionsMd or webhookUrl required.
string
Short tool description (used when webhookUrl is set).
string
When set, the skill is a callable webhook tool.
string
HTTP method for webhook calls. Default POST. One of: GET, POST, PUT, PATCH, DELETE.
object
Parameters/schema for the webhook. Default {}.
object
Headers sent with webhook requests. Default {}.

.get(skillName) / .update(skillName, params) / .delete(skillName)


kairn.mandates

.create(params) → Mandate

string
required
The user this mandate runs for.
string
required
Soul name to run.
string
required
Human-readable label.
string
required
The task the agent will execute each time the mandate fires.
object
required
{ type: 'cron', cron: '0 9 * * 1' } — standard cron expression (UTC).

.list() / .get(id) / .pause(id) / .cancel(id)


kairn.invocations

.list(params) → InvocationListResult

.get(invocationId) → Invocation


Error handling


TypeScript

The SDK ships full type definitions. All types are exported: