Skip to content

jathinsn27/travis_ai

Repository files navigation

Travis AI - Letta Agent with Slack Integration

A FastAPI application that integrates Letta AI agents with Slack, providing intelligent conversation capabilities through a single endpoint.

Features

  • 🤖 Letta AI Integration: Uses a persistent Letta agent for intelligent conversations
  • 💬 Slack Integration: Handles Slack URL verification, message events, and app mentions
  • 🔄 Automatic Responses: Posts Letta agent responses back to Slack channels
  • 🎯 Smart Filtering: Filters out simple greetings to reduce noise
  • 🌐 ngrok Support: Easy deployment with static domain support
  • 📝 Comprehensive Logging: Detailed debug information for troubleshooting

Project Structure

travis_ai/
├── letta/
│   ├── create_agent.py      # Letta agent manager
│   └── api.py               # Legacy API (moved to simple_api.py)
├── slack/
│   └── auth_middleware.py   # Slack authentication middleware
├── simple_api.py            # Main FastAPI application
├── main.py                  # Entry point
├── run.py                   # Simplified startup script
├── test.py                  # Basic API tests
├── requirements.txt         # Python dependencies
├── .env                     # Environment variables (create this)
└── README.md               # This file

Prerequisites

Setup Instructions

1. Clone and Install Dependencies

# Clone the repository
git clone <your-repo-url>
cd travis_ai

# Install dependencies using uv
uv pip install -r requirements.txt

2. Environment Configuration

Create a .env file in the project root:

# Letta AI Configuration
LETTA_API_KEY=your_letta_api_key_here

# Slack Configuration  
SLACK_BOT_TOKEN=xoxb-your-slack-bot-token-here

# Optional: ngrok static domain
NGROK_DOMAIN=your-static-domain.ngrok-free.dev

3. Letta Agent Setup

The application uses a pre-configured Letta agent ID: agent-2ed1f26b-6de6-4d1a-8466-b89e12482f71

If you need to create a new agent, you can use the letta/create_agent.py script:

uv run python letta/create_agent.py

4. Slack App Configuration

  1. Create a Slack app at api.slack.com/apps
  2. Add the following OAuth scopes:
    • app_mentions:read
    • channels:history
    • chat:write
    • im:history
    • im:read
    • im:write
  3. Subscribe to bot events:
    • message.channels
    • app_mention
  4. Set the Request URL to your ngrok URL + /conversation

Running the Application

Option 1: Local Development

# Run locally without ngrok
uv run python simple_api.py

# Or use the main entry point
uv run python main.py

Option 2: With ngrok (for Slack integration)

# Run with ngrok tunneling
uv run python simple_api.py --ngrok

# Or use the main entry point with ngrok
uv run python main.py --ngrok

Option 3: Using the simplified runner

# Local
uv run python run.py

# With ngrok
uv run python run.py --ngrok

API Endpoints

POST /conversation

The main endpoint that handles all interactions:

Slack URL Verification:

{
  "type": "url_verification",
  "challenge": "challenge_string"
}

Slack Message Events:

{
  "type": "event_callback",
  "event": {
    "type": "message",
    "user": "U1234567890",
    "text": "Hello, how are you?",
    "channel": "C1234567890"
  }
}

Direct Conversation:

{
  "message": "What is Python programming?"
}

GET /health

Health check endpoint that returns:

{
  "status": "healthy",
  "message": "Simple Letta Agent API is running",
  "agent_id": "agent-2ed1f26b-6de6-4d1a-8466-b89e12482f71"
}

Testing

Run the basic test suite:

uv run python test.py

This will test:

  • Health check endpoint
  • URL verification
  • Simple greeting filtering
  • Direct conversation with Letta agent

Slack Integration

Event Types Handled

  1. URL Verification: Responds to Slack's challenge requests
  2. Message Events: Processes regular channel messages
  3. App Mentions: Handles @bot mentions specifically

Message Filtering

The application filters out simple greetings to reduce noise:

  • hi, hey, hiya
  • good morning/afternoon/evening
  • what's up, how are you
  • thanks, ok, yes, no

Response Posting

  • Responses are automatically posted back to Slack
  • Uses threading to keep conversations organized
  • Includes comprehensive logging for debugging

Troubleshooting

Common Issues

  1. ModuleNotFoundError: Ensure all dependencies are installed with uv pip install -r requirements.txt

  2. LETTA_API_KEY not set: Check your .env file and ensure the API key is correct

  3. Slack events not received:

    • Verify ngrok is running and accessible
    • Check Slack app configuration
    • Ensure Request URL points to /conversation
  4. Agent not responding:

    • Verify the agent ID is correct
    • Check Letta API key permissions
    • Review logs for error messages

Debug Logging

The application provides extensive debug logging:

  • 🔍 DEBUG: - Detailed request/response information
  • - Successful operations
  • - Errors and failures
  • 📨 - Slack message processing
  • 🤖 - Letta agent responses

Development

Code Structure

  • simple_api.py: Main FastAPI application with single endpoint
  • letta/create_agent.py: Letta agent management and API interactions
  • slack/auth_middleware.py: Slack authentication and middleware
  • main.py: Application entry point with argument parsing
  • run.py: Simplified startup script

Key Components

  1. LettaAgentManager: Handles all Letta API interactions
  2. Message Filtering: Smart filtering to reduce noise
  3. Slack Integration: URL verification and event handling
  4. Response Posting: Automatic Slack message posting
  5. Error Handling: Comprehensive error handling and logging

Deployment

Local Development

uv run python simple_api.py --ngrok

Production Considerations

  • Use a proper WSGI server like Gunicorn
  • Set up proper environment variable management
  • Configure SSL/TLS for HTTPS
  • Use a proper domain instead of ngrok for production

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Test thoroughly
  5. Submit a pull request

License

This project is licensed under the MIT License.

Support

For issues and questions:

  1. Check the troubleshooting section
  2. Review the debug logs
  3. Verify environment configuration
  4. Test with the provided test suite

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages