Skip to main content

A lightweight library for creating and running AI agents with tools, supporting OpenAI-compatible APIs

Project description

Avachain

A lightweight, efficient library for creating and running AI agents with tools. Avachain focuses on OpenAI-compatible APIs and provides a minimal interface for building powerful AI agents with tool-calling capabilities.

✨ Features

  • 🚀 Lightweight & Fast: Minimal dependencies, maximum performance
  • 🔧 Tool Integration: Easy tool creation and management
  • 💬 Conversation Memory: Intelligent context management
  • 🎯 Streaming Support: Real-time response streaming
  • 📊 Callback System: Monitor and handle agent events
  • 🎨 Colored Output: Beautiful console output with print_color
  • 🔄 Function/Tool Calling: Support for both modern and legacy function calling
  • 📝 Context Management: Advanced message trimming and context preservation
  • 🛠️ Tool Creator: Built-in tool creation and management utilities
  • 👤 Persona Creator: Agent persona creation and management system

📚 Documentation

Full documentation is available at:

👉 https://avachain.docs.pathor.in/

🏗️ Architecture Overview

Avachain follows a modular architecture designed for flexibility and extensibility:

avachain/
├── avachain.py           # Core classes: BaseTool, LLM, OpenaiLLM, CallbackHandler
├── avachain_executor.py  # Main AvaAgent orchestrator and execution engine
├── avachain_utils.py     # Utility functions for resource management
├── tool_creator.py       # Tool creation and JSON conversion utilities
└── persona_creator.py    # Agent persona management system

📦 Dependencies

Avachain keeps dependencies minimal for maximum compatibility:

  • pydantic (≥2.6.1): Data validation and settings management
  • requests (≥2.31.0): HTTP client for API calls
  • tokenizers (==0.19.1): Text tokenization utilities
  • openai (==1.63.0): OpenAI API client
  • numpy: Numerical computing support
  • print_color: Colored console output

Api Keys

To use Avachain, you need API keys for the services you want to integrate. Follow these steps to set up your API keys:

  1. Ava API Key: Sign up at AvaConsole and create an API key.

Store your API keys in a secure location and reference them in your code as needed.

Prerequisites

Ensure you have the following installed on your system:

  • Python (3.10 or higher recommended)
  • Git
  • pip (Python package installer)

🚀 Quick Start

1. Clone the Repository

git clone https://github.com/OnlinePage/Avachain.git
cd Avachain

2. Install the Package

# For basic installation
python setup.py sdist

# For development (includes linting tools):
pip install -e ".[dev]"

# For testing (includes pytest):
pip install -e ".[test]"

3. Basic Usage

from avachain.avachain_executor import AvaAgent
from avachain import OpenaiLLM, BaseTool
from pydantic import BaseModel, Field

# Initialize the LLM
llm = OpenaiLLM(
    model="gpt-4o-mini",
    api_key="your-ava-api-key", # Visit https://console.ava.pathor.in/
    base_url="https://api.ava.pathor.in/v1",
    temperature=0.7
)

class SearchArgs(BaseModel):
    query: str = Field(description="Search query")
    status: str = Field(
        description="What are you doing in first person format as status. Should be casual, personalized addressing user friendly!",
    )

# Define a custom tool
class SearchTool(BaseTool):
    name: str = "web_search"
    description: str = "Search the web for information"
    args_schema: Type[BaseModel] = SearchArgs

    def _run(self, query: str):
        # Your search implementation here
        return f"Search results for: {query}"


# Create the agent with comprehensive configuration
agent = AvaAgent(
    sys_prompt="You are a helpful assistant with web search capabilities.",
    ava_llm=llm,
    tools_list=[SearchTool()],
    logging=True,
    pickup_mes_count=10,
)

# Chat with the agent using the run method
response = agent.run("Search for Python tutorials")
print(response)

Plugin Creator Module

Advanced tool creation and management utilities.

from avachain.tool_creator import convert_tool_to_json

# Convert tool with metadata for external systems
tool_json = convert_tool_to_json(
    tool=my_tool,
    tool_id="unique_id",
    human_description="User-friendly description",
    public_name="Display Name",
    logo="path/to/logo.png",
    isAnonymous=False,
    authentication_required=True,
    tags=["search", "web", "utility"],
    supports_android=False,
    supports_windows=True
)

Persona Creator Module

Agent persona creation and management system.

from avachain import persona_creator, validate_logo_path

# Create and manage agent personas
persona_creator = PersonaCreator()

# Validate logo file
logo_path = validate_logo_path("path/to/logo.png")

# Create persona with tools and configuration
persona_data = {
    "name": "Research Assistant",
    "description": "AI assistant specialized in research tasks",
    "system_prompt": "You are a research assistant...",
    "tools": [search_tool, analysis_tool],
    "logo_path": logo_path
}

🤝 Contributing

We welcome contributions! Please see our Contributing Guide for detailed information on how to contribute to Avachain, including development setup, coding standards, and submission guidelines.

� Security Considerations

  • API Key Management: Never hardcode API keys in your code. Use environment variables or secure configuration files.
  • Tool Security: Validate all tool inputs and sanitize outputs. Be cautious with tools that execute system commands.
  • Input Validation: Always validate user inputs before processing.
  • Error Handling: Don't expose sensitive information in error messages.
import os
from avachain import OpenaiLLM, AvaAgent

# Secure API key handling
api_key = os.getenv("OPENAI_API_KEY")
if not api_key:
    raise ValueError("OPENAI_API_KEY environment variable not set")

llm = OpenaiLLM(api_key=api_key, model="gpt-3.5-turbo")

🚀 Performance Tips

  1. Context Management: Use appropriate pickup_mes_count to balance context and performance
  2. Tool Optimization: Keep tool execution time minimal
  3. Streaming: Use streaming for better perceived performance in interactive applications
  4. Caching: Implement caching in tools for frequently accessed data
  5. Async Operations: Consider async patterns for I/O heavy tools

📊 Monitoring and Logging

Built-in Logging

# Enable comprehensive logging
agent = AvaAgent(
    sys_prompt="Your system prompt",
    ava_llm=llm,
    logging=True,
    deeper_logs=True,  # More detailed logs
    agent_name_identifier="MyAgent"
)

📝 License

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

Made with ❤️ for the AI community #\x00 \x00T\x00r\x00i\x00g\x00g\x00e\x00r\x00 \x00C\x00I\x00 \x00r\x00e\x00b\x00u\x00i\x00l\x00d\x00 \x00 \x00

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

avachain-2.0.9.tar.gz (41.2 kB view details)

Uploaded Source

Built Distribution

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

avachain-2.0.9-py3-none-any.whl (31.6 kB view details)

Uploaded Python 3

File details

Details for the file avachain-2.0.9.tar.gz.

File metadata

  • Download URL: avachain-2.0.9.tar.gz
  • Upload date:
  • Size: 41.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for avachain-2.0.9.tar.gz
Algorithm Hash digest
SHA256 5dc63f1286cdf9ca3dbbc57c44e07ae0170d788dc2fe53e85f83a162f556260b
MD5 5de7b564e1bdd866002420b8ab447df4
BLAKE2b-256 0f594ab0c59a382884e2f2afa54bcb40a04edf51ac303ba2a9fd43b759c4910b

See more details on using hashes here.

Provenance

The following attestation bundles were made for avachain-2.0.9.tar.gz:

Publisher: ci.yml on OnlinePage/Avachain

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file avachain-2.0.9-py3-none-any.whl.

File metadata

  • Download URL: avachain-2.0.9-py3-none-any.whl
  • Upload date:
  • Size: 31.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for avachain-2.0.9-py3-none-any.whl
Algorithm Hash digest
SHA256 da874ef9f523d6b1320beef7fe79e7fdc13bddbb7197eea3f0343e09b73d8b38
MD5 ad8947d276ec19014727aba75dc299c3
BLAKE2b-256 1c5f4e44109d59f513d3ca5da2ad0000a1912a041be397b5267e582dddcdc057

See more details on using hashes here.

Provenance

The following attestation bundles were made for avachain-2.0.9-py3-none-any.whl:

Publisher: ci.yml on OnlinePage/Avachain

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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