Skip to content

result_types

Class info

Classes

Name Children Inherits
BaseResponseDefinition
llmling_agent.models.result_types
Base class for response definitions.
ImportedResponseDefinition
llmling_agent.models.result_types
Response definition that imports an existing Pydantic model.
    InlineResponseDefinition
    llmling_agent.models.result_types
    Inline definition of an agent's response structure.
      ResponseField
      llmling_agent.models.result_types
      Field definition for inline response types.

        🛈 DocStrings

        Models for response fields and definitions.

        BaseResponseDefinition

        Bases: BaseModel

        Base class for response definitions.

        Source code in src/llmling_agent/models/result_types.py
        43
        44
        45
        46
        47
        48
        49
        50
        51
        52
        53
        54
        55
        56
        57
        58
        59
        60
        class BaseResponseDefinition(BaseModel):
            """Base class for response definitions."""
        
            type: str = Field(init=False)
        
            description: str | None = None
            """A description for this response definition."""
        
            result_tool_name: str = "final_result"
            """The tool name for the Agent tool to create the structured response."""
        
            result_tool_description: str | None = None
            """The tool description for the Agent tool to create the structured response."""
        
            result_retries: int | None = None
            """Retry override. How often the Agent should try to validate the response."""
        
            model_config = ConfigDict(use_attribute_docstrings=True, extra="forbid")
        

        description class-attribute instance-attribute

        description: str | None = None
        

        A description for this response definition.

        result_retries class-attribute instance-attribute

        result_retries: int | None = None
        

        Retry override. How often the Agent should try to validate the response.

        result_tool_description class-attribute instance-attribute

        result_tool_description: str | None = None
        

        The tool description for the Agent tool to create the structured response.

        result_tool_name class-attribute instance-attribute

        result_tool_name: str = 'final_result'
        

        The tool name for the Agent tool to create the structured response.

        ImportedResponseDefinition

        Bases: BaseResponseDefinition

        Response definition that imports an existing Pydantic model.

        Allows using externally defined Pydantic models as response types. Benefits: - Reuse existing model definitions - Full Python type support - Complex validation logic - IDE support for imported types

        Example

        responses: AnalysisResult: type: import import_path: myapp.models.AnalysisResult

        Source code in src/llmling_agent/models/result_types.py
        102
        103
        104
        105
        106
        107
        108
        109
        110
        111
        112
        113
        114
        115
        116
        117
        118
        119
        120
        121
        122
        123
        124
        125
        126
        127
        128
        129
        130
        131
        132
        133
        134
        135
        136
        137
        class ImportedResponseDefinition(BaseResponseDefinition):
            """Response definition that imports an existing Pydantic model.
        
            Allows using externally defined Pydantic models as response types.
            Benefits:
            - Reuse existing model definitions
            - Full Python type support
            - Complex validation logic
            - IDE support for imported types
        
            Example:
                responses:
                  AnalysisResult:
                    type: import
                    import_path: myapp.models.AnalysisResult
            """
        
            type: Literal["import"] = Field("import", init=False)
            """Import-path based response definition."""
        
            import_path: str
            """The path to the pydantic model to use as the response type."""
        
            # mypy is confused about
            def resolve_model(self) -> type[BaseModel]:  # type: ignore
                """Import and return the model class."""
                try:
                    model_class = importing.import_class(self.import_path)
                    if not issubclass(model_class, BaseModel):
                        msg = f"{self.import_path} must be a Pydantic model"
                        raise TypeError(msg)  # noqa: TRY301
                except Exception as e:
                    msg = f"Failed to import response type {self.import_path}"
                    raise ValueError(msg) from e
                else:
                    return model_class
        

        import_path instance-attribute

        import_path: str
        

        The path to the pydantic model to use as the response type.

        type class-attribute instance-attribute

        type: Literal['import'] = Field('import', init=False)
        

        Import-path based response definition.

        resolve_model

        resolve_model() -> type[BaseModel]
        

        Import and return the model class.

        Source code in src/llmling_agent/models/result_types.py
        126
        127
        128
        129
        130
        131
        132
        133
        134
        135
        136
        137
        def resolve_model(self) -> type[BaseModel]:  # type: ignore
            """Import and return the model class."""
            try:
                model_class = importing.import_class(self.import_path)
                if not issubclass(model_class, BaseModel):
                    msg = f"{self.import_path} must be a Pydantic model"
                    raise TypeError(msg)  # noqa: TRY301
            except Exception as e:
                msg = f"Failed to import response type {self.import_path}"
                raise ValueError(msg) from e
            else:
                return model_class
        

        InlineResponseDefinition

        Bases: BaseResponseDefinition

        Inline definition of an agent's response structure.

        Allows defining response types directly in the configuration using: - Field definitions with types and descriptions - Optional validation constraints - Custom field descriptions

        Example

        responses: BasicResult: type: inline fields: success: {type: bool, description: "Operation success"} message: {type: str, description: "Result details"}

        Source code in src/llmling_agent/models/result_types.py
        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
        class InlineResponseDefinition(BaseResponseDefinition):
            """Inline definition of an agent's response structure.
        
            Allows defining response types directly in the configuration using:
            - Field definitions with types and descriptions
            - Optional validation constraints
            - Custom field descriptions
        
            Example:
                responses:
                  BasicResult:
                    type: inline
                    fields:
                      success: {type: bool, description: "Operation success"}
                      message: {type: str, description: "Result details"}
            """
        
            type: Literal["inline"] = Field("inline", init=False)
            """Inline response definition."""
        
            fields: dict[str, ResponseField]
            """A dictionary containing all fields."""
        
            def create_model(self) -> type[BaseModel]:  # type: ignore
                """Create Pydantic model from inline definition."""
                fields = {}
                for name, field in self.fields.items():
                    python_type = TYPE_MAP.get(field.type)
                    if not python_type:
                        msg = f"Unsupported field type: {field.type}"
                        raise ValueError(msg)
        
                    field_info = Field(description=field.description, **(field.constraints))
                    fields[name] = (python_type, field_info)
        
                cls_name = self.description or "ResponseType"
                return create_model(cls_name, **fields, __base__=BaseModel)  # type: ignore[call-overload]
        

        fields instance-attribute

        A dictionary containing all fields.

        type class-attribute instance-attribute

        type: Literal['inline'] = Field('inline', init=False)
        

        Inline response definition.

        create_model

        create_model() -> type[BaseModel]
        

        Create Pydantic model from inline definition.

        Source code in src/llmling_agent/models/result_types.py
        86
        87
        88
        89
        90
        91
        92
        93
        94
        95
        96
        97
        98
        99
        def create_model(self) -> type[BaseModel]:  # type: ignore
            """Create Pydantic model from inline definition."""
            fields = {}
            for name, field in self.fields.items():
                python_type = TYPE_MAP.get(field.type)
                if not python_type:
                    msg = f"Unsupported field type: {field.type}"
                    raise ValueError(msg)
        
                field_info = Field(description=field.description, **(field.constraints))
                fields[name] = (python_type, field_info)
        
            cls_name = self.description or "ResponseType"
            return create_model(cls_name, **fields, __base__=BaseModel)  # type: ignore[call-overload]
        

        ResponseField

        Bases: BaseModel

        Field definition for inline response types.

        Defines a single field in an inline response definition, including: - Data type specification - Optional description - Validation constraints

        Used by InlineResponseDefinition to structure response fields.

        Source code in src/llmling_agent/models/result_types.py
        20
        21
        22
        23
        24
        25
        26
        27
        28
        29
        30
        31
        32
        33
        34
        35
        36
        37
        38
        39
        40
        class ResponseField(BaseModel):
            """Field definition for inline response types.
        
            Defines a single field in an inline response definition, including:
            - Data type specification
            - Optional description
            - Validation constraints
        
            Used by InlineResponseDefinition to structure response fields.
            """
        
            type: str
            """Data type of the response field"""
        
            description: str | None = None
            """Optional description of what this field represents"""
        
            constraints: dict[str, Any] = Field(default_factory=dict)
            """Optional validation constraints for the field"""
        
            model_config = ConfigDict(use_attribute_docstrings=True, extra="forbid")
        

        constraints class-attribute instance-attribute

        constraints: dict[str, Any] = Field(default_factory=dict)
        

        Optional validation constraints for the field

        description class-attribute instance-attribute

        description: str | None = None
        

        Optional description of what this field represents

        type instance-attribute

        type: str
        

        Data type of the response field