-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathfunction_based_sleep_calculator.py
More file actions
67 lines (49 loc) · 1.79 KB
/
function_based_sleep_calculator.py
File metadata and controls
67 lines (49 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
"""
Minimal example using FunctionBasedSleepCalculator
"""
import time
from proactiveagent import ProactiveAgent, OpenAIProvider
from proactiveagent.sleep_time_calculators import FunctionBasedSleepCalculator
def on_ai_response(response: str):
print(f"🤖 AI: {response}")
def on_sleep_time_calculated(sleep_time: int, reasoning: str):
print(f"⏰ Sleep: {sleep_time}s - {reasoning}")
def custom_sleep_function(config, context):
"""Simple custom sleep calculation"""
user_engagement = context.get('user_engagement', 'low')
if user_engagement == 'high':
return 60, "High engagement - check every minute"
elif user_engagement == 'medium':
return 120, "Medium engagement - check every 2 minutes"
else:
return 180, "Low engagement - check every 3 minutes"
def main():
provider = OpenAIProvider(
model="gpt-5-nano",
)
# Use custom sleep function
sleep_calculator = FunctionBasedSleepCalculator(custom_sleep_function)
agent = ProactiveAgent(
provider=provider,
system_prompt="You are a helpful AI assistant.",
decision_config={
'min_sleep_time': 30,
'max_sleep_time': 300,
}
)
# Override the default sleep calculator
agent.scheduler.sleep_calculator = sleep_calculator
agent.add_callback(on_ai_response)
agent.add_sleep_time_callback(on_sleep_time_calculated)
agent.start()
print("=== Function-Based Sleep Calculator ===")
print("Uses custom logic based on engagement level.")
print("Type 'quit' to exit.\n")
while True:
message = input("You: ").strip()
if message.lower() == 'quit': break
agent.send_message(message)
time.sleep(1)
agent.stop()
if __name__ == "__main__":
main()