@mify decorator for turning Python objects into [Component](../../core/base#class-component)s.
mify wraps an existing Python class or instance with the MifiedProtocol
interface, exposing its fields as named spans and its documented methods as
[MelleaTool](../../backends/tools#class-melleatool) instances callable by the LLM. The resulting MifiedProtocol object
can be queried, transformed, and formatted for a language model without any manual
[Component](../../core/base#class-component) subclassing. Use mify when you have an existing domain object
(dataclass, Pydantic model, or plain class) that you want to expose directly to an
LLM-driven pipeline.
Functions
FUNC mify
- the stringify_func will not be used to represent this object to the model
- you must specify a template field or a template in the template_order field that handles a dict with those fields as keys
- it’s advised to use fields_include due to the many dunder fields and inherited fields an object/class might have
obj: A class or an instance of a class to mify. Omit when using as a decorator with arguments (e.g.@mify(fields_include=\{...\})).query_type: A specific query component type to use when querying a model. Defaults toQuery.transform_type: A specific transform component type to use when transforming with a model. Defaults toTransform.fields_include: Fields of the object to include in its representation to models. When set,stringify_funcis not used.fields_exclude: Fields of the object to exclude from its representation to models.funcs_include: Functions of the object to expose as tools to models.funcs_exclude: Functions of the object to hide from models.template: A Jinja2 template string. Takes precedence overtemplate_orderwhen provided.template_order: A template name or list of names used when searching for applicable templates.parsing_func: Not yet implemented.stringify_func: A callable used to create a string representation of the object forcontent_as_string.
- An object if an object was passed in or a decorator (callable) to mify classes.
- If an object is returned, that object will be the same object that was passed in.
- For example,
-
- obj = mify(obj)
- obj.format_for_llm()
-
- and
-
- mify(obj)
- obj.format_for_llm()
-
- are equivalent.
- Most IDEs will not correctly show the type hints for the newly added functions
- for either an mify object or instances of an mified class. For IDE support, write
-
- assert isinstance(obj, MifiedProtocol)
-
Classes
CLASS MifiedProtocol
Adds additional functionality to the MObjectProtocol and modifies MObject functions so that mified objects can be more easily interacted with and modified.
See the mify decorator for more information.
Methods:
FUNC parts
- list[Component | CBlock]: Always an empty list for mified objects.
FUNC get_query_object
query: The natural-language query string.
- A
Querycomponent wrapping this object and the given query.
FUNC get_transform_object
transformation: The natural-language transformation description.
- A
Transformcomponent wrapping this object and the - given transformation description.
FUNC content_as_string
stringify_func passed to mify when one was
provided; otherwise falls back to str(self).
Returns:
- String representation of the mified object’s content.
FUNC format_for_llm
[TemplateRepresentation](../../core/base#class-templaterepresentation) for this mified object.
[no-index]
Sets the [TemplateRepresentation](../../core/base#class-templaterepresentation) fields based on the object and the
configuration values supplied to mify (fields, templates, tools, etc.).
See the mify decorator for more details.
Returns:
- The formatted representation including args,
- tools, and template ordering.
FUNC parse
_parse and wraps any exception in a
[ComponentParseError](../../core/base#class-componentparseerror) to give callers a consistent error type.
Args:
computed: The raw model output to parse.
- The string value extracted from
computed.
ComponentParseError: If_parseraises any exception during parsing.