Skip to content

latent.agents.conditions

Reusable predicates for agent lifecycle hooks.

Functions

all_of

all_of(predicates: MessagePredicate = ()) -> MessagePredicate

Return a predicate that passes only when all predicates pass.

any_of

any_of(predicates: MessagePredicate = ()) -> MessagePredicate

Return a predicate that passes when any predicate passes.

is_first_message

is_first_message(messages: list[Message]) -> bool

Return True when the history contains exactly one user message.

is_later_turn

is_later_turn(messages: list[Message]) -> bool

Return True when at least two user messages are present.

last_user_matches

last_user_matches(pattern: str | re.Pattern[str]) -> MessagePredicate

Build a predicate matching the latest user text with search.

min_user_turns

min_user_turns(n: int) -> MessagePredicate

Build a predicate requiring at least n user messages.

not_

not_(predicate: MessagePredicate) -> MessagePredicate

Return the logical negation of predicate.

Attributes

MessagePredicate