thunc()
think + function

Call an LLM like a typed Python function.

pip install thunc
@thunc.function
def urgency(ticket: str) -> int:
    """Rate how urgent this ticket is,
    from 1 (can wait) to 5 (blocked)."""
    ...

urgency("I was charged twice!")
# -> 4  # a checked int

Your function is the prompt.

docstring

The instructions the model follows.

parameters

The inputs, sent separately from the instructions as data.

return type

What you get back, parsed and checked.

Supported return types

strboolintfloatLiteral[...] list[T]dict[str, T]T | Nonedataclasses

Robust by default

Or just pass a string.

When the prompt comes from a variable, a config file or a loop, call thunc.call with it. You still get typed, checked results.

prompt = f"Translate into {lang}."
text = thunc.call(prompt, {"note": note})

score = thunc.call(
    rubric,
    {"answer": answer},
    returns=int,
)

Durable agents with Temporal.

New in 0.2.1: optional durable execution, with recorded model turns, recoverable tool effects, reconnectable runs and explicit resolution of uncertain commands. Local calls keep their dependency-free runtime.

Durable mode requires a Temporal service, a worker and persistent workspace storage. Install it with pip install "thunc[temporal]".

Temporal setup and recovery guide