mellea.stdlib.components.simple
SimpleComponent: a lightweight named-span component.
SimpleComponent accepts arbitrary keyword arguments (strings, CBlocks, or
Components) and renders them as a JSON object keyed by the argument names. It is
the go-to component type for ad-hoc prompts that do not require a dedicated
Component subclass or a Jinja2 template.
Classes
CLASS SimpleComponent
A Component that is make up of named spans.
Methods:
FUNC parts
parts(self) -> list[Component | CBlock]
Returns the values of the kwargs.
Returns:
- List of component values passed as keyword arguments.
FUNC make_simple_string
make_simple_string(kwargs: dict[str, Any]) -> str
Render keyword arguments as <|key|>value</|key|> tagged strings.
Args:
Returns:
- Newline-joined tagged representation of all keyword arguments.
FUNC make_json_string
make_json_string(kwargs: dict[str, Any]) -> str
Serialize keyword arguments to a JSON string.
Each value is converted to its string representation: CBlock and
ModelOutputThunk values use their .value attribute, while
Component values use format_for_llm().
Args:
kwargs: Mapping of span names toCBlock,Component, orModelOutputThunkvalues.
Returns:
- JSON-encoded representation of the keyword arguments.
FUNC format_for_llm
format_for_llm(self) -> str
Format this component as a JSON string representation for the language model.
Delegates to make_json_string using the stored keyword arguments.
Returns:
- JSON-encoded string of all named spans in this component.