For the complete documentation index, see llms.txt. Markdown versions of all docs pages are available by appending .md to any docs URL.
Declarative agents
Build an agent from a system prompt, tools, skills, and plugins, and let the kagent harness run the agentic loop.
A declarative agent is an agent that you describe rather than build. In an AgentTemplateAgentTemplateA Kubernetes custom resource defining what an agent does: its model, system prompt, tools, skills, and plugins. It runs only once an Agent pairs it with a Harness.Learn more resource, you write a system prompt, name a model, and bind the tools, skills, and plugins that the agent can use. The kagent HarnessHarnessA Kubernetes custom resource defining how an agent is allowed to run: which harness executes the agent, its workload image, and its WorkerPool and snapshot storage. An Agent pairs it with the AgentTemplate that it runs.Learn more then runs kagent’s built-in Go engine, which reads the AgentTemplate configuration and runs the agentic loop from it. To change what the agent does, you edit the AgentTemplate.
Declarative agents and BYO agents
kagent runs an agent in one of two ways depending on who owns the agentic loop. A declarative agent hands the loop to kagent. A BYO agent keeps the loop inside a container image that you build and maintain, and kagent runs the image instead.
| Declarative agent | BYO agent | |
|---|---|---|
| Harness | kagent | byo |
| What executes the agent | kagent’s built-in Go engine | The container image that you build |
| Where the behavior is defined | The AgentTemplate | The image, which might read the AgentTemplate |
| Changing the behavior | Edit the AgentTemplate | Rebuild the image, unless the image reads the configuration that kagent delivers |
| Structured output, long-term memory, and UI file attachments | Supported | Unsupported |
Both routes receive the same resolved agent configuration, run in the same sandbox, follow the same snapshot policy, and route through the same gateway. For how a BYO image reads that configuration, and what its agent card leaves out, see Compare BYO and declarative agents.
The codex and claude harnesses provide a third route, in which a coding agent owns the loop and takes its configuration from the AgentTemplate. To compare all options side by side, see Choose a harness.
Configure the kagent harness
Define settings that belong to the engine rather than to the agent in the spec.kagent section of the Harness resource. The section takes memory settings, which persist facts across conversations, and compaction settings, which keep a single conversation’s prompt within a limit as the conversation grows.
spec:
kagent:
memory:
modelConfigRef:
name: embedding-model-config
ttlDays: 30
compaction:
tokenThreshold: 120000
eventRetentionSize: 20Compaction offers two strategies. Tail retention summarizes the older history once the prompt passes a token count, while a sliding window summarizes each group of completed invocations as the conversation goes. Setting compaction requires at least one of these two strategies, and setting both is valid. For the rules that the API server enforces, see Context management.
| Field | Description |
|---|---|
memory.modelConfigRef.name | The ModelConfigModelConfigA Kubernetes custom resource naming one model at one provider, along with the credentials to reach it. An AgentTemplate references one by name, and every agent compiled from that template calls the model that it names.Learn more that supplies the embedding model, in the Harness’s namespace. Required when memory is set. Setting memory gives every agent on this Harness memory that persists across conversations. For how agents store and retrieve it, see Agent memory. |
memory.ttlDays | How many days a stored memory entry stays valid. Minimum 1. When omitted, the server applies a default of 15 days. |
compaction.tokenThreshold | Tail retention. The prompt token count that triggers a summary. Once the prompt passes this count, kagent summarizes the older history before the next model call. Requires compaction.eventRetentionSize. |
compaction.eventRetentionSize | Tail retention. The number of most recent events that kagent leaves out of that summary, so the latest exchanges reach the model in full. Requires compaction.tokenThreshold. |
compaction.compactionInterval | Sliding window. The number of new user-initiated invocations that triggers a summary of those invocations. Set 5 to summarize each group of five. |
compaction.overlapSize | Sliding window. The number of already-summarized invocations that kagent includes in the next summary, so that consecutive summaries overlap and carry context forward. Requires compaction.compactionInterval. |
compaction.summarizer | Both strategies. The ModelConfig and prompt template that write the summaries. When omitted, kagent summarizes with the agent’s own model and the engine’s default prompt. |
For the fields that every Harness shares, such as the workload image and the Agent Substrate placement, see Configure a Harness.
Apply a complete declarative agent
The following example applies a declarative agent end to end, from the ModelConfig to the Agent that runs it. The ModelConfig reads its API key from the kagent-openai Secret that the OpenAI guide creates. spec.kagent is an empty object because memory and compaction are both optional.
kubectl apply -f - <<EOF
apiVersion: api.kagent.dev/v1alpha3
kind: ModelConfig
metadata:
name: kagent-model-config
namespace: kagent
spec:
apiKeySecret: kagent-openai
apiKeySecretKey: OPENAI_API_KEY
model: gpt-4o-mini
provider: OpenAI
openAI: {}
---
apiVersion: api.kagent.dev/v1alpha3
kind: Harness
metadata:
name: kagent-harness
namespace: kagent
spec:
kagent: {}
workload:
image: ghcr.io/kagent-dev/kagent/golang-adk@sha256:ae01c3a6d7e0ed2e044253a26abbfb1a9426f3176363842ca9a954762c274d36
substrate:
workerPoolRef:
name: kagent-default
snapshotPolicy:
location: s3://ate-snapshots/kagent/
---
apiVersion: api.kagent.dev/v1alpha3
kind: AgentTemplate
metadata:
name: kagent-template
namespace: kagent
spec:
modelConfig:
name: kagent-model-config
systemPrompt: You are a concise, helpful assistant.
---
apiVersion: api.kagent.dev/v1alpha3
kind: Agent
metadata:
name: my-agent
namespace: kagent
spec:
template:
ref:
name: kagent-template
harnessRef:
name: kagent-harness
EOFTo confirm that the Agent is ready, run the following command. In the output, READY reports whether kagent built and prepared a revisionRevisionThe compiled, immutable output of one Agent, identified by a content digest. A Session runs the revision it was created from for its whole life, so editing the Agent affects only sessions created afterward. for the pair.
kagent agent get my-agentA READY value of False immediately after you apply the Agent is expected, because kagent builds a snapshot of the agent before it reports the Agent ready. If READY stays False, read the conditions on the Agent to find the stage that failed, asdescribed in Your first agent. To start a conversation with the agent, see Create a Session.