Utilities and Support API¶
HoloDeck provides several utility modules for template rendering and error handling.
Template Engine¶
Jinja2-based template rendering for dynamic configuration and instruction generation.
TemplateRenderer()
¶
Renders Jinja2 templates and validates output against schemas.
Provides safe template rendering with: - Restricted Jinja2 filters for security - YAML validation against AgentConfig schema - Clear error messages for debugging
Initialize the TemplateRenderer with a secure Jinja2 environment.
Source code in src/holodeck/lib/template_engine.py
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | |
get_available_templates()
staticmethod
¶
Get available templates with metadata.
Discovers templates from the templates/ directory and extracts metadata (name, display_name, description) from their manifest.yaml files.
Returns:
| Type | Description |
|---|---|
list[dict[str, str]]
|
List of dicts with 'value', 'display_name', 'description' keys. |
list[dict[str, str]]
|
Returns empty list if templates directory doesn't exist. |
Source code in src/holodeck/lib/template_engine.py
237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 | |
list_available_templates()
staticmethod
¶
List all available built-in templates.
Discovers templates from the templates/ directory structure.
Returns:
| Type | Description |
|---|---|
list[str]
|
List of template names (e.g., ['conversational', 'research', |
list[str]
|
'customer-support']) |
Source code in src/holodeck/lib/template_engine.py
225 226 227 228 229 230 231 232 233 234 235 | |
render_and_validate(template_path, variables)
¶
Render a Jinja2 template and validate output (for YAML files).
Combines rendering and validation in a safe way: only returns rendered content if both rendering and validation succeed. This is the recommended way to process agent.yaml templates.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
template_path
|
str
|
Path to the Jinja2 template file |
required |
variables
|
dict[str, Any]
|
Dictionary of variables to pass to the template |
required |
Returns:
| Type | Description |
|---|---|
str
|
Rendered and validated template content as a string |
Raises:
| Type | Description |
|---|---|
InitError
|
If rendering fails |
ValidationError
|
If validation fails |
Source code in src/holodeck/lib/template_engine.py
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 | |
render_template(template_path, variables)
¶
Render a Jinja2 template with provided variables.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
template_path
|
str
|
Path to the Jinja2 template file |
required |
variables
|
dict[str, Any]
|
Dictionary of variables to pass to the template |
required |
Returns:
| Type | Description |
|---|---|
str
|
Rendered template content as a string |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If template file doesn't exist |
InitError
|
If rendering fails (syntax errors, undefined variables, etc.) |
Source code in src/holodeck/lib/template_engine.py
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 | |
validate_agent_config(yaml_content)
¶
Validate YAML content against Agent schema.
Parses YAML and validates it against the Agent Pydantic model. This is the critical validation gate for agent.yaml files.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
yaml_content
|
str
|
YAML content as a string |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Agent |
Agent
|
Validated Agent configuration object |
Raises:
| Type | Description |
|---|---|
ValidationError
|
If YAML is invalid or doesn't match schema |
InitError
|
If parsing fails |
Source code in src/holodeck/lib/template_engine.py
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 | |
Usage Examples¶
Template Rendering¶
from holodeck.lib.template_engine import TemplateRenderer
renderer = TemplateRenderer()
# Render inline template
result = renderer.render_template(
"template_string",
{"name": "Alice"}
)
Related Documentation¶
- Configuration Loading: Using template engine with configs
- CLI Commands: Project initialization and CLI API