TheDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/Effectful-Tech/clanka/llms.txt
Use this file to discover all available pages before exploring further.
Agent.send() method returns a Stream<Output, AgentFinished | AiError>. Each element of the stream is a tagged class that describes one moment in the agent’s execution — from startup through script runs, reasoning traces, sub-agent delegation, and token usage reporting.
Output union
Output is the top-level discriminated union. Every event has a _tag string discriminant matching the class name.
Agent lifecycle events
AgentStart
Emitted once at the beginning of each agent run, before any model output is produced.Monotonically increasing identifier for this agent invocation. Sub-agents receive their own unique
id.The full structured prompt sent to the model for this turn.
The model provider name (e.g.
"anthropic", "openai"), sourced from Model.ProviderName in context.The model identifier (e.g.
"claude-opus-4-5"), sourced from Model.ModelName in context.AgentFinished
A tagged error class — the stream fails with this value when the agent completes. It is not emitted as a regular stream element; catch it withStream.catchTag("AgentFinished", ...) or Effect.catchTag("AgentFinished", ...).
The final summary text produced by the agent when it called
taskComplete. Empty string when the agent is in conversation mode.AgentFinished is a normal, expected termination signal — not an unhandled failure. Always handle it explicitly to retrieve the agent’s summary.Reasoning events
These three events bracket a block of extended thinking / chain-of-thought output. They arrive in order:ReasoningStart → one or more ReasoningDelta → ReasoningEnd.
ReasoningStart
Signals that the model has begun a reasoning block.ReasoningDelta
A chunk of reasoning text.Incremental reasoning text. Concatenate all
ReasoningDelta.delta values between a ReasoningStart / ReasoningEnd pair to reconstruct the full reasoning block.ReasoningEnd
Signals that the current reasoning block is complete.Script execution events
The agent writes and executes JavaScript scripts through theexecute tool. These events track the full lifecycle of each script.
ScriptStart
Emitted when the model begins writing a script to theexecute tool.
ScriptDelta
A chunk of script content as the model streams it.Incremental script text. Concatenate all
ScriptDelta.delta values between ScriptStart and ScriptEnd to reconstruct the full script source.ScriptEnd
Emitted when the complete script has been received and submitted to the executor sandbox.ScriptOutput
The result of running the script — allconsole output produced by the sandbox.
The full console output string from the script execution. This is what the model sees as the tool result and uses to decide next steps.
Sub-agent events
When a script calls a sub-agent, three events are emitted to track that nested invocation.SubagentStart
Emitted when a sub-agent is about to start executing.Unique identifier for this sub-agent invocation. Correlates
SubagentStart, SubagentPart, and SubagentComplete events.The plain-text prompt passed to the sub-agent.
The model identifier the sub-agent is using.
The model provider the sub-agent is using.
SubagentPart
Wraps an output event emitted by the sub-agent, tagged with the sub-agent’sid.
The sub-agent
id from the corresponding SubagentStart.A nested output event from the sub-agent’s own stream. Can be any
ContentPart variant (ReasoningDelta, ScriptOutput, etc.).SubagentComplete
Emitted when the sub-agent’s stream has finished.The sub-agent
id from the corresponding SubagentStart.The final summary from the sub-agent’s
AgentFinished error.Token usage
Usage
Emitted once per model response, after thefinish part arrives from the streaming API.
The number of input tokens for the current request (i.e. the context window used this turn).
Cumulative input tokens consumed across all turns in this agent session.
Cumulative output tokens produced across all turns in this agent session.
Error events
ErrorRetry
Emitted when the agent encounters a retryable error and is about to retry the current turn. The stream continues — this is an informational event, not a failure.The retryable error that triggered the retry. Common causes include rate-limit responses (
AiError.isRetryable === true) and turn timeout (TurnTimeout expiry, which generates an UnknownError with description "TurnTimeout was reached").