Repository navigation
Expand file tree
/
Copy pathagent_brain.py
More file actions
72 lines (58 loc) · 2.61 KB
/
Copy pathagent_brain.py
File metadata and controls
72 lines (58 loc) · 2.61 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
68
69
70
71
72
from langchain_google_genai import ChatGoogleGenerativeAI
from langchain.agents import create_tool_calling_agent, AgentExecutor
from langchain.tools import Tool
from langchain_core.prompts import ChatPromptTemplate, MessagesPlaceholder
# Ferramentas do Navegador
from langchain_community.tools.playwright.utils import create_async_playwright_browser
from langchain_community.tools.playwright.navigate import NavigateTool
from langchain_community.tools.playwright.click import ClickTool
from langchain_community.tools.playwright.extract_text import ExtractTextTool
from langchain_community.tools.playwright.get_elements import GetElementsTool
from langchain_community.tools.playwright.current_page import CurrentWebPageTool
from email_manager import EmailService
# --- SUA CHAVE DO ROBONOVO (Ela funciona!) ---
CHAVE_GOOGLE = "AIzaSyD6eJSQHapsT4_IxxMV3krB7ZWAJazXrWo"
email_service = EmailService()
async def criar_agente_inteligente():
# 1. Configura o Browser
async_browser = create_async_playwright_browser(headless=False)
browser_tools = [
NavigateTool.from_browser(async_browser=async_browser),
ClickTool.from_browser(async_browser=async_browser),
ExtractTextTool.from_browser(async_browser=async_browser),
GetElementsTool.from_browser(async_browser=async_browser),
CurrentWebPageTool.from_browser(async_browser=async_browser)
]
# 2. Ferramentas de Email
tool_gerar_email = Tool(
name="GerarEmailTemporario",
func=lambda x: email_service.gerar_email(),
description="Gera um email novo e retorna o endereço."
)
tool_ler_codigo = Tool(
name="LerCodigoEmail",
func=lambda x: email_service.esperar_codigo(),
description="Lê a caixa de entrada e retorna o código de verificação encontrado."
)
all_tools = browser_tools + [tool_gerar_email, tool_ler_codigo]
# 3. LLM - VOLTAMOS PARA A REALIDADE (Gemini 1.5 Flash)
# Com a data do PC certa, esse modelo vai conectar instantaneamente.
llm = ChatGoogleGenerativeAI(
model="gemini-2.0-flash-exp",
google_api_key=CHAVE_GOOGLE,
temperature=0
)
# 4. Prompt
prompt = ChatPromptTemplate.from_messages([
("system", "Você é um especialista em automação web. Use as ferramentas para navegar e preencher formulários."),
("human", "{input}"),
MessagesPlaceholder("agent_scratchpad"),
])
# 5. Agente
agent = create_tool_calling_agent(llm, all_tools, prompt)
agent_executor = AgentExecutor(
agent=agent,
tools=all_tools,
verbose=True
)
return agent_executor