Skip to content

builtin_provider

Class info

Classes

Name Children Inherits
BasePromptProvider
llmling_agent.prompts.base
Base class for external prompt providers.
BuiltinPromptProvider
llmling_agent.prompts.builtin_provider
Default provider using system prompts.
    RuntimePromptProvider
    llmling_agent.prompts.builtin_provider
    Provider for prompts from RuntimeConfig.
      StaticPromptConfig
      llmling_agent_config.system_prompts
      Configuration for a static text prompt.
        • BaseSystemPrompt

        🛈 DocStrings

        Builtin prompt provider.

        BuiltinPromptProvider

        Bases: BasePromptProvider

        Default provider using system prompts.

        Source code in src/llmling_agent/prompts/builtin_provider.py
        17
        18
        19
        20
        21
        22
        23
        24
        25
        26
        27
        28
        29
        30
        31
        32
        33
        34
        35
        36
        37
        38
        39
        40
        41
        42
        43
        44
        45
        46
        47
        48
        49
        50
        51
        52
        53
        54
        55
        56
        57
        58
        59
        60
        61
        62
        63
        64
        65
        66
        67
        68
        69
        70
        71
        72
        73
        74
        75
        76
        77
        class BuiltinPromptProvider(BasePromptProvider):
            """Default provider using system prompts."""
        
            supports_variables = True
            name = "builtin"
        
            def __init__(self, manifest_prompts: dict[str, StaticPromptConfig]):
                from jinjarope import Environment
        
                self.prompts = manifest_prompts
                self.env = Environment(autoescape=False, enable_async=True)
        
            async def get_prompt(
                self,
                identifier: str,
                version: str | None = None,
                variables: dict[str, Any] | None = None,
            ) -> str:
                """Get prompt content as string."""
                from jinja2 import Template, meta
        
                if identifier not in self.prompts:
                    msg = f"Prompt not found: {identifier}"
                    raise KeyError(msg)
        
                prompt = self.prompts[identifier]
                content = prompt.content
        
                # Parse template to find required variables
                ast = self.env.parse(content)
                required_vars = meta.find_undeclared_variables(ast)
                if variables and (unknown_vars := (set(variables) - required_vars)):
                    vars_ = ", ".join(unknown_vars)
                    msg = f"Unknown variables for prompt {identifier}: {vars_}"
                    raise KeyError(msg)
        
                if required_vars:
                    if not variables:
                        req = ", ".join(required_vars)
                        msg = f"Prompt {identifier} requires variables: {req}"
                        raise KeyError(msg)
        
                    # Check for missing required variables
                    missing_vars = required_vars - set(variables or {})
                    if missing_vars:
                        vars_ = ", ".join(missing_vars)
                        msg = f"Missing required variables for prompt {identifier}: {vars_}"
                        raise KeyError(msg)
        
                    try:
                        template = Template(content, enable_async=True)
                        content = await template.render_async(**variables)
                    except Exception as e:
                        msg = f"Failed to render prompt {identifier}: {e}"
                        raise ValueError(msg) from e
        
                return content
        
            async def list_prompts(self) -> list[str]:
                """List available prompt identifiers."""
                return list(self.prompts.keys())
        

        get_prompt async

        get_prompt(
            identifier: str, version: str | None = None, variables: dict[str, Any] | None = None
        ) -> str
        

        Get prompt content as string.

        Source code in src/llmling_agent/prompts/builtin_provider.py
        29
        30
        31
        32
        33
        34
        35
        36
        37
        38
        39
        40
        41
        42
        43
        44
        45
        46
        47
        48
        49
        50
        51
        52
        53
        54
        55
        56
        57
        58
        59
        60
        61
        62
        63
        64
        65
        66
        67
        68
        69
        70
        71
        72
        73
        async def get_prompt(
            self,
            identifier: str,
            version: str | None = None,
            variables: dict[str, Any] | None = None,
        ) -> str:
            """Get prompt content as string."""
            from jinja2 import Template, meta
        
            if identifier not in self.prompts:
                msg = f"Prompt not found: {identifier}"
                raise KeyError(msg)
        
            prompt = self.prompts[identifier]
            content = prompt.content
        
            # Parse template to find required variables
            ast = self.env.parse(content)
            required_vars = meta.find_undeclared_variables(ast)
            if variables and (unknown_vars := (set(variables) - required_vars)):
                vars_ = ", ".join(unknown_vars)
                msg = f"Unknown variables for prompt {identifier}: {vars_}"
                raise KeyError(msg)
        
            if required_vars:
                if not variables:
                    req = ", ".join(required_vars)
                    msg = f"Prompt {identifier} requires variables: {req}"
                    raise KeyError(msg)
        
                # Check for missing required variables
                missing_vars = required_vars - set(variables or {})
                if missing_vars:
                    vars_ = ", ".join(missing_vars)
                    msg = f"Missing required variables for prompt {identifier}: {vars_}"
                    raise KeyError(msg)
        
                try:
                    template = Template(content, enable_async=True)
                    content = await template.render_async(**variables)
                except Exception as e:
                    msg = f"Failed to render prompt {identifier}: {e}"
                    raise ValueError(msg) from e
        
            return content
        

        list_prompts async

        list_prompts() -> list[str]
        

        List available prompt identifiers.

        Source code in src/llmling_agent/prompts/builtin_provider.py
        75
        76
        77
        async def list_prompts(self) -> list[str]:
            """List available prompt identifiers."""
            return list(self.prompts.keys())
        

        RuntimePromptProvider

        Bases: BasePromptProvider

        Provider for prompts from RuntimeConfig.

        Source code in src/llmling_agent/prompts/builtin_provider.py
         80
         81
         82
         83
         84
         85
         86
         87
         88
         89
         90
         91
         92
         93
         94
         95
         96
         97
         98
         99
        100
        101
        102
        class RuntimePromptProvider(BasePromptProvider):
            """Provider for prompts from RuntimeConfig."""
        
            name = "runtime"
            supports_variables = True
        
            def __init__(self, runtime_config: RuntimeConfig):
                self.runtime = runtime_config
        
            async def get_prompt(
                self,
                name: str,
                version: str | None = None,
                variables: dict[str, Any] | None = None,
            ) -> str:
                prompt = self.runtime.get_prompt(name)
                if variables:
                    messages = await prompt.format(variables)
                messages = await prompt.format()
                return "\n".join(m.get_text_content() for m in messages)
        
            async def list_prompts(self) -> list[str]:
                return [p.name for p in self.runtime.get_prompts() if p.name]