Prompt ManagementΒΆ
AgentHeaven uses a combination of Jinja2 templating and Babel for powerful and flexible prompt management. This approach allows you to separate prompt structures from the content, making it easy to manage, version, and localize prompts for different languages.
For a detailed guide on the underlying utilities, see Jinja Utilities.
1. How Jinja and Babel Work TogetherΒΆ
AgentHeaven combines Jinja2 and Babel to create a powerful internationalization (i18n) workflow for prompts. This allows you to write a single prompt template and render it in multiple languages. Hereβs how they interact:
Marking Translatable Text: In your
.jinjatemplates, you wrap any text that needs to be translated in{% trans %}...{% endtrans %}tags.Extraction: The
babelcommand-line tool (orbabel_initfunction) scans your templates, finds thesetransblocks, and extracts the text into a.pot(Portable Object Template) file. This file is a master list of all translatable strings.Translation: From the
.potfile, language-specific.po(Portable Object) files are created for each target language (e.g.,zhfor Chinese). Translators then fill in the corresponding translations for each string in these files. This step can be done manually or automated with theahvn babel translatecommand.Compilation: The completed
.pofiles are compiled into binary.mo(Machine Object) files using thebabel_compilefunction. These files are optimized for fast lookups at runtime.Rendering: When you load a Jinja environment with a specific language (e.g.,
lang="zh"), it automatically finds and uses the corresponding.mofile. When it encounters a{% trans %}block during rendering, it replaces the original text with the translated version.
This entire process allows for a clean separation of prompt logic from translations, making it easy to manage and scale multilingual agent applications.
For more details on using Jinja2 for templating, refer to the Template Processing documentation.
2. Template StructureΒΆ
Each template directory in AgentHeaven follows a consistent structure that supports templates, custom filters, and i18n:
template_directory/
βββ *.jinja # Jinja template files
βββ filters/ # Custom Jinja filters
β βββ *.py # Python filter modules
βββ locale/ # Babel i18n
βββ babel.cfg # Babel configuration
βββ messages.pot # Portable Object Template
βββ zh/LC_MESSAGES/ # Language-specific translations
βββ messages.po # Translation file
βββ messages.mo # Compiled translation
For more details on creating and using custom Jinja filters, refer to the Template Processing documentation.
3. Babel CLI CommandsΒΆ
The ahvn babel command group provides tools to manage the localization workflow.
3.1. ahvn babel initΒΆ
This command initializes the directory structure and configuration for Babel.
Usage:
ahvn babel init [PATH] [OPTIONS]
Arguments:
PATH: The directory to initialize. Defaults to the current directory.
Options:
-l, --langs: Specify target languages (e.g.,-l en -l zh).-m, --main: The main (source) language.-o, --overwrite: Overwrite existing translation files.-e, --encoding: Encoding for the Babel configuration file.
3.2. ahvn babel translateΒΆ
Uses a Large Language Model (LLM) to automatically translate .po files from the source language to the target language(s).
Usage:
ahvn babel translate [PATH] [OPTIONS]
Arguments:
PATH: The directory containing the.pofiles. Defaults to the current directory.
Options:
-s, --src-lang: Source language for translation.-t, --tgt-lang: Target language for translation.-o, --overwrite: Overwrite existing translations in the.pofiles.-b, --batch-size: Number of entries to process in a single batch.-h, --hint: Provide hints to the LLM for translation.-p, --llm-preset: The LLM preset to use for translation (e.g.,translator).
3.3. ahvn babel compileΒΆ
Compiles the .po translation files into .mo files, which are binary files used by the application at runtime.
Usage:
ahvn babel compile [PATH] [OPTIONS]
Arguments:
PATH: The directory containing the.pofiles. Defaults to the current directory.
Options:
-l, --langs: Specify which languages to compile.-m, --main: The main (source) language.
Further ExplorationΒΆ
Tip: For more information about Prompts in AgentHeaven, see:
Template Processing - Jinja + Babel templating utilities in Python
Tip: For more information about CLI usage in AgentHeaven, see:
LLM Inference - LLM inference tools in CLI
LLM Session - LLM interactive sessions in CLI
Knowledge Management - Knowledge base management in CLI
Repo Management - Project init, config, and management in CLI