Skip to main content
Prerequisites: Instruct, Validate, Repair complete, 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 an Instruction component and passes it to act()
  • chat() creates a Message component and passes it to act() with strategy=None
  • query() and transform() wrap mified objects into components and pass them to act()
Use 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 any Component 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 a Message:
Note: The base Document class does not yet support being embedded inside a Message (#636). For rich document processing (PDFs, tables), use RichDocument from mellea.stdlib.components.docs — see Working with Data.
For rich document processing (PDFs, tables), 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):
See Instruct, Validate, Repair and Inference-Time Scaling for full details on requirements and validation.

Structured output

Pass a Pydantic BaseModel as the format parameter for constrained decoding:

The functional API

Advanced: mellea.stdlib.functional exposes act() and aact() as standalone functions. You pass context and backend explicitly instead of relying on a session to thread them.
The functional 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:
The functional async version is mfuncs.aact():
For parallel generation and streaming patterns, see Async and Streaming.
See also: Async and Streaming | Inference-Time Scaling | Instruct, Validate, Repair