prompt.ts
This file offers general tools for working with prompt templates and parsing
structured (XML) responses, separate from the main agent prompt defined in
prompts/main.ts
. It provides createPrompt
for making reusable prompt
templates and createParser
for defining how to extract data from XML text into
a specific JavaScript object structure.
How to Use
While the core agent loop uses its own specific prompt, you might use these
helpers in more advanced scenarios, perhaps within an action
handler:
-
createPrompt
: If an action needs to call another LLM for a sub-task, you could usecreatePrompt
to define a reusable template for that specific sub-task prompt. -
createParser
: If an action receives a complex XML response from an external system (or perhaps even from a specialized LLM call), you could usecreateParser
to define precisely how to extract the necessary data from the XML tags into a structured JavaScript object.
Benefit
Provides flexible utilities for developers who need to implement custom prompt
generation or response parsing logic within their actions or extensions, beyond
the standard agent interaction loop. createPrompt
helps manage reusable prompt
strings, and createParser
offers a structured way to handle custom XML parsing
needs.
Anticipated Questions
- "Is this the main prompt the agent uses?" No, the main prompt template and
its formatting logic are primarily defined in
packages/core/src/prompts/main.ts
. This file (prompt.ts
) provides more general, optional tools for custom prompt/parsing scenarios. - "When would I need
createParser
?" It's less common, but potentially useful if an action interacts with a system that returns data in a specific XML format, and you want a structured way to extract information based on tag names.