Skip to content

ContextStr

autogen.agentchat.contrib.swarm_agent.ContextStr dataclass #

ContextStr(template)

A string that requires context variable substitution.

Use the format method to substitute context variables into the string.

PARAMETER DESCRIPTION
template

The string to be substituted with context variables. It is expected that the string will contain {var} placeholders and that string format will be able to replace all values.

TYPE: str

Source code in autogen/agentchat/contrib/swarm_agent.py
def __init__(self, template: str):
    self.template = template

template instance-attribute #

template = template

format #

format(context_variables)

Substitute context variables into the string.

PARAMETER DESCRIPTION
context_variables

The context variables to substitute into the string.

TYPE: dict[str, Any]

RETURNS DESCRIPTION
Optional[str]

Optional[str]: The formatted string with context variables substituted.

Source code in autogen/agentchat/contrib/swarm_agent.py
def format(self, context_variables: dict[str, Any]) -> Optional[str]:
    """Substitute context variables into the string.

    Args:
        context_variables (dict[str, Any]): The context variables to substitute into the string.

    Returns:
        Optional[str]: The formatted string with context variables substituted.
    """
    return OpenAIWrapper.instantiate(
        template=self.template,
        context=context_variables,
        allow_format_str_template=True,
    )