No description
Find a file
2026-01-23 13:05:28 -03:00
docs feat: Enhance SQL optimization tools with internal knowledge base and observability features 2026-01-23 13:02:17 -03:00
kb feat: Enhance SQL optimization tools with internal knowledge base and observability features 2026-01-23 13:02:17 -03:00
scripts refactor: Revamp start script to include Agent UI setup and dependency installation 2026-01-23 13:05:28 -03:00
src feat: Enhance SQL optimization tools with internal knowledge base and observability features 2026-01-23 13:02:17 -03:00
.gitignore feat: Implement SQL prompt generators for PostgreSQL, SQLite, and SQL Server 2026-01-21 13:51:03 -03:00
README.md feat: Enhance SQL optimization tools with internal knowledge base and observability features 2026-01-23 13:02:17 -03:00
requirements.txt feat: Enhance SQL optimization tools with internal knowledge base and observability features 2026-01-23 13:02:17 -03:00
sample.env feat: Enhance SQL optimization tools with internal knowledge base and observability features 2026-01-23 13:02:17 -03:00

SQL Optimizer Team (Agno)

POC de um time de agentes usando o framework Agno para reproduzir o fluxo do projeto oracle-sql-query-optimizer.

Objetivo

  • Receber uma SQL e o banco alvo (oracle/sqlserver/postgresql/mysql/sqlite).
  • Gerar explicação detalhada (SQL → linguagem natural).
  • Gerar SQL otimizada (linguagem natural → SQL), preservando 100% da lógica de negócio.
  • (Opcional) Gerar análise conservadora (sem reescrever a query).

As prompts são mantidas idênticas às do projeto oracle-sql-query-optimizer.

Estrutura

src/
  sql_optimizer_team/
    team_app.py
    agents/
    tools/

Configuração rápida

  1. Crie o ambiente e instale dependências:
    • pip install -r requirements.txt
  2. Configure variáveis de ambiente (exemplo em sample.env ou .env).
  3. Execute o servidor:
    • ./scripts/start.sh

Acesse:

  • http://localhost:8204/docs (Swagger UI)
  • http://localhost:8204 (informações básicas da API)

UI local (Agent UI)

Use o Agent UI (agno-agi/agent-ui) como front local:

  1. Instale com o script oficial:
  • npx create-agent-ui@latest
  1. Inicie a UI:
  • pnpm dev
  1. Abra http://localhost:3000 e ajuste o endpoint para http://localhost:8204.

Opcional: se o AgentOS usar autenticação, configure OS_SECURITY_KEY conforme o README do Agent UI.

Fluxo do time

  1. Gestor recebe a requisição e valida o contexto (banco + SQL).
  2. SQL Analyst gera a explicação detalhada usando a prompt original.
  3. SQL Optimizer gera a query otimizada preservando toda a lógica.
  4. SQL Quality Reviewer valida fidelidade e checklist.
  5. Conservative Analyst (se solicitado) gera análise sem reescrever a query.
  6. Gestor consolida e entrega.

RAG (KB interna)

  • Coloque documentos em kb/ (md/txt/sql/pdf).
  • O RAG local usa Chroma + SentenceTransformers.
  • Variáveis principais:
    • SQL_OPT_KB_PATH, SQL_OPT_KB_CHROMA_PATH, SQL_OPT_KB_DB_FILE
    • SQL_OPT_KB_EMBEDDER_ID
    • SQL_OPT_BLOCK_EXTERNAL_TOOLS=true bloqueia ferramentas externas.

Observabilidade de tokens/custos

  • Ative com LLM_LOG_USAGE=true.
  • Defina preços (USD por 1K tokens) com:
    • LLM_COST_INPUT_PER_1K
    • LLM_COST_OUTPUT_PER_1K

Observações

  • Use o provedor configurado em .env (ex.: Ollama local, OpenAI, Gemini, Groq, etc.).
  • O time é colaborativo e mantém histórico em SQLite (configurável via env).