File size: 2,370 Bytes
6086e71
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import sys
import os
import traceback
import json

sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))

from app.config import get_settings
from app.db.connection import DatabasePool
from app.llm.router import ModelRouter
from app.rag.retriever import HybridRetriever
from app.agents.orchestrator import AgentOrchestrator

try:
    settings = get_settings()
    
    db_pool = DatabasePool(
        settings.DB_URI,
        query_timeout=settings.DB_QUERY_TIMEOUT,
        pool_size=settings.DB_POOL_SIZE,
        max_overflow=settings.DB_MAX_OVERFLOW,
        pool_timeout=settings.DB_POOL_TIMEOUT,
    )
    
    llm_config = {
        "default_provider": settings.DEFAULT_LLM_PROVIDER,
        "groq_api_key": settings.GROQ_API_KEY,
        "groq_model_primary": settings.GROQ_MODEL_PRIMARY,
        "groq_model_fast": settings.GROQ_MODEL_FAST,
        "groq_base_url": settings.GROQ_BASE_URL,
        "huggingface_token": settings.HUGGINGFACEHUB_API_TOKEN,
        "huggingface_model": settings.DEFAULT_MODEL,
        "openai_api_key": settings.OPENAI_API_KEY,
        "anthropic_api_key": settings.ANTHROPIC_API_KEY,
        "ollama_base_url": settings.OLLAMA_BASE_URL,
    }
    llm_router = ModelRouter(llm_config)
    
    # Bypass loading models in semantic cache by patching it
    # to speed up execution
    AgentOrchestrator._init_semantic_cache = staticmethod(lambda: None)
    
    # Disable vector rag to speed up execution
    os.environ["DISABLE_VECTOR_RAG"] = "true"
    os.environ["DISABLE_ML_INTENT"] = "true"
    
    rag_retriever = HybridRetriever(db_pool, chroma_persist_dir=settings.CHROMA_PERSIST_DIR)
    orchestrator = AgentOrchestrator(llm_router, rag_retriever, db_pool)
    
    initial_state = {
        "user_query": "show me top 5 employees",
        "conversation_history": [],
        "tenant_id": "default",
        "user_role": "analyst",
        "trace_id": "debug",
    }
    
    res = orchestrator.graph.invoke(initial_state, config={"recursion_limit": 50})
    
    # Write output as JSON with UTF-8 encoding
    with open("debug_output.json", "w", encoding="utf-8") as f:
        json.dump(dict(res), f, ensure_ascii=False, indent=2, default=str)
    print("Execution completed successfully. Output written to debug_output.json")
    
except Exception:
    print("--- RAW TRACEBACK ---")
    traceback.print_exc()