Create a prompt library
Create a library of reusable prompt fragments in the kagent UI.
About this tutorial
A prompt library is a named set of prompt fragments, such as a tone of voice or a list of safety rules. Agents include a fragment by its key, so the text lives in one place and a change reaches every agent that uses it. kagent installs one library, kagent-builtin-prompts. In this tutorial, you create your own in the kagent UI. For how an agent’s prompt is built, see System prompts.
Time: about 10 minutes.
Before you begin
Create and use a prompt library
Follow the steps in the kagent UI, or apply the same resources as YAML from the command line.
Open the kagent UI
kagent dashboardThe command forwards the UI to http://localhost:8082 and opens it in your browser. Leave it running while you work.
Create the library

In the sidebar, click Prompts, and then click New Library.
In the Name field, enter
assistant-prompts. Leave the Namespace askagent.Click Add fragment, and enter a key and the fragment text.
Key Fragment text toneBe friendly and concise. Use plain language and short sentences.Click Add fragment again, and add a second fragment.
Key Fragment text safety-rulesNever share personal data. Say so when you are not sure of an answer.Beside each fragment, the form shows the tag that pulls the fragment into a prompt, such as
{{ include "assistant-prompts/tone" }}.Click Create library. The Prompts page lists the library with its keys.
Use a fragment in an agent
kagent stores a library as a ConfigMap of the same name, in the namespace that you chose. An agent can use it in two ways.
- As the whole system prompt: In the template form, set System prompt to Read from a ConfigMap, so that the prompt comes from one key of the library.
- As part of a prompt: List the library as a data source of the template, and place the
includetag where the fragment belongs. For the YAML, see Template the prompt.
Verify the library
Check that kagent stored the library as a labeled ConfigMap.
kubectl get configmap -n kagent -l kagent.dev/prompt-library=trueThe output lists
assistant-prompts, beside the built-inkagent-builtin-promptslibrary.Read one fragment back.
kubectl get configmap assistant-prompts -n kagent -o jsonpath='{.data.tone}'Example output:
Be friendly and concise. Use plain language and short sentences.
What you built
A prompt library with two fragments that any agent in the namespace can include. Along the way, you used these features:
| Feature | What you did | Read more |
|---|---|---|
| Prompt libraries | Stored reusable prompt fragments in one labeled ConfigMap | System prompts |
| Prompt templating | Saw the include tag that pulls a fragment into a prompt | Template the prompt |
Clean up
- Delete the library. If an agent still includes one of its fragments, change that agent first.
kubectl delete configmap assistant-prompts -n kagent