Skip to main content

Python client for Agora REST APIs

Project description

Agora REST Client - Python

Python SDK for Agora REST APIs, including Conversational AI Agent management.

Features

  • 🤖 High-level Agent API - Simple interface for managing Agora Conversational AI Agents
  • 🔧 Configuration Management - Easy configuration from environment variables
  • 🎯 Type-safe - Full type hints support
  • 📦 Lightweight - Minimal dependencies
  • 🚀 Production-ready - Built for reliability and performance

Installation

From PyPI (Recommended)

pip install agora-rest-client-python

From Git Repository

pip install git+https://github.com/your-org/agora-rest-client-python.git

For Development

git clone https://github.com/your-org/agora-rest-client-python.git
cd agora-rest-client-python
pip install -e .

Quick Start

1. Set up environment variables

Create a .env file:

# Agora Configuration
APP_ID=your_app_id
APP_CERTIFICATE=your_app_certificate

# Agora REST API Credentials
API_KEY=your_customer_id
API_SECRET=your_customer_secret

# LLM - OpenAI
LLM_API_KEY=your_openai_key

# ASR - Deepgram (Optional)
ASR_DEEPGRAM_API_KEY=your_deepgram_key

# TTS - ElevenLabs (Optional)
TTS_ELEVENLABS_API_KEY=your_elevenlabs_key

2. Initialize and use the Agent

import os
from agora_rest import AgentClient
from agora_rest.agent import DeepgramASRConfig, OpenAILLMConfig, ElevenLabsTTSConfig

# Create agent client
client = AgentClient(
    app_id=os.getenv("APP_ID"),
    app_certificate=os.getenv("APP_CERTIFICATE"),
    customer_id=os.getenv("API_KEY"),
    customer_secret=os.getenv("API_SECRET")
)

# Generate connection configuration
config_data = client.generate_config()
print(f"Channel: {config_data['channel_name']}")
print(f"Token: {config_data['token']}")

# Configure ASR, LLM, TTS
asr = DeepgramASRConfig(api_key=os.getenv("ASR_DEEPGRAM_API_KEY"))
llm = OpenAILLMConfig(api_key=os.getenv("LLM_API_KEY"))
tts = ElevenLabsTTSConfig(api_key=os.getenv("TTS_ELEVENLABS_API_KEY"))

# Start an agent
result = client.start_agent(
    channel_name=config_data['channel_name'],
    agent_uid=config_data['agent_uid'],
    user_uid=config_data['uid'],
    asr_config=asr,
    llm_config=llm,
    tts_config=tts
)

print(f"Agent started: {result['agent_id']}")


# Stop the agent
manager.stop_agent(result['agent_id'])
print("Agent stopped")

Configuration

Environment Variables

Variable Description Required
APP_ID Agora App ID Yes
APP_CERTIFICATE Agora App Certificate Yes
API_KEY Agora REST API Customer ID Yes
API_SECRET Agora REST API Customer Secret Yes
LLM_API_KEY OpenAI LLM API key Yes
ASR_DEEPGRAM_API_KEY Deepgram ASR API key Optional
TTS_ELEVENLABS_API_KEY ElevenLabs TTS API key Optional
PORT Server port (default: 8000) Optional

API Reference

AgentClient

Core business logic for agent operations.

import os
from agora_rest import AgentClient

client = AgentClient(
    app_id=os.getenv("APP_ID"),
    app_certificate=os.getenv("APP_CERTIFICATE"),
    customer_id=os.getenv("API_KEY"),
    customer_secret=os.getenv("API_SECRET")
)

# Generate connection configuration
config_data = client.generate_config()

# Start an agent
result = manager.start_agent(
    channel_name="my_channel",
    agent_uid="123",
    user_uid="456",
    asr_config={...},
    llm_config={...},
    tts_config={...}
)

# Stop an agent
manager.stop_agent(agent_id)

Configuration Components

from agora_rest.agent import ASRConfig, LLMConfig, TTSConfig

# ASR Configuration (Deepgram) - uses defaults
asr = ASRConfig(api_key="your_deepgram_key")

# LLM Configuration (OpenAI) - uses defaults
llm = LLMConfig(api_key="your_openai_key")

# TTS Configuration (ElevenLabs) - uses defaults
tts = TTSConfig(api_key="your_elevenlabs_key")

# Optional: Customize if needed
# llm.model = "gpt-4o"
# llm.system_message = "You are a helpful assistant"
# asr.language = "zh-CN"

Supported Vendors

ASR (Automatic Speech Recognition)

  • ✅ Deepgram

LLM (Large Language Model)

  • ✅ OpenAI (GPT-4, GPT-3.5)

TTS (Text-to-Speech)

  • ✅ ElevenLabs

Examples

See the examples directory for more usage examples.

Requirements

Development

Setup Development Environment

# Clone repository
git clone https://github.com/your-org/agora-rest-client-python.git
cd agora-rest-client-python

# Create virtual environment
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate

# Install dependencies
pip install -r requirements.txt

# Install in editable mode
pip install -e .

Running Tests

pytest

Code Style

# Format code
black .

# Lint code
flake8 .

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Support

Changelog

See CHANGELOG.md for version history.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

agora_rest_client_python-0.1.1.tar.gz (29.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

agora_rest_client_python-0.1.1-py3-none-any.whl (33.9 kB view details)

Uploaded Python 3

File details

Details for the file agora_rest_client_python-0.1.1.tar.gz.

File metadata

  • Download URL: agora_rest_client_python-0.1.1.tar.gz
  • Upload date:
  • Size: 29.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.10

File hashes

Hashes for agora_rest_client_python-0.1.1.tar.gz
Algorithm Hash digest
SHA256 8ccd912d2de0556e8aba15ce83a48e82bd6470c6bc8870861e1b6305cecbd102
MD5 8ac969cc8ad5ef305b3d3bc6d04d29b2
BLAKE2b-256 114db46e8b07c8f45c77c9e527a26bed891b3b6f8d068c72e5ac99f362131a67

See more details on using hashes here.

File details

Details for the file agora_rest_client_python-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for agora_rest_client_python-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 00be46d6e085882f76a31e66f82220ff6803b692df89598163a5ecb742419f91
MD5 84bee327066c06be4bd740d0e1b5f1f3
BLAKE2b-256 95688bf8abdcfccdc51d1a046a921d258937165a3b8e80e973b97b9d325a7fde

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page