TemplateFormatter: Jinja2-template-based formatter for legacy backends.
TemplateFormatter extends [ChatFormatter](chat_formatter#class-chatformatter) to look up a per-component Jinja2
template at rendering time, allowing each [Component](../core/base#class-component) type to control its own
prompt representation. Template discovery walks a configurable template_path and
the built-in templates directory; results are cached in a [SimpleLRUCache](../backends/cache#class-simplelrucache) for
performance. Use this formatter when your backend requires hand-crafted prompts
rather than a generic chat-message rendering.
Classes
CLASS TemplateFormatter
Formatter that uses Jinja2 templates to render components into prompt strings.
Template discovery walks a configurable template_path and the built-in
templates directory. Results are optionally cached in a [SimpleLRUCache](../backends/cache#class-simplelrucache)
for performance. Use this formatter when your backend requires hand-crafted
prompts rather than generic chat-message rendering.
Args:
model_id: Describes the model for which templates will be looked up. Should match the template directory structure.template_path: An alternate location where templates can be found. Will be preferred over all other template directories even if a less exact match is found. Defaults to"".use_template_cache: WhenTrue, caches template lookup results. Set toFalseif you plan to changemodel_idortemplate_pathafter construction. Defaults toTrue.
FUNC print
c: The component or code block to render.
- The rendered string representation of the component.