Skip to navigation

Government Scheme Awareness Agent using LiveKit

View as Markdown

Overview

This guide demonstrates how to build a government scheme awareness agent that helps citizens discover, understand, and learn how to apply for various government welfare schemes using LiveKit for real-time communication and Sarvam AI for speech processing. Ideal for government digital initiatives, NGOs, and citizen service centers.

For the broader architecture pattern this agent fits into, accessibility, grounding scheme facts, latency targets, see the Government Services use-case guide. For a closely related rural/farmer audience, see Agri & Rural.

What You’ll Build

A voice agent that can:

  • Explain various government schemes in simple language
  • Help citizens understand eligibility criteria
  • Guide users through application processes
  • Answer questions about benefits, documents required, and deadlines
  • Communicate in multiple Indian languages for maximum accessibility

Quick Overview

  1. Get API keys (LiveKit, Sarvam)
  2. Install packages
  3. Create .env file with your API keys
  4. Write the agent code
  5. Run: python agent.py dev
  6. Test: python agent.py console

Quick Start

1. Prerequisites

2. Install Dependencies

pip install "livekit-agents[sarvam,silero]" python-dotenv

3. Create Environment File

Create a file named .env in your project folder and add your API keys:

LIVEKIT_URL=wss://your-project-xxxxx.livekit.cloud
LIVEKIT_API_KEY=APIxxxxxxxxxxxxx
LIVEKIT_API_SECRET=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
SARVAM_API_KEY=sk_xxxxxxxxxxxxxxxxxxxxxxxx

Replace the values with your actual API keys.

4. Write Your Agent

Create scheme_awareness_agent.py:

import logging
from dotenv import load_dotenv
from livekit.agents import JobContext, WorkerOptions, cli
from livekit.agents.voice import Agent, AgentSession
from livekit.plugins import sarvam
# Load environment variables
load_dotenv()
# Set up logging
logger = logging.getLogger("scheme-awareness-agent")
logger.setLevel(logging.INFO)
class GovernmentSchemeAgent(Agent):
def __init__(self) -> None:
super().__init__(
# Government scheme awareness agent personality and instructions
instructions="""
You are a helpful government scheme awareness assistant designed to help Indian citizens
understand and access various government welfare schemes and programs.
Your responsibilities:
- Explain government schemes in simple, easy-to-understand language
- Help citizens determine their eligibility for various schemes
- Provide information about required documents for applications
- Guide users through the application process step by step
- Answer questions about scheme benefits, deadlines, and procedures
- Suggest relevant schemes based on user's situation (farmer, student, senior citizen, etc.)
Key government schemes you should know about:
- PM Kisan Samman Nidhi (farmer income support)
- Ayushman Bharat (health insurance)
- PM Awas Yojana (housing for all)
- Sukanya Samriddhi Yojana (girl child savings)
- PM Ujjwala Yojana (LPG connections)
- MGNREGA (rural employment guarantee)
- PM Jan Dhan Yojana (financial inclusion)
- Atal Pension Yojana (pension scheme)
- PM Mudra Yojana (small business loans)
- Skill India Mission (skill development)
Communication guidelines:
- Use simple language avoiding complex jargon
- Be patient and willing to repeat or explain again
- Speak slowly and clearly
- Be encouraging and supportive
- If you don't know something, honestly say so and suggest where they can get accurate information
- Always mention official government portals for verification
- Be sensitive to the fact that many users may have limited formal education
Start by greeting the user warmly and asking how you can help them today with government schemes.
""",
# Saaras v4 STT - Converts speech to text
stt=sarvam.STT(
language="unknown", # Auto-detect language for accessibility
model="saaras:v4",
mode="transcribe"
),
# Sarvam LLM - The "brain" that processes and generates responses
llm=sarvam.LLM(model="sarvam-105b"),
# Bulbul TTS - Converts text to speech
tts=sarvam.TTS(
language_code="hi-IN", # Hindi as default for wider reach
model="bulbul:v3",
speaker="simran" # Warm and friendly female voice
),
)
async def on_enter(self):
"""Called when user joins - agent starts the conversation"""
self.session.generate_reply()
async def entrypoint(ctx: JobContext):
"""Main entry point - LiveKit calls this when a user connects"""
logger.info(f"User connected to room: {ctx.room.name}")
# Create and start the agent session
session = AgentSession()
await session.start(
agent=GovernmentSchemeAgent(),
room=ctx.room
)
if __name__ == "__main__":
# Run the agent
cli.run_app(WorkerOptions(entrypoint_fnc=entrypoint))

5. Run Your Agent

python scheme_awareness_agent.py dev

6. Test Your Agent

In a new terminal, run:

python scheme_awareness_agent.py console

Customization Examples

Example 1: Hindi-focused Agent

For Hindi-speaking citizens:

stt=sarvam.STT(
language="hi-IN", # Hindi
model="saaras:v4",
mode="transcribe"
),
tts=sarvam.TTS(
language_code="hi-IN",
model="bulbul:v3",
speaker="simran" # Warm and friendly voice
)

Example 2: Tamil Agent for Rural Tamil Nadu

stt=sarvam.STT(language="ta-IN", model="saaras:v4", mode="transcribe"),
tts=sarvam.TTS(
language_code="ta-IN",
model="bulbul:v3",
speaker="priya"
)

Example 3: Bengali Agent for West Bengal

stt=sarvam.STT(language="bn-IN", model="saaras:v4", mode="transcribe"),
tts=sarvam.TTS(
language_code="bn-IN",
model="bulbul:v3",
speaker="ishita"
)

Example 4: Multilingual Agent (Auto-detect)

For citizen service centers serving diverse populations:

stt=sarvam.STT(language="unknown", model="saaras:v4", mode="transcribe"), # Auto-detects language
tts=sarvam.TTS(language_code="hi-IN", model="bulbul:v3", speaker="simran")

Example 5: Speech-to-English Agent (Saaras)

When you need to process regional language input but generate English reports. Saaras v4 handles both transcription (same-language output) and translation (English output) via the mode parameter: use mode="translate" for speech-to-English.

# User speaks in any Indian language → Saaras converts to English → LLM processes
stt=sarvam.STT(model="saaras:v4", mode="translate"), # Speech-to-English translation
llm=sarvam.LLM(model="sarvam-105b"),
tts=sarvam.TTS(language_code="en-IN", model="bulbul:v3", speaker="priya")

Available Options

Language Codes

LanguageCode
English (India)en-IN
Hindihi-IN
Bengalibn-IN
Tamilta-IN
Telugute-IN
Gujaratigu-IN
Kannadakn-IN
Malayalamml-IN
Marathimr-IN
Punjabipa-IN
Odiaod-IN
Auto-detectunknown

Speaker Voices (Bulbul v3)

Male (23): Shubh (default), Aditya, Rahul, Rohan, Amit, Dev, Ratan, Varun, Manan, Sumit, Kabir, Aayan, Ashutosh, Advait, Anand, Tarun, Sunny, Mani, Gokul, Vijay, Mohit, Rehan, Soham

Female (14): Ritu, Priya, Neha, Pooja, Simran, Kavya, Ishita, Shreya, Roopa, Tanya, Shruti, Suhani, Kavitha, Rupali


Pro Tips

  • Use language="unknown" to serve citizens who speak different languages
  • Use warm, friendly voices like simran for citizen-facing services
  • Sarvam’s models handle code-mixing naturally - citizens often mix Hindi with English or regional languages
  • Consider deploying region-specific agents for better language accuracy
  • Keep responses simple and avoid bureaucratic jargon

Troubleshooting

API key errors: Check that all keys are in your .env file and the file is in the same directory as your script.

Module not found: Run the installation command again based on your operating system.

Poor transcription: Try language="unknown" for auto-detection, or specify the correct language code.


Additional Resources


Need Help?


Happy Building!