Introduction
Imagine an AI assistant that doesn’t just respond to your queries but also executes multiple tasks in parallel, tracks user activity, and handles complex function chains seamlessly.
This system is modular, event-driven, and built on the Mediator pattern, allowing local function calling, dynamic task execution, and AI-driven responses. Unlike traditional chatbots, this one doesn’t just talk—it acts, executing real-time commands with asynchronous efficiency.
Whether it's controlling smart devices, managing workflows, or responding intelligently, this AI Chat Assistant delivers powerful, fluid, and natural interactions.
Features at a Glance
Advanced Function Execution
- Local Function Calling – Execute system functions dynamically.
- Chained Function Calling – Queue and execute multiple functions in sequence.
- Simultaneous Function Execution – Run multiple functions at once.
Intelligent Voice Interaction
- Google STT (Speech-to-Text API) – Converts speech into actionable text.
- Google TTS (Studio-Q Voice) – Generates natural AI voice responses.
Performance & Efficiency
- Asynchronous Task Execution – Ensures smooth, non-blocking operations.
- Function Library & Manager – Dynamically handles function retrieval and execution.
- User Activity Tracking – Monitors engagement and optimizes responses dynamically.
Requirements
Core Modules
- Google Gemini AI – Powers chatbot responses.
- Google Speech-to-Text API – Processes voice input.
- Google Text-to-Speech API (Studio-Q Voice) – Generates spoken responses.
Python Modules Used
google.generativeai
– AI-powered chatbot interactions.asyncio
– Enables asynchronous execution of tasks.playsound
/pydub
– For playing TTS responses.
Custom Modules
Module | Description |
---|---|
Mediator | Central hub that connects all components for seamless communication. |
STT | Converts speech input into text commands. |
TTS | Converts chatbot responses into spoken output. |
TaskManager | Handles chained and parallel function execution. |
FunctionManager | Dynamically retrieves and executes functions from the Function Library. |
Function Library | Collection of predefined functions (e.g., play_music.py , dim_lights.py ). |
ChatApp | Manages chat history and response caching. |
FeedbackManager | Monitors user activity and detects delays in responses. |
AudioPlayer | Handles playback of AI-generated speech. |
What Makes This System Unique?
This AI assistant isn’t just a chatbot—it’s a real-time execution engine. Thanks to the FunctionManager and TaskManager, it can process multiple function calls, queue tasks, and execute them asynchronously.
Chained Function Execution Example
With chained function calling, the AI can execute multiple commands in a single request.
def generate_response(self, user_input: str):
response = self.chatbot.send_message(user_input)
has_function_call = False
for part in response.parts:
if fn := part.function_call:
has_function_call = True
function = self.function_manager.get_function(fn.name)
if function:
self.task_manager.add_task(function=function, **fn.args)
if not has_function_call:
self.audio_player.play(self.text_to_speech.run_speech_generation(response.text))
self.chatapp.update_chat_history(user_input, response.text)
- User Input: "Start the project and play some music."
- Detected Functions:
start_project_task()
,play_music()
- Task Execution: Start Project → Play Music → Confirm Execution
- Bot Response: "Project started. Playing music. What else can I do?"
Asynchronous Task Execution with Feedback Tracking
The TaskManager ensures smooth execution without blocking other operations. Each task is wrapped with a feedback timer, which ensures that execution delays are detected and handled appropriately.
import asyncio
from functools import partial
from helper.feedback_manager import TaskFeedback
async def _add_task_async(self, function, **kwargs):
# Start feedback timer
task_feedback = TaskFeedback(self.send_task_feedback)
task_feedback.reset()
def feedback_wrapper(**kwargs):
# Execute the task
results = function(**kwargs)
# Stop timer as soon as execution completes
task_feedback.kill_timer()
return results
async def wrapper(**kwargs):
try:
loop = asyncio.get_event_loop()
bound_func = partial(feedback_wrapper, **kwargs)
result = await loop.run_in_executor(None, bound_func)
# Process results
self.mediator.handle_function_call_results({function.__name__: result})
except Exception as e:
# Handle execution errors
self.mediator.handle_function_call_results(f'{function.__name__}:{e}')
print(f"Task {function.__name__} raised an exception: {e}")
- User says: "Turn on the lights and adjust the volume."
- System detects:
dim_lights()
andchange_system_volume()
- Task Execution:
- Lights dimming...
- Volume adjusting...
- Feedback Tracking: System ensures execution happens without delays.
- Bot Response: "Lights dimmed. Volume adjusted. Need anything else?"
Why This System Stands Out
Unlike traditional chatbots, this AI assistant doesn’t just talk—it acts. With function chaining, parallel execution, and real-time interaction, this system is designed for automation, workflow management, and AI-powered task execution.
Contributing
Currently, this repository is private and still under development. Once it's ready for public access, i'll update this section with information on how you can get involved. In the meantime, feel free to reach out if you have any questions.
License
This project is licensed under the MET License - see the LICENSE file for details.
MET License
The MET License is a permissive open-source license. It allows users to do anything with the code, including modification, distribution, and commercial use, as long as the original copyright notice and disclaimer are retained. However, the original author or copyright holder is not liable for any consequences resulting from the use of this software. Read the full MET License