Skip to content

templating

strands_teams.templating

Jinja2 environment factory for agent-prompt templates.

Adapted from the pre-split code_context_agent.templates package initializer. Generalized so the template directory is a parameter rather than the module's own directory: each use case supplies its own template dir.

make_environment

make_environment(template_dir)

Create a Jinja2 environment rooted at template_dir.

Parameters:

Name Type Description Default
template_dir str | Path

Directory containing .md.j2 prompt templates.

required

Returns:

Type Description
Environment

Configured Jinja2 Environment (cached per directory).

Source code in packages/strands-teams/src/strands_teams/templating.py
def make_environment(template_dir: str | Path) -> Environment:
    """Create a Jinja2 environment rooted at ``template_dir``.

    Args:
        template_dir: Directory containing ``.md.j2`` prompt templates.

    Returns:
        Configured Jinja2 ``Environment`` (cached per directory).
    """
    return _get_environment(str(Path(template_dir).resolve()))

render_prompt

render_prompt(template_dir, template_name, **context)

Render a prompt template from a use-case template directory.

Parameters:

Name Type Description Default
template_dir str | Path

Directory containing the template.

required
template_name str

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

required
**context object

Variables passed to the template.

{}

Returns:

Type Description
str

Rendered prompt string.

Source code in packages/strands-teams/src/strands_teams/templating.py
def render_prompt(template_dir: str | Path, template_name: str, **context: object) -> str:
    """Render a prompt template from a use-case template directory.

    Args:
        template_dir: Directory containing the template.
        template_name: Template filename (e.g., ``"coordinator.md.j2"``).
        **context: Variables passed to the template.

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