Get up and running with the LangChain-powered AI assistant in 5 minutes.
- Python 3.9+
- PostgreSQL database access (Supabase)
- OpenAI API key
# Navigate to the ai_assistant folder
cd ai_assistant
# Install dependencies
pip install -r requirements.txtCreate a .env file:
# Required
DATABASE_URL=postgresql://your-connection-string
OPENAI_API_KEY=sk-your-key-here
# Optional (defaults shown)
LLM_MODEL=gpt-4o-mini
LLM_TEMPERATURE_SQL=0.1
LLM_TEMPERATURE_RESPONSE=0.7
MEMORY_WINDOW_SIZE=3
MAX_RETRIES=3streamlit run ui/app.pyOpen http://localhost:8501 in your browser.
python -c "from config.database import test_connection; print('✅ Connected!' if test_connection() else '❌ Failed')"from agents.sql_agent import LangChainSQLAgent
agent = LangChainSQLAgent(company_id=29447)
result = agent.generate_sql("What are the contact details?")
print(f"SQL: {result['sql']}")from memory.conversation_memory import ConversationMemoryManager
memory = ConversationMemoryManager()
memory.add_exchange("test_session", "What's the email?", "contact@example.com")
memory.add_exchange("test_session", "What about phone?", "+1234567890")
history = memory.get_conversation_history("test_session")
print(f"History: {history}")from core.executor import execute_with_retry
result = execute_with_retry(
user_question="What are the contact details?",
company_id=29447
)
print(f"Success: {result['success']}")
print(f"SQL: {result['sql']}")
print(f"Response: {result['natural_response']}")Try these in the UI:
-
Phone Calls
- "What was the last phone call?"
- "Show me recent calls"
- "Any voicemails?"
-
Phone Messages (SMS)
- "Show me text messages"
- "Any SMS from the client?"
-
Email Communications
- "What quotes were sent?"
- "What's going on with this account?"
- "Show me recent emails"
-
Company Data
- "What are the contact details?"
- "What's the email address?"
- "How many employees do they have?"
-
General Queries
- "Show me all activity from last month"
- "What happened recently?"
┌─────────────────┐
│ Streamlit UI │
└────────┬────────┘
│
▼
┌─────────────────┐
│ LangChain │
│ SQL Agent │
├─────────────────┤
│ • Skill Router │
│ • SQL Chain │
│ • Response Chain│
│ • Memory Mgr │
└────────┬────────┘
│
▼
┌─────────────────┐
│ Executor │
├─────────────────┤
│ • Validator │
│ • PostgreSQL │
│ • Retry Logic │
└─────────────────┘
agents/sql_agent.py- Main LangChain agent orchestratorchains/sql_generation_chain.py- SQL generation chainchains/response_chain.py- Response generation chainmemory/conversation_memory.py- LangChain memory managercore/executor.py- SQL execution with retryui/app.py- Streamlit interface
pip install -r requirements.txt- Check DATABASE_URL in .env
- Test with:
python -c "from config.database import test_connection; print(test_connection())"
- Ensure memory_manager is in st.session_state
- Check session_id is consistent across requests
- Review error message in UI debug info
- Check that query includes company_id filter
- Ensure only SELECT queries (no INSERT/UPDATE/DELETE)
Enable detailed tracing:
# In .env
LANGCHAIN_TRACING_V2=true
LANGCHAIN_API_KEY=ls-your-key
LANGCHAIN_PROJECT=ai-assistantView traces at https://smith.langchain.com
- ✅ Get the app running
- Try example queries
- Review the architecture in README.md
- Customize skills for your use case
- Enable LangSmith for production monitoring
- Explore advanced LangChain features
- README.md - Detailed documentation
- LangChain docs - https://python.langchain.com
- LangSmith tracing - https://smith.langchain.com