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.base 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.base import BaseAgent

# Load the agent from the database
agent = BaseAgent.load_from_db("ChatBot")
print(f"Loaded agent: {agent.name}")

Creating and Managing Stacks

from modular_intelligence.agents.base import BaseAgent
from modular_intelligence.stacks.stack 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.save_to_db()

print("Stack created and saved!")

# Load the stack in another workspace
loaded_stack = AgentStack.load("ExampleStack")
print(f"Loaded stack: {loaded_stack.name} with agents: {[agent.name for agent in loaded_stack.agents]}")

Deploying Stacks

Deploy stacks in different workspaces by loading them from the database:

from modular_intelligence.stacks.stack 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.base import BaseAgent
from modular_intelligence.stacks.stack 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

def display_table(table_name):
    db_connection = sqlite3.connect("~/modular-intelligence/modular-intelligence.db")
    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

  • BaseAgent(name, description, prompt): Create a new AI agent.
  • .save_to_db(status="optional custom checkpoint name"): Save the agent to the database.
  • BaseAgent.load_from_db(name or id): Load an agent by name.

Stack Class

  • Stack(name, agents): Create a new stack with up to 5 agents.
  • .save_to_db(): Save the stack to the database.
  • Stack.load_from_db(name or stack_id): Load a stack by name.
  • .deploy(): Deploy the stack to another workspace.

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.5.tar.gz (26.9 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.5-py3-none-any.whl (28.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: modular_intelligence-0.0.5.tar.gz
  • Upload date:
  • Size: 26.9 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.5.tar.gz
Algorithm Hash digest
SHA256 8099a1ca1b1ea07cd9cab99b23cb98f47410ded7c450a936ce2fd208ec1d5c92
MD5 5b83d9ace65179cb3cba9bc029b03fb8
BLAKE2b-256 8f554de834b51163d6981b01df28969d76894cabd6b9fa84bcc1f8cbc42c0c7d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for modular_intelligence-0.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 16771eecd2e9a0bbf077b661be814a862928dd7bf985cde2cbc06293464f4702
MD5 f37b15d49b0c9c6c9ff4bab13276f22b
BLAKE2b-256 79afc3e5402bba801a8f6b3b909cff8f411e26fe9ab0085ad5392aadf31b226c

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