Skip to main content

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:

  1. Initializing the database.
  2. Creating AI agents for specific use cases (e.g., Math Tutor, English Tutor, Science Explainer, History Buff, Code Helper).
  3. Organizing agents into stacks.
  4. Managing agent conversations and creating checkpoints.
  5. 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.

  1. Fork the repository.
  2. Create your feature branch (git checkout -b feature/AmazingFeature).
  3. Commit your changes (git commit -m 'Add some AmazingFeature').
  4. Push to the branch (git push origin feature/AmazingFeature).
  5. 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


Download files

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

Source Distribution

modular_intelligence-0.0.10.tar.gz (28.0 kB view details)

Uploaded Source

Built Distribution

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

modular_intelligence-0.0.10-py3-none-any.whl (29.9 kB view details)

Uploaded Python 3

File details

Details for the file modular_intelligence-0.0.10.tar.gz.

File metadata

  • Download URL: modular_intelligence-0.0.10.tar.gz
  • Upload date:
  • Size: 28.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.5

File hashes

Hashes for modular_intelligence-0.0.10.tar.gz
Algorithm Hash digest
SHA256 fc0ad35841ffd4884d3c8fec06ae8a8314a46f18e6aa2da592de18a9637a7f6f
MD5 25c7033a758f32ff7371947f6b6cf255
BLAKE2b-256 b754b0052371dea4c5ce3f27a7c3de1eaebd2ed2e39c020b46e905239ee5230b

See more details on using hashes here.

File details

Details for the file modular_intelligence-0.0.10-py3-none-any.whl.

File metadata

File hashes

Hashes for modular_intelligence-0.0.10-py3-none-any.whl
Algorithm Hash digest
SHA256 daafe353edea95f64ca0caeaee7e346234d9b64812b71d728f4f11bebc43b8aa
MD5 f2e400009180fa6c0a998597b5c332f2
BLAKE2b-256 1da1efe0eb1492b38067def9f6644109165c7d35687ef2764ddb1077a6ff0e77

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