-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
67 lines (52 loc) · 2.21 KB
/
app.py
File metadata and controls
67 lines (52 loc) · 2.21 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
"""
Aplicação principal - Coordena o agente e o monitoramento
"""
import sys
import os
from dotenv import load_dotenv
# Carrega variáveis de ambiente PRIMEIRO
load_dotenv()
# Importações após load_dotenv
from agent import create_agent
from monitoring.notifications import NotificationSender
from monitoring.monitor import MonitorManager
from agno.tools.telegram import TelegramTools
def main():
"""Função principal - ponto de entrada da aplicação"""
# Cria o agente
agent = create_agent()
# Verifica se deve iniciar o monitoramento
if "--monitor" in sys.argv or "-m" in sys.argv:
print("🤖 Iniciando agente em modo autônomo com monitoramento...")
# Configura as notificações
telegram_token = os.getenv("TELEGRAM_BOT_TOKEN")
telegram_chat_id = os.getenv("TELEGRAM_CHAT_ID")
telegram_tool = TelegramTools(token=telegram_token, chat_id=telegram_chat_id)
notification_sender = NotificationSender(telegram_tool)
# Inicia o monitoramento
monitor = MonitorManager(notification_sender)
monitor.start_monitoring()
print("💬 Agente pronto para receber perguntas. Pressione Ctrl+C para sair.")
# Modo autônomo: monitora em background e aceita perguntas
try:
while True:
user_input = input("\nYou: ")
if user_input.strip().lower() in ("/quit", "/q"):
print("Encerrando o monitoramento...")
monitor.stop_monitoring()
break
agent.print_response(user_input, stream=True)
except KeyboardInterrupt:
print("\n\nEncerrando...")
monitor.stop_monitoring()
else:
# Modo interativo normal (sem monitoramento)
print("💬 Agente em modo interativo. Use '--monitor' para habilitar monitoramento automático.")
while True:
user_input = input("You: ")
if user_input.strip().lower() in ("/quit", "/q"):
print("Exiting the conversation. Goodbye!")
break
agent.print_response(user_input, stream=True)
if __name__ == "__main__":
main()