For the complete documentation index, see llms.txt. Markdown versions of all docs pages are available by appending .md to any docs URL.
Your first agent
Create and communicate with your first agent by using the kagent project.
This guide walks you through creating an agent, from applying a Harness and an AgentTemplate to holding a conversation with the AgentInstance that they produce. You apply the Harness and the AgentTemplate as Kubernetes resources, and you create and talk to the AgentInstance with the kagent CLI. For definitions of each of these components, review the core concepts. For an overview of how each component fits together in kagent, review the architecture. For the complete schema of every field that this guide sets, see the API reference.
Before you begin
Download the kagent CLI.
curl https://raw.githubusercontent.com/kagent-dev/kagent/refs/heads/main/scripts/get-kagent | bashInstall
jq, to read the AgentInstance ID out of the CLI’s JSON output.
Note
The CLI reaches the kagent controller at localhost:8083. When nothing serves that port, the CLI runs kubectl port-forward against the kagent-controller service for you, and closes the forward when the command exits. Keep kubectl on your path, and keep your kubeconfig pointed at the cluster that runs kagent.
Create a Harness and an AgentTemplate
Apply a
Harnessthat uses kagent’s native runtime. Itssubstratesection names the WorkerPool that this Harness’s Actors run on, and the object storage location for their snapshots.apiVersion: kagent.dev/v1alpha3 kind: Harness metadata: name: my-first-harness namespace: kagent spec: kagent: {} workload: # kagent's native runtime image, pinned by digest image: ghcr.io/kagent-dev/kagent/golang-adk@sha256:c8ab012e9774d50e20ffa8cd035ddebff69486a2843b3af281f5f6ebc67ab512 substrate: workerPoolRef: name: kagent-default snapshotPolicy: # The object storage location your cluster's Substrate installation uses for Actor snapshots location: gs://<your-bucket>/kagent/ allowedAgentTemplates: selector: matchLabels: # Selector to match the AgentTemplate label kagent.dev/harness: my-first-harnessNote
An
AgentTemplatehas no field naming this Harness. Thekagent.dev/harness: my-first-harnessselector is a convention that this guide uses to match thekagent.dev/harnesslabel in the next step. However, you can choose any label key and value, as long as the Harness selector and the AgentTemplate’s labels match.Apply an
AgentTemplatethat is labeled to match the Harness’sallowedAgentTemplatesselector. ThemodelConfigfield references thedefault-model-configModelConfigModelConfigA 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 was automatically created for the model provider API key that you provided during kagent installation.apiVersion: kagent.dev/v1alpha3 kind: AgentTemplate metadata: name: my-first-agent namespace: kagent labels: # Label matching the Harness selector kagent.dev/harness: my-first-harness spec: description: My first kagent agent modelConfig: # Default config created by the kagent install guide name: default-model-config systemPrompt: You are a concise, helpful assistant.Confirm that the pair is ready. The
HARNESScolumn lists each Harness that admitted this AgentTemplate, andREADYreports whether kagent compiled a runtime revisionRevisionThe compiled, immutable output of one Harness and AgentTemplate pairing, identified by a content digest. An AgentInstance runs the revision it was created from for its whole life, so editing either resource affects only instances created afterward. for that pairing.kagent get agent-template my-first-agentExample output:
+----------------+------------------+-------+----------------------+ | NAME | HARNESS | READY | CREATED | +----------------+------------------+-------+----------------------+ | my-first-agent | my-first-harness | TRUE | 2026-08-31T15:01:44Z | +----------------+------------------+-------+----------------------+An empty
HARNESScolumn with aREADYvalue ofUNKNOWNmeans that the kagent controller has not yet reconciled the pair. Wait a few seconds, then check again. IfREADYstaysFALSE, inspect the individual conditions to find which stage failed.kagent get agent-template my-first-agent -o jsonEach entry in
status.harnessesreports four conditions, ending inReady. TheAcceptedcondition covers the label selector match,ResolvedRefscovers the ModelConfig and tool references,Compatiblecovers whether the resolved configuration suits the Harness runtime, andReadycovers the compiled revision itself.
Create the AgentInstance
An AgentInstance is one running conversation. Creating it starts an Actor on the WorkerPool from the revision that kagent compiled for the Harness and AgentTemplate pair.
Create an AgentInstance from the Harness and AgentTemplate pair.
kagent create agent-instance --harness my-first-harness --agent-template my-first-agentThe command returns output only after the AgentInstance reaches the
READYstate. Example output:+--------------------------------------+----------------+------------------+-------+----------------------+ | ID | AGENT TEMPLATE | HARNESS | STATE | CREATED | +--------------------------------------+----------------+------------------+-------+----------------------+ | 0198c3d7-4f2a-7b61-9c3e-5d8f7a2b4e10 | my-first-agent | my-first-harness | READY | 2026-08-31T15:02:10Z | +--------------------------------------+----------------+------------------+-------+----------------------+An error reporting that the AgentTemplate and Harness have no ready prepared revision means that the pair is not
READYyet. Return to step 3 of the previous section to check the conditions.Save the AgentInstance’s ID to an environment variable.
export INSTANCE_ID=$(kagent get agent-instance -o json \ | jq -r '[.agentInstances[] | select(.agentTemplate.name == "my-first-agent")] | sort_by(.createdAt) | last | .id') echo $INSTANCE_ID
Talk to your agent
Send a message to the AgentInstance. The CLI holds the conversation over the A2AA2AThe Agent-to-Agent protocol, which callers and other agents use to talk to an AgentInstance. The conversation's context identifier is the AgentInstance ID, so a second message on the same ID continues the same conversation.Learn more (Agent-to-Agent) protocol.
kagent invoke --agent-instance $INSTANCE_ID --task "What is 2+2?"The agent’s reply prints as text.
4Send a follow-up message to the same AgentInstance. An AgentInstance holds the transcriptTranscriptThe record of an AgentInstance's conversation, held server-side and append-only. It survives the Actor suspending between turns, and a resumed runtime cannot shrink it. of its conversation, so the agent answers with the earlier turns in context.
kagent invoke --agent-instance $INSTANCE_ID --task "What did I just ask you?"You asked what 2+2 is.
Note
An AgentInstance gives its Worker back at the end of every turn. The AgentInstance itself stays READY, because suspension applies to the Actor running underneath it rather than to the conversation, and the next kagent invoke resumes that Actor automatically. To understand what happens to the Actor in between, see Suspend and resume.
The invoke command takes a few more options that are useful beyond a first conversation.
| Option | Description |
|---|---|
--file | Read the task from a file, or from standard input with -, instead of passing it inline with --task. |
--stream | Print the reply as the agent produces it, rather than waiting for the complete answer. |
Tip
Run kagent with no arguments to open an interactive workspace in your terminal, where you can browse your AgentInstances and chat with them without passing an ID to each command.
Clean up
Important
Other guides build on the Harness, AgentTemplate, and AgentInstance that you created here, including Your first MCP tool and Agent Substrate. Unless you are finished with the kagent guides, leave the resources in place.
To remove the resources, follow these steps.
Delete every AgentInstance that was created from the AgentTemplate. Later guides create their own instances from the same pair, so delete them all rather than only the one that you saved. Deleting the Harness and the AgentTemplate does not delete the AgentInstances that you created from them, so delete the instances first.
kagent get agent-instance -o json \ | jq -r '.agentInstances[] | select(.agentTemplate.name == "my-first-agent") | .id' \ | xargs -n1 kagent delete agent-instanceDelete the AgentTemplate and the Harness.
kubectl delete agenttemplate my-first-agent -n kagent kubectl delete harness my-first-harness -n kagent