Skip to main content

Async AI Agent Framework

Project description

GRAMI AI: The Modern Async AI Agent Framework

Documentation Status PyPI version License: MIT

๐Ÿค– GRAMI AI Framework

Python 3.8+ License Code style: black

GRAMI AI is an open-source, async-first Python framework for building intelligent, modular AI agents. It provides a robust foundation for creating, managing, and orchestrating AI agents with a focus on flexibility, performance, and extensibility.

๐ŸŒŸ Features

  • Async-First Architecture: Built from the ground up for high-performance async operations
  • Modular Design: Easily extend and customize components
  • Multi-Provider Support: Works with OpenAI, Anthropic, Cohere, and more
  • Robust Memory Management: Multiple backend options (Redis, PostgreSQL, MongoDB)
  • Event-Driven: Real-time updates and communication between agents
  • Type-Safe: Comprehensive type hints for better IDE support
  • Production-Ready: Built-in monitoring, logging, and error handling

๐Ÿ—๏ธ Architecture

                                GRAMI AI Architecture
                                
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                           Client Applications                        โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                                    โ”‚
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                              API Layer                              โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                                    โ”‚
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                           Agent Orchestrator                         โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚  Agent 1    โ”‚   Agent 2   โ”‚   Agent 3   โ”‚   Agent 4   โ”‚  Agent N   โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”˜
      โ”‚              โ”‚              โ”‚             โ”‚            โ”‚
โ”Œโ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚   Memory   โ”‚   Events    โ”‚    Tools    โ”‚  Providers โ”‚  Security  โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

๐Ÿš€ Quick Start

  1. Install GRAMI AI:
pip install grami-ai
  1. Create your first agent:
from grami_ai import BaseAgent, Tool, Memory
from grami_ai.core.config import settings

class MyAgent(BaseAgent):
    async def initialize(self):
        # Set up agent-specific configuration
        self.memory = Memory(backend=settings.memory.backend)
        self.tools = [Tool1(), Tool2()]
    
    async def execute_task(self, task):
        # Implement task execution logic
        result = await self.process_task(task)
        await self.memory.store(result)
        return result

# Create and run agent
agent = MyAgent()
await agent.start()
  1. Assign tasks to your agent:
from grami_ai.core.constants import Priority

# Create a task
task = {
    "objective": "Analyze this text document",
    "input": "Sample text for analysis",
    "priority": Priority.HIGH
}

# Assign and execute task
result = await agent.execute_task(task)

๐Ÿ“ฆ Core Components

1. Agents

  • Base agent class with common functionality
  • Customizable behavior and capabilities
  • Built-in task queue and priority handling

2. Memory

  • Multiple backend support (Redis, PostgreSQL, MongoDB)
  • Automatic data serialization/deserialization
  • Configurable retention and indexing

3. Events

  • Real-time communication between agents
  • Kafka-based event streaming
  • Event filtering and routing

4. Tools

  • Extensible tool interface
  • Built-in common tools
  • Custom tool development support

5. Configuration

  • Environment-specific settings
  • Secure secrets management
  • Dynamic configuration updates

๐Ÿ”ง Development

  1. Clone the repository:
git clone https://github.com/yourusername/grami-ai.git
cd grami-ai
  1. Create a virtual environment:
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate
  1. Install development dependencies:
pip install -e ".[dev]"
  1. Run tests:
pytest tests/

๐Ÿ“– Documentation

Full documentation is available at docs.grami-ai.org

๐Ÿค Contributing

We welcome contributions! Please see our Contributing Guide for details.

๐Ÿ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

๐Ÿ™ Acknowledgments

  • The amazing open-source community
  • All our contributors and users

Vision

Grami AI is designed to revolutionize how developers build AI agents by providing a modern, async-first framework that emphasizes:

  • Asynchronous by Default: Built from the ground up for high-performance, non-blocking operations
  • Modular Architecture: Plug-and-play components for tools, memory, and LLM providers
  • Type Safety: Comprehensive type hints and protocol-based interfaces
  • Production Ready: Built for reliability and scalability in real-world applications

Quick Start

# Install the base package
pip install grami-ai

# Install with optional features
pip install grami-ai[gemini]    # For Google Gemini support
pip install grami-ai[ollama]    # For Ollama support
pip install grami-ai[dev]       # For development tools

Basic Usage

from grami_ai.agent import AsyncAgent
from grami_ai.tools import CalculatorTool, WebScraperTool
from grami_ai.memory import InMemoryAbstractMemory

async def main():
    # Initialize agent with tools and memory
    agent = AsyncAgent(
        tools=[CalculatorTool(), WebScraperTool()],
        memory=InMemoryAbstractMemory(),
        model="gemini-pro"  # or "gpt-3.5-turbo", "ollama/llama2", etc.
    )
    
    # Execute tasks asynchronously
    result = await agent.execute(
        "Calculate the square root of the number of words on example.com"
    )
    print(result)

# Run the async function
import asyncio
asyncio.run(main())

Architecture

Grami AI is built on three core pillars:

1. Tools System

  • Protocol-based tool definition
  • Async execution
  • Built-in validation and error handling
  • Extensive tool library (web scraping, calculations, file operations, etc.)
from grami_ai.core.interfaces import AsyncTool
from typing import Any, Dict

class MyCustomTool(AsyncTool):
    async def run(self, input_data: str, **kwargs) -> Dict[str, Any]:
        # Your async tool implementation
        return {"result": processed_data}

2. Memory Management

  • Flexible memory backends (In-Memory, Redis, Custom)
  • Automatic context management
  • Memory size limits and pruning strategies
from grami_ai.memory import RedisMemory

memory = RedisMemory(
    redis_url="redis://localhost:6379",
    max_items=1000,
    ttl=3600  # 1 hour
)

3. LLM Integration

  • Support for multiple LLM providers
  • Streaming responses
  • Token management
  • Retry mechanisms
from grami_ai.llm import GeminiProvider

llm = GeminiProvider(
    api_key="your-api-key",
    model="gemini-pro",
    max_tokens=1000
)

Advanced Features

Parallel Tool Execution

async def parallel_execution():
    tools = [WebScraperTool(), CalculatorTool(), StringTool()]
    results = await asyncio.gather(*[
        tool.execute(input_data) 
        for tool in tools
    ])

Custom Memory Backend

from grami_ai.core.interfaces import AsyncMemoryProvider

class MyCustomMemory(AsyncMemoryProvider):
    async def add_item(self, key: str, value: dict) -> None:
        # Implementation
        pass

    async def get_items(self, key: str) -> list:
        # Implementation
        pass

Error Handling

from grami_ai.exceptions import ToolExecutionError

try:
    result = await agent.execute("complex task")
except ToolExecutionError as e:
    print(f"Tool execution failed: {e}")

Documentation

Comprehensive documentation is available at grami-ai.readthedocs.io, including:

  • Getting Started Guide
  • API Reference
  • Advanced Usage Examples
  • Contributing Guidelines

Contributing

We welcome contributions! Here's how you can help:

  1. Fork the repository
  2. Create a feature branch
  3. Write your changes
  4. Write tests for your changes
  5. Submit a pull request
# Development setup
git clone https://github.com/grami-ai/framework.git
cd framework
pip install -e .[dev]
pytest

License

MIT License

Copyright (c) 2024 YAFATEK Solutions

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Links

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

grami_ai-0.2.2.tar.gz (40.9 kB view details)

Uploaded Source

Built Distribution

grami_ai-0.2.2-py3-none-any.whl (40.8 kB view details)

Uploaded Python 3

File details

Details for the file grami_ai-0.2.2.tar.gz.

File metadata

  • Download URL: grami_ai-0.2.2.tar.gz
  • Upload date:
  • Size: 40.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for grami_ai-0.2.2.tar.gz
Algorithm Hash digest
SHA256 ac26397a141223056c447424abb041bcfdd1ff053225979ac3ce2027ee4babe1
MD5 2b48a5051251926abac8fa8bfdcb8e26
BLAKE2b-256 5e415631b154d7648260a15d850ed00b74b6fdad20481497f8d5d4a25ffec681

See more details on using hashes here.

File details

Details for the file grami_ai-0.2.2-py3-none-any.whl.

File metadata

  • Download URL: grami_ai-0.2.2-py3-none-any.whl
  • Upload date:
  • Size: 40.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for grami_ai-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 bd14d03bb402fd25c97a3d924ee5aab207a0b5d28fbb8f1a96dd44f9c3c3ff0e
MD5 821dce56b2784bbf3c6c21abb4f28bf2
BLAKE2b-256 cd16858278b0f951d3e4661e08f986a29aa696fa29bdd926532c70b0cd16c60b

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page