Skip to content

Create a prompt library

Page as Markdown

Create a library of reusable prompt fragments in the kagent UI.

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

  1. Install kagent.

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 dashboard

The command forwards the UI to http://localhost:8082 and opens it in your browser. Leave it running while you work.

Create the library

The kagent UI creating a prompt library named assistant-prompts with two fragments
Figure: Creating a prompt library with two fragments, sped up
  1. In the sidebar, click Prompts, and then click New Library.

  2. In the Name field, enter assistant-prompts. Leave the Namespace as kagent.

  3. Click Add fragment, and enter a key and the fragment text.

    KeyFragment text
    toneBe friendly and concise. Use plain language and short sentences.
  4. Click Add fragment again, and add a second fragment.

    KeyFragment 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" }}.

  5. 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 include tag where the fragment belongs. For the YAML, see Template the prompt.

Verify the library

  1. Check that kagent stored the library as a labeled ConfigMap.

    kubectl get configmap -n kagent -l kagent.dev/prompt-library=true

    The output lists assistant-prompts, beside the built-in kagent-builtin-prompts library.

  2. 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:

FeatureWhat you didRead more
Prompt librariesStored reusable prompt fragments in one labeled ConfigMapSystem prompts
Prompt templatingSaw the include tag that pulls a fragment into a promptTemplate the prompt

Clean up

  1. Delete the library. If an agent still includes one of its fragments, change that agent first.
    kubectl delete configmap assistant-prompts -n kagent

Next steps