Skip to main content

Step 1: Deploy Your Agent

Before integrating with CometChat, ensure your agent is:
  • Publicly accessible over HTTPS
  • Running on a stable server (AWS, Google Cloud, Azure, etc.)
  • Protected with authentication headers

Step 2: Configure Agent in CometChat Dashboard

  1. Login to CometChat Dashboard
  2. Navigate to AI Agents
    • Go to AI Agents in the left-hand menu
    • Click “Add Agent” or “Custom Agents”
  3. Configure Agent Settings Basic Information:
    • Agent Name: Give your agent a memorable name (e.g., “Support Assistant”)
    • Provider: Select “Custom” or “AG-UI Compatible”
    • Deployment URL: Enter your agent’s public URL
    Agent Identity:
    • Display Name: Name shown to users (e.g., “AI Assistant”)
    • Avatar: Upload an avatar image for your agent
    • Greeting Message: Set a welcome message
  4. Configure Security Headers CometChat allows you to securely access your agent using custom headers. This is highly recommended for production. Headers Configuration (JSON format):
    Example with Basic Auth:
  5. Enable the Agent
    • Toggle the agent status to “Enabled”
    • Click “Save”

Step 3: Implement Header Validation in Your Agent

Express.js Example:
NestJS Example:

Step 4: Test Integration

  1. Access CometChat in your app
  2. Start a conversation with your AI agent
  3. Send a message and verify the agent responds correctly
  4. Check streaming - messages should appear token-by-token
  5. Test tools - if your agent uses tools, verify they execute properly

Step 5: Monitor and Debug

Check Agent Logs:
CometChat Analytics:
  • Navigate to Analytics in CometChat dashboard
  • Monitor agent performance, response times, and error rates

Best Practices and Security

Security Best Practices

1. Use HTTPS

Always deploy your agent with HTTPS. Never expose HTTP endpoints in production.

2. Implement Authentication

Use strong authentication headers:

3. Rate Limiting

Implement rate limiting to prevent abuse:

4. Input Validation

Validate all inputs:

5. Error Handling

Never expose sensitive information in errors:

Performance Best Practices

1. Streaming Optimization

Stream responses as soon as possible:

2. Connection Management

Handle client disconnections gracefully:

3. Timeout Configuration

Set appropriate timeouts:

4. Memory Management

Clean up resources properly:

Development Best Practices

1. Environment Variables

Use environment variables for all sensitive data:

2. TypeScript Strict Mode

Enable strict TypeScript checking:

3. Logging

Implement structured logging:

4. Testing

Write tests for your agent:

Deployment Checklist

  • Agent is accessible over HTTPS
  • Authentication headers are configured
  • Rate limiting is enabled
  • Input validation is implemented
  • Error handling doesn’t expose sensitive data
  • Logging is configured
  • Environment variables are set
  • Timeouts are configured appropriately
  • Health check endpoint is available
  • Agent is tested with real CometChat integration

Conclusion

You now have a comprehensive understanding of:
  1. AG-UI Protocol - Event types, message formats, and patterns
  2. CometChat Integration - “Bring Your Own Agent” approach
  3. Agent Implementation - Complete Express.js and NestJS examples
  4. Security & Best Practices - Production-ready configurations
Your AG-UI compatible agent can now be seamlessly integrated with CometChat, providing a powerful, self-served AI agent experience with full control over your agent logic while benefiting from CometChat’s production-ready chat infrastructure.

Additional Resources


Happy Building! 🚀