Templates (Prompt Templates)

[!TIP]

Location within the framework Hive-agent-framework/template.

Template is a predefined structure or format used to create consistent documents or outputs. It often includes placeholders for specific information that can be filled in later.

Prompt template, on the other hand, is a specific type of template used in the context of language models or AI applications. It consists of a structured prompt that guides the model in generating a response or output. The prompt often includes variables or placeholders for user input, which helps to elicit more relevant or targeted responses.

The Framework exposes such functionality via the PromptTemplate class, which is based on the well-known Mustache.js template system, which is supported almost in every programming language. In addition, the framework provides type safety and validation against appropriate `code schema, as you can see in the following examples.

[!TIP]

The Prompt Template concept is used anywhere - especially in our agents.

Usage

Primitives

import { PromptTemplate } from "Hive-agent-framework/template";
import { z } from "zod";

const greetTemplate = new PromptTemplate({
  template: `Hello {{name}}`,
  schema: z.object({
    name: z.string(),
  }),
});

const output = greetTemplate.render({
  name: "Alex",
});
console.log(output); // Hello Alex!

Source: examples/templates/primitives.ts

Arrays

Source: examples/templates/arrays.ts

Objects

Source: examples/templates/objects.ts

Forking

Source: examples/templates/forking.ts

Functions

Source: examples/templates/functions.ts

Agents

The Hive Agent internally uses multiple prompt templates, and because now you know how to work with them, you can alter the agent’s behavior.

The internal prompt templates can be modified here.