"""
Exemplo de uso do Policy Engine
"""
from atomic_agents.core import PolicyEngine

def main():
    # Configurar políticas
    policies = {
        "maxCost": 50.0,
        "maxTokens": 5000,
        "blockedTools": ["delete_file", "rm", "format_disk"]
    }
    
    engine = PolicyEngine(policies, mode="enforce")
    
    print("=== Testes de Políticas ===\n")
    
    # Teste 1: Verificar custo
    print("1. Verificação de Custo:")
    result = engine.pre_check("llm_call", {"current_cost": 30.0})
    print(f"   Custo: $30.00 | Permitido: {result.allowed}")
    
    result = engine.pre_check("llm_call", {"current_cost": 60.0})
    print(f"   Custo: $60.00 | Permitido: {result.allowed}")
    if not result.allowed:
        print(f"   Razão: {result.reason}\n")
    
    # Teste 2: Verificar tokens
    print("2. Verificação de Tokens:")
    result = engine.pre_check("llm_call", {"current_tokens": 3000})
    print(f"   Tokens: 3000 | Permitido: {result.allowed}")
    
    result = engine.pre_check("llm_call", {"current_tokens": 6000})
    print(f"   Tokens: 6000 | Permitido: {result.allowed}")
    if not result.allowed:
        print(f"   Razão: {result.reason}\n")
    
    # Teste 3: Verificar ferramentas bloqueadas
    print("3. Verificação de Ferramentas:")
    tools = ["read_file", "delete_file", "write_file", "rm"]
    for tool in tools:
        result = engine.check_tool(tool)
        status = "✅ Permitido" if result.allowed else "❌ Bloqueado"
        print(f"   {tool}: {status}")
        if not result.allowed:
            print(f"      Razão: {result.reason}")

if __name__ == "__main__":
    main()


