Installation
Initialisation
kairn.invoke()
Run an agent for a user. Waits for the full response.
InvokeResult:
kairn.stream()
Stream an agent invocation as typed events. Same params as invoke.
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.
invoke(), plus:
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.
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: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:
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
The soul’s identity, personality, and instructions (markdown). This becomes the agent’s system prompt.
.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
Behavioral guide injected into the system prompt. At least one of
instructionsMd or webhookUrl required.