Skip to main content

Overview

The Suada Python SDK provides a Pythonic interface to interact with the Suada API. Built with type safety in mind using Pydantic, it offers a robust and intuitive way to integrate Suada’s capabilities into your Python applications.

Prerequisites

  • Python 3.8 or higher
  • A Suada API key
  • pip package manager

Installation

Install the Suada Python SDK using pip:
Or using poetry:

Quick Start

Here’s a basic example to get you started:

Authentication

Setting up your API Key

We recommend storing your API key in environment variables:
Then load it in your application:

Core Concepts

Chat Messages

The chat endpoint is the primary way to interact with Suada. Each chat request can include:
  • A message (required)
  • Chat history (optional)
  • Configuration options (optional)

Response Format

Chat responses include several key components:

Advanced Features

Passthrough Mode

Passthrough mode allows you to associate Suada conversations with your application’s user system:

LangChain Integration

The SDK provides seamless integration with LangChain, allowing you to use Suada’s capabilities within your LangChain applications:

LangChain Best Practices

  1. Tool Configuration
    • Write clear, descriptive tool descriptions
    • Set appropriate temperature for your use case
    • Implement tool-specific error handling
    • Consider adding custom tool validation
  2. Agent Setup
    • Use structured prompts for consistent behavior
    • Implement conversation memory when needed
    • Consider using different agent types based on your needs
    • Test agent behavior with various input types
  3. Error Handling
    • Implement proper error handling for both Suada and LangChain
    • Add retry logic for transient failures
    • Log agent actions for debugging
    • Consider implementing fallback mechanisms
  4. Memory Management
    • Choose appropriate memory types for your use case
    • Implement memory cleanup when needed
    • Consider memory persistence for long-running conversations
    • Handle memory size limitations
  5. Performance Optimization
    • Reuse agent instances when possible
    • Implement appropriate timeouts
    • Consider caching for frequently used data
    • Monitor memory usage in long-running applications

Privacy Mode

Enable privacy mode to ensure sensitive information is handled with additional security:

Error Handling

The SDK provides robust error handling with descriptive exceptions:

Best Practices

  1. Environment Variables
    • Store API keys and sensitive configuration in environment variables
    • Use python-dotenv for environment variable management
    • Never commit API keys to version control
  2. Error Handling
    • Implement try-except blocks around API calls
    • Use specific exception types for better error handling
    • Log errors appropriately for debugging
  3. Type Safety
    • Take advantage of Pydantic models and type hints
    • Use mypy for static type checking
    • Enable strict type checking in your development environment
  4. Response Processing
    • Always check for the presence of optional fields
    • Handle missing data gracefully
    • Implement proper error handling for data parsing

Configuration Options

FAQ

How do I handle rate limiting?

The SDK automatically implements exponential backoff for rate limits. You can customize the retry behavior:

How do I maintain conversation context?

Use the chat_history parameter to maintain conversation context:

How can I enable debug logging?

Use Python’s built-in logging module:

Can I use the SDK in async/await code?

Yes, the SDK provides async support:

Development Setup

For contributors and developers:

Support