This repository contains an AI agent framework that was made to simplify and separate the building and deployment phases of AI agents. Using sqlite, we are able to create & save agents, put them into stacks, then deploy those stacks of agents into any application connected to the server or machine.
Project description
Modular Intelligence
Modular Intelligence is a Python library designed to simplify the process of creating, managing, and deploying AI agents. The library leverages an SQLite database for seamless portability and enables you to define and organize agents into stacks, which can be shared and deployed across multiple workspaces.
Features
- Easy Installation: Install via pip with a single command.
- SQLite-Powered: Store agents and stacks in a local SQLite database at
~/.modular-intelligence/modular-intelligence.db. - Agent Portability: Create agents in one workspace and access them in another.
- Stack System: Organize agents into stacks for better modularity. Each stack can hold up to 5 agents, and you can have an unlimited number of stacks.
- Flexible Deployment: Define agents and stacks in one workspace and deploy them effortlessly in another.
Installation
Install the library using pip:
pip install modular_intelligence
Quick Start
Here is an example to get you started:
Creating an AI Agent
from modular_intelligence.agents import BaseAgent
# Create a new agent
agent = BaseAgent(name="ChatBot", description="A conversational AI agent", prompt="Hello! How can I help you today?")
# Save the agent to the database
agent.save_to_db()
print("Agent created and saved!")
Accessing an Agent in Another Workspace
from modular_intelligence.agents import BaseAgent
# Load the agent from the database
agent = BaseAgent()
agent.load_from_db("ChatBot")
print(f"Loaded agent: {agent.name}")
Creating and Managing Stacks
Stacks are updated in real time. There is no need for a "save()" function.
from modular_intelligence.agents import BaseAgent
from modular_intelligence.stacks import AgentStack
# Create agents
agent1 = BaseAgent(name="Agent1", description="Agent 1 description", prompt="Prompt for Agent 1")
agent2 = BaseAgent(name="Agent2", description="Agent 2 description", prompt="Prompt for Agent 2")
# Save agents to the database
agent1.save_to_db()
agent2.save_to_db()
# Create a stack with up to 5 agents
stack = AgentStack(name="ExampleStack", agents=[agent1, agent2])
stack.create(agents=[agent1, agent2])
print("Stack created and saved!")
# Load the stack in another workspace
stack.load_from_db(stack_name="ExampleStack")
print(f"Loaded stack: {stack.name} with agents: {[agent.name for agent in stack.agents]}")
Deploying Stacks
Deploy stacks in different workspaces by loading them from the database ( Not yet available ):
from modular_intelligence.stacks import AgentStack
# Load and deploy the stack
stack = AgentStack.load_from_db("ExampleStack") or AgentStack.load_from_db(stack_id=1)
stack.deploy()
Demo Script
The library includes a demo script to showcase its capabilities. This script demonstrates:
- Initializing the database.
- Creating AI agents for specific use cases (e.g., Math Tutor, English Tutor, Science Explainer, History Buff, Code Helper).
- Organizing agents into stacks.
- Managing agent conversations and creating checkpoints.
- Displaying database tables.
Demo Code Example
from modular_intelligence.database.init_db import init_database
from modular_intelligence.agents import BaseAgent
from modular_intelligence.stacks import AgentStack
from modular_intelligence.scripts.conversations.convos_for_demo_script import get_conversations
# Initialize the database
init_database()
print("Database initialized successfully!")
# Step 1: Create agents
agent1 = BaseAgent(name="MathTutor", description="An AI that helps with math problems.",
default_system_prompt="You are a math tutor helping students understand mathematical concepts.")
agent2 = BaseAgent(name="EnglishTutor", description="An AI that helps with English grammar and writing.",
default_system_prompt="You are an English tutor assisting students with grammar and composition.")
# Save agents to the database
agent1.save_to_db()
agent2.save_to_db()
# Step 2: Create a stack and add agents
stack = AgentStack(name="Education Stack", description="Stack for educational AI agents")
stack.create()
stack.add_slot(bot=agent1)
stack.add_slot(bot=agent2)
# Step 3: Simulate conversations and create checkpoints
conversations = get_conversations()
for agent, convo in zip([agent1, agent2], conversations):
for user_input in convo:
agent.generate_response(user_input)
agent.save_to_db()
# Step 4: Display database tables
import sqlite3
import pandas as pd
from modular_intelligence.database.init_db import Config
def display_table(table_name):
db_connection = sqlite3.connect(Config.DATABASE)
cursor = db_connection.cursor()
cursor.execute(f"SELECT * FROM {table_name}")
rows = cursor.fetchall()
columns = [description[0] for description in cursor.description]
df = pd.DataFrame(rows, columns=columns)
print(f"\nTable: {table_name}")
print(df)
cursor.close()
db_connection.close()
tables_to_display = ['Bots', 'Stacks', 'StackSlots']
for table in tables_to_display:
display_table(table_name=table)
Run this script to see agents and stacks in action. The output will display the database tables with details of agents, stacks, and their configurations.
File Structure
When installed, the SQLite database is located at:
~/.modular-intelligence/modular-intelligence.db
This ensures all agents and stacks are accessible across different projects or workspaces.
API Reference
Agent Class
agent = BaseAgent(name, description, prompt): Create a new AI agent.agent.save_to_db(status="optional custom checkpoint name"): Save the agent to the database.agent.load_from_db(name or id): Load an agent by name.
Stack Class
stack = AgentStack(name, agents): Create a new stack with up to 5 agents.stack.save_to_db(): Save the stack to the database.stack.load_from_db(name or stack_id): Load a stack by name.
Use Cases
- Agent Sharing: Create reusable AI agents that can be accessed from any workspace.
- Workspace Organization: Group agents into modular stacks for better manageability.
- Deployment Across Workspaces: Define agents and stacks in one environment and use them seamlessly elsewhere.
Contributing
Contributions are welcome! Feel free to submit issues or pull requests to improve the library.
- Fork the repository.
- Create your feature branch (
git checkout -b feature/AmazingFeature). - Commit your changes (
git commit -m 'Add some AmazingFeature'). - Push to the branch (
git push origin feature/AmazingFeature). - Open a pull request.
License
This project is licensed under the MIT License. See the LICENSE file for details.
Support
For issues or questions, open a GitHub issue or reach out to the maintainer.
Start building your AI agents with Modular Intelligence today!
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file modular_intelligence-0.0.7.tar.gz.
File metadata
- Download URL: modular_intelligence-0.0.7.tar.gz
- Upload date:
- Size: 27.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.12.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
492a3e807bb48e4a2f265f60046e2f6e9aa7d627afc7a71a0237097d1363a553
|
|
| MD5 |
ed7316c54b1bf4e39c78fef13b9749c8
|
|
| BLAKE2b-256 |
613e268a450510184a4c59587ad50f99c1938dd0d7667f4d6c958da3387751d6
|
File details
Details for the file modular_intelligence-0.0.7-py3-none-any.whl.
File metadata
- Download URL: modular_intelligence-0.0.7-py3-none-any.whl
- Upload date:
- Size: 29.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.12.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
be7cabd91e11f1779b92983e3519ae85ef39c3292b0f63b45f8e7d6d118141cc
|
|
| MD5 |
5c71f6232ef40d9095d77db5db502383
|
|
| BLAKE2b-256 |
543a604bf592086227df8527c9916df02ddcfb089dcdb6b4d02af2b63737eed9
|