Skip to main content
SimpleComponent: a lightweight named-span component. SimpleComponent accepts arbitrary keyword arguments (strings, [CBlock](../../core/base#class-cblock)s, or [Component](../../core/base#class-component)s) 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](../../core/base#class-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.

FUNC make_simple_string

make_simple_string(kwargs: dict[str, Any]) -> str
Render keyword arguments as <|key|>value</|key|> tagged strings. Args:
  • kwargs: Mapping of span names to their [CBlock](../../core/base#class-cblock) or [Component](../../core/base#class-component) values.
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](../../core/base#class-cblock) and [ModelOutputThunk](../../core/base#class-modeloutputthunk) values use their .value attribute, while [Component](../../core/base#class-component) values use format_for_llm(). Args:
  • kwargs: Mapping of span names to [CBlock](../../core/base#class-cblock), [Component](../../core/base#class-component), or [ModelOutputThunk](../../core/base#class-modeloutputthunk) values.
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.