Government Scheme Awareness Agent using LiveKit

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.

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, OpenAI)
  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,openai,silero]" python-dotenv

3. Create Environment File

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

1LIVEKIT_URL=wss://your-project-xxxxx.livekit.cloud
2LIVEKIT_API_KEY=APIxxxxxxxxxxxxx
3LIVEKIT_API_SECRET=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
4SARVAM_API_KEY=sk_xxxxxxxxxxxxxxxxxxxxxxxx
5OPENAI_API_KEY=sk-proj-xxxxxxxxxxxxxxxx

Replace the values with your actual API keys.

4. Write Your Agent

Create scheme_awareness_agent.py:

1import logging
2from dotenv import load_dotenv
3from livekit.agents import JobContext, WorkerOptions, cli
4from livekit.agents.voice import Agent, AgentSession
5from livekit.plugins import openai, sarvam
6
7# Load environment variables
8load_dotenv()
9
10# Set up logging
11logger = logging.getLogger("scheme-awareness-agent")
12logger.setLevel(logging.INFO)
13
14
15class GovernmentSchemeAgent(Agent):
16 def __init__(self) -> None:
17 super().__init__(
18 # Government scheme awareness agent personality and instructions
19 instructions="""
20 You are a helpful government scheme awareness assistant designed to help Indian citizens
21 understand and access various government welfare schemes and programs.
22
23 Your responsibilities:
24 - Explain government schemes in simple, easy-to-understand language
25 - Help citizens determine their eligibility for various schemes
26 - Provide information about required documents for applications
27 - Guide users through the application process step by step
28 - Answer questions about scheme benefits, deadlines, and procedures
29 - Suggest relevant schemes based on user's situation (farmer, student, senior citizen, etc.)
30
31 Key government schemes you should know about:
32 - PM Kisan Samman Nidhi (farmer income support)
33 - Ayushman Bharat (health insurance)
34 - PM Awas Yojana (housing for all)
35 - Sukanya Samriddhi Yojana (girl child savings)
36 - PM Ujjwala Yojana (LPG connections)
37 - MGNREGA (rural employment guarantee)
38 - PM Jan Dhan Yojana (financial inclusion)
39 - Atal Pension Yojana (pension scheme)
40 - PM Mudra Yojana (small business loans)
41 - Skill India Mission (skill development)
42
43 Communication guidelines:
44 - Use simple language avoiding complex jargon
45 - Be patient and willing to repeat or explain again
46 - Speak slowly and clearly
47 - Be encouraging and supportive
48 - If you don't know something, honestly say so and suggest where they can get accurate information
49 - Always mention official government portals for verification
50 - Be sensitive to the fact that many users may have limited formal education
51
52 Start by greeting the user warmly and asking how you can help them today with government schemes.
53 """,
54
55 # Saarika STT - Converts speech to text
56 stt=sarvam.STT(
57 language="unknown", # Auto-detect language for accessibility
58 model="saarika:v2.5"
59 ),
60
61 # OpenAI LLM - The "brain" that processes and generates responses
62 llm=openai.LLM(model="gpt-4o"),
63
64 # Bulbul TTS - Converts text to speech
65 tts=sarvam.TTS(
66 target_language_code="hi-IN", # Hindi as default for wider reach
67 model="bulbul:v2",
68 speaker="manisha" # Warm and friendly female voice
69 ),
70 )
71
72 async def on_enter(self):
73 """Called when user joins - agent starts the conversation"""
74 self.session.generate_reply()
75
76
77async def entrypoint(ctx: JobContext):
78 """Main entry point - LiveKit calls this when a user connects"""
79 logger.info(f"User connected to room: {ctx.room.name}")
80
81 # Create and start the agent session
82 session = AgentSession()
83 await session.start(
84 agent=GovernmentSchemeAgent(),
85 room=ctx.room
86 )
87
88
89if __name__ == "__main__":
90 # Run the agent
91 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:

1stt=sarvam.STT(
2 language="hi-IN", # Hindi
3 model="saarika:v2.5"
4),
5tts=sarvam.TTS(
6 target_language_code="hi-IN",
7 model="bulbul:v2",
8 speaker="manisha" # Warm and friendly voice
9)

Example 2: Tamil Agent for Rural Tamil Nadu

1stt=sarvam.STT(language="ta-IN", model="saarika:v2.5"),
2tts=sarvam.TTS(
3 target_language_code="ta-IN",
4 model="bulbul:v2",
5 speaker="anushka"
6)

Example 3: Bengali Agent for West Bengal

1stt=sarvam.STT(language="bn-IN", model="saarika:v2.5"),
2tts=sarvam.TTS(
3 target_language_code="bn-IN",
4 model="bulbul:v2",
5 speaker="vidya"
6)

Example 4: Multilingual Agent (Auto-detect)

For citizen service centers serving diverse populations:

1stt=sarvam.STT(language="unknown", model="saarika:v2.5"), # Auto-detects language
2tts=sarvam.TTS(target_language_code="hi-IN", model="bulbul:v2", speaker="manisha")

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

When you need to process regional language input but generate English reports:

1# User speaks in any Indian language → Saaras converts to English → LLM processes
2
3stt=sarvam.STT(model="saaras:v2.5"), # Speech-to-English translation
4llm=openai.LLM(model="gpt-4o"),
5tts=sarvam.TTS(target_language_code="en-IN", model="bulbul:v2", speaker="anushka")

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 v2)

Female Voices:

  • anushka - Clear and professional (default)
  • manisha - Warm and friendly (recommended for citizen services)
  • vidya - Articulate and precise
  • arya - Young and energetic

Male Voices:

  • abhilash - Deep and authoritative
  • karun - Natural and conversational
  • hitesh - Professional and engaging

Pro Tips

  • Use language="unknown" to serve citizens who speak different languages
  • Use warm, friendly voices like manisha 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!