🚀 Auto-deploy: BotVPS atualizado em 21/04/2026 21:16:18
This commit is contained in:
27
ai_agent.py
27
ai_agent.py
@@ -3,7 +3,8 @@ import re
|
|||||||
import httpx
|
import httpx
|
||||||
import asyncio
|
import asyncio
|
||||||
import json
|
import json
|
||||||
from tools import AVAILABLE_TOOLS
|
from tools import AVAILABLE_TOOLS as TOOLS_LEGACY
|
||||||
|
from tools_v2 import TOOLS_V2 as TOOLS_NEW
|
||||||
from llm_providers import call_llm, get_available_models, get_planner_llm
|
from llm_providers import call_llm, get_available_models, get_planner_llm
|
||||||
from config import get_config
|
from config import get_config
|
||||||
|
|
||||||
@@ -26,7 +27,9 @@ def query_agent(prompt: str, override_provider=None, chat_history=None) -> str:
|
|||||||
async def query_agent_async(prompt: str, override_provider=None, chat_history=None) -> str:
|
async def query_agent_async(prompt: str, override_provider=None, chat_history=None) -> str:
|
||||||
cfg = get_config()
|
cfg = get_config()
|
||||||
provider = override_provider or cfg.get("active_provider", "openrouter")
|
provider = override_provider or cfg.get("active_provider", "openrouter")
|
||||||
tools_desc = "\n".join([f"- {k}: {v['description']}" for k, v in AVAILABLE_TOOLS.items()])
|
# Unifica ferramentas legadas e novas
|
||||||
|
ALL_TOOLS = {**TOOLS_LEGACY, **TOOLS_NEW}
|
||||||
|
tools_desc = "\n".join([f"- {k}: {v.get('description') or v.get('desc')}" for k, v in ALL_TOOLS.items()])
|
||||||
|
|
||||||
system_prompt = f"""Você é o Antigravity, um assistente de IA de alto desempenho operando na VPS do Marcos. Sua natureza é dual:
|
system_prompt = f"""Você é o Antigravity, um assistente de IA de alto desempenho operando na VPS do Marcos. Sua natureza é dual:
|
||||||
|
|
||||||
@@ -85,11 +88,23 @@ DIRETRIZES:
|
|||||||
|
|
||||||
arg = content_after[:end_tag.start()].strip() if end_tag else content_after.strip()
|
arg = content_after[:end_tag.start()].strip() if end_tag else content_after.strip()
|
||||||
|
|
||||||
if t_name in AVAILABLE_TOOLS:
|
all_tools = {**TOOLS_LEGACY, **TOOLS_NEW}
|
||||||
func = AVAILABLE_TOOLS[t_name]["func"]
|
if t_name in all_tools:
|
||||||
|
tool_info = all_tools[t_name]
|
||||||
|
func = tool_info["func"]
|
||||||
print(f"[AGENT] Executando {t_name} com argumento: {arg[:50]}...")
|
print(f"[AGENT] Executando {t_name} com argumento: {arg[:50]}...")
|
||||||
obs = func(arg) if arg else func()
|
|
||||||
print(f"[TOOL:{t_name}] Observation: {obs[:100]}...")
|
# Execução (suporta async se necessário, embora tools.py seja sync)
|
||||||
|
if asyncio.iscoroutinefunction(func):
|
||||||
|
obs = await func(arg) if arg else await func()
|
||||||
|
else:
|
||||||
|
obs = func(arg) if arg else func()
|
||||||
|
|
||||||
|
# Se o resultado for um dicionário (comum em tools_v2), extrai o output ou converte para string
|
||||||
|
if isinstance(obs, dict):
|
||||||
|
obs = obs.get("output") or obs.get("message") or str(obs)
|
||||||
|
|
||||||
|
print(f"[TOOL:{t_name}] Observation: {str(obs)[:100]}...")
|
||||||
|
|
||||||
if len(str(obs)) > 3000:
|
if len(str(obs)) > 3000:
|
||||||
obs = str(obs)[:3000] + "... [TRUNCATED]"
|
obs = str(obs)[:3000] + "... [TRUNCATED]"
|
||||||
|
|||||||
@@ -168,7 +168,7 @@ class WorkspaceTools:
|
|||||||
@staticmethod
|
@staticmethod
|
||||||
def coolify_deploy_status() -> str:
|
def coolify_deploy_status() -> str:
|
||||||
"""Consulta os últimos 5 deploies registrados no Coolify via banco de dados."""
|
"""Consulta os últimos 5 deploies registrados no Coolify via banco de dados."""
|
||||||
cmd = 'docker exec coolify psql -U coolify -d coolify -c "SELECT p.name as project, a.name as application, d.status, d.updated_at FROM deployments d JOIN applications a ON d.application_id = a.id JOIN projects p ON a.project_id = p.id ORDER BY d.updated_at DESC LIMIT 5;"'
|
cmd = 'docker exec coolify-db psql -U coolify -d coolify -c "SELECT application_name as application, status, created_at FROM application_deployment_queues ORDER BY created_at DESC LIMIT 5;"'
|
||||||
return run_bash(cmd)["output"]
|
return run_bash(cmd)["output"]
|
||||||
|
|
||||||
# ============================================================
|
# ============================================================
|
||||||
|
|||||||
Reference in New Issue
Block a user