← Guides
Extend kcode

Change how the agent loop proceeds

Extend the process around the model, not just the list of things it can call.

Understand a turn first

The agent loop assembles context, requests a model response, checks tool requests, executes tools, and returns results to the model. It repeats until the work finishes or a limit stops it. Extensions can observe or intervene at supported points along that process.

Observe without changing the result

Event handlers can record turn boundaries or react to timer ticks and other published events. Observation is appropriate when you need logging or a follow-up action, rather than changing the current request.

Transform or gate before an action

Input transforms can rewrite or veto an incoming prompt. Tool gates can reject a proposed tool call. Supported intercept points allow pass, veto, or rewrite behavior around operations such as provider requests, compaction, and continuation.

Act from plugin code

Available host APIs let plugins inject messages, invoke session tools, and dispatch subagents. These are capability-gated operations, not permission to bypass the session’s safety rules.

Put a limit on a provider request

The guardrails example inspects a request before it reaches the model provider and reduces an excessive output-token limit. Other handlers defer compaction while tools are running or stop continuation after a chosen number of rounds. Each handler changes one decision in the loop.

Explore this area