Skip to content

templates

code_context_agent.templates

Jinja2 template loading and rendering for agent prompts.

This module provides a configured Jinja2 environment for rendering prompt templates. Templates are loaded from this directory using FileSystemLoader with StrictUndefined to catch missing variables.

render_prompt

render_prompt(template_name, **context)

Render a prompt template with the given context.

Parameters:

Name Type Description Default
template_name str

Template filename (e.g., "system.md.j2")

required
**context Any

Variables to pass to the template

{}

Returns:

Type Description
str

Rendered prompt string

Source code in packages/code-context-agent/src/code_context_agent/templates/__init__.py
def render_prompt(template_name: str, **context: Any) -> str:
    """Render a prompt template with the given context.

    Args:
        template_name: Template filename (e.g., "system.md.j2")
        **context: Variables to pass to the template

    Returns:
        Rendered prompt string
    """
    env = _get_environment()
    template = env.get_template(template_name)
    return template.render(**context)