- Updated README.md to include new setup instructions for RAG and observability. - Added internal knowledge base (KB) setup for SQL optimization team, supporting various document types. - Implemented token usage logging in LLM tools to track costs and usage. - Refactored SQL analysis and optimization prompts for clarity and consistency. - Introduced filtering of external tools based on environment configuration. - Enhanced conservative analysis agent with structured prompt for performance suggestions. - Updated requirements.txt to include new dependencies for RAG functionality. - Added internal KB helpers for building and attaching knowledge to agents.
81 lines
2.4 KiB
Markdown
81 lines
2.4 KiB
Markdown
# 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
|
|
|
|
```text
|
|
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).
|