pip install mellea, Ollama running locally.
act() is the generic method on MelleaSession that runs any Component and
returns a result. Every other session method is built on it:
instruct()creates anInstructioncomponent and passes it toact()chat()creates aMessagecomponent and passes it toact()withstrategy=Nonequery()andtransform()wrap mified objects into components and pass them toact()
act() when you need to work directly with a component — for custom components,
fine-grained control, or building your own inference loops.
Three levels of abstraction
These three snippets all produce the same result:Basic usage
Pass anyComponent to act(). It returns a ModelOutputThunk:
Working with Messages
Message is a component with a role and content string. Pass strategy=None to
skip the IVR loop — this is what chat() does internally:
Working with Documents
Pass document content directly in aMessage:
Note: The baseFor rich document processing (PDFs, tables), see Working with Data.Documentclass does not yet support being embedded inside aMessage(#636). For rich document processing (PDFs, tables), useRichDocumentfrommellea.stdlib.components.docs— see Working with Data.
Validation and sampling strategies
act() accepts the same requirements and strategy parameters as instruct().
The default is RejectionSamplingStrategy(loop_budget=2):
Structured output
Pass a PydanticBaseModel as the format parameter for constrained decoding:
The functional API
Advanced:mellea.stdlib.functionalexposesact()andaact()as standalone functions. You passcontextandbackendexplicitly instead of relying on a session to thread them.
act() returns a (ModelOutputThunk, Context) tuple. With
return_sampling_results=True it returns (SamplingResult, Context).
Use the functional API when you need to branch context for parallel explorations or
build custom inference loops. For most use cases, the session API (m.act()) is
simpler.
Async with aact()
aact() is the async counterpart. Same signature, same return types:
mfuncs.aact():
See also: Async and Streaming | Inference-Time Scaling | Instruct, Validate, Repair