Skip to content

Sleep Time Calculators

Sleep time calculators determine how long the agent should wait before the next decision cycle.

SleepTimeCalculator (Base Class)

proactiveagent.sleep_time_calculators.base.SleepTimeCalculator

Bases: ABC

Abstract base class for sleep time calculation strategies

calculate_sleep_time abstractmethod async

Python
calculate_sleep_time(config: Dict[str, Any], context: Dict[str, Any]) -> tuple[int, str]

Calculate how long to sleep before next wake-up

Parameters:

Name Type Description Default
config Dict[str, Any]

Full configuration dictionary containing wake_up_pattern, max_sleep_time (int), etc.

required
context Dict[str, Any]

Current conversation context

required

Returns:

Type Description
tuple[int, str]

Tuple of (sleep_time_seconds: int, reasoning: str)

AIBasedSleepCalculator

Uses AI to interpret natural language patterns and determine optimal sleep time.

proactiveagent.sleep_time_calculators.ai_based.AIBasedSleepCalculator

Python
AIBasedSleepCalculator(provider: BaseProvider)

Bases: SleepTimeCalculator

AI provider-based sleep time calculation (default behavior)

Initialize with an AI provider

Parameters:

Name Type Description Default
provider BaseProvider

AI provider instance that implements calculate_sleep_time

required

calculate_sleep_time async

Python
calculate_sleep_time(config: Dict[str, Any], context: Dict[str, Any]) -> tuple[int, str]

Calculate sleep time using AI provider

StaticSleepCalculator

Fixed sleep intervals regardless of context.

proactiveagent.sleep_time_calculators.static.StaticSleepCalculator

Python
StaticSleepCalculator(sleep_seconds: int, reasoning: str = 'Static sleep time')

Bases: SleepTimeCalculator

Simple static sleep time calculator

Initialize with fixed sleep time

Parameters:

Name Type Description Default
sleep_seconds int

Fixed sleep time in seconds

required
reasoning str

Explanation for the sleep time

'Static sleep time'

calculate_sleep_time async

Python
calculate_sleep_time(config: Dict[str, Any], context: Dict[str, Any]) -> tuple[int, str]

Return the static sleep time

PatternBasedSleepCalculator

Adjusts timing based on conversation keywords and patterns.

proactiveagent.sleep_time_calculators.pattern_based.PatternBasedSleepCalculator

Python
PatternBasedSleepCalculator(pattern_mappings: Dict[str, int] = None)

Bases: SleepTimeCalculator

Pattern-based sleep time calculator without AI

Initialize with pattern mappings

Parameters:

Name Type Description Default
pattern_mappings Dict[str, int]

Dictionary mapping pattern keywords to sleep times in seconds

None

calculate_sleep_time async

Python
calculate_sleep_time(config: Dict[str, Any], context: Dict[str, Any]) -> tuple[int, str]

Calculate sleep time based on pattern keywords

FunctionBasedSleepCalculator

Custom timing logic using Python functions.

proactiveagent.sleep_time_calculators.function_based.FunctionBasedSleepCalculator

Python
FunctionBasedSleepCalculator(calc_function: Callable[[Dict[str, Any], Dict[str, Any]], tuple[int, str]])

Bases: SleepTimeCalculator

Adapter for function-based sleep time calculations

Initialize with a calculation function

Parameters:

Name Type Description Default
calc_function Callable[[Dict[str, Any], Dict[str, Any]], tuple[int, str]]

Function that takes (config, context) and returns (sleep_seconds, reasoning)

required

calculate_sleep_time async

Python
calculate_sleep_time(config: Dict[str, Any], context: Dict[str, Any]) -> tuple[int, str]

Calculate sleep time using the provided function