Skip to content

This repo provides a basic intro to learn how to use the Alith Agentic Framework

Notifications You must be signed in to change notification settings

TheVictorMunoz/Intro-to-Alith-AI-Framework

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 

Repository files navigation

Intro-to-Alith-AI-Framework

Introductory workshop to start working with the Alith AI Agent Framework. This repository is designed to help you learn how AI agents work in general, understand what makes the Alith framework unique, and explore practical code examples in Python.


Table of Contents


Overview of AI Agents

AI agents are autonomous programs that interact with data and perform tasks by processing natural language, making decisions, and even engaging with users in real time. They play a critical role in various applications such as chatbots, data analysis, and automation—especially in decentralized environments where trust and transparency are key.


What is the Alith AI Agent Framework?

The Alith AI Agent Framework is a multi-language toolkit designed for building intelligent agents. Alith lets you create AI agents (like bots, assistants, or decision-makers) that can reason, access external tools, remember things, and interact with users or blockchains while giving developers full control over logic, models, memory, and data privacy.


Why Alith?

  • Multi-Language Integration: Write and deploy AI agents using your language of choice.
  • Blockchain-Ready: Easily integrate with decentralized systems and smart contracts.
  • Optimized Performance: Benefit from asynchronous execution and native support for advanced AI models.
  • Ease of Use: Comprehensive installation instructions, quick start guides, and code examples lower the barrier to entry.
  • Extensibility: Adaptable for various use cases—from simple chatbots to complex automation systems.

Installation & Quick Start


Installing Alith (Python version)

To get started with the Alith framework using Python, first ensure you have Python 3.8+ installed.

Install the Alith SDK via pip:

pip install alith

If you’re running the example with OpenAI or another model provider, set your API key as an environment variable:

Unix/macOS

export OPENAI_API_KEY="your-api-key"

Windows (Powershell)

$env:OPENAI_API_KEY = "your-api-key"

For full details and Rust/Node.js usage, please refer to the Alith Documentation. For reference about full implementation of the telegram bot, please refer to this Repo.


Code Walkthrough

test_alith.py

This script shows how to create a simple AI agent using GPT-4 with a comedic role. It initializes the agent, sends a prompt, and prints the response.

from alith import Agent

def main():
    # Create an Agent using GPT-4 with a comedic role
    agent = Agent(
        name="Comedian Agent",
        model="gpt-4",
        preamble="You are a stand-up comedian who cracks jokes and makes people laugh."
    )

    # Prompt the agent
    user_message = "Entertain me with a short joke!"
    response = agent.prompt(user_message)

    print("AI Agent Response:", response)

if __name__ == "__main__":
    main()

Key Points:

  • Agent(...): Instantiates an AI agent with a specified name, model, and preamble.
  • prompt(...): Sends a prompt to the agent and retrieves the response.

tg-bot.py (Snippet)

This script integrates the Alith framework into a Telegram bot. The bot can handle user greetings, token balance checks, and token deployments on Metis Sepolia. Below is a simplified snippet:

import os
from telegram import Update, InlineKeyboardButton, InlineKeyboardMarkup
from telegram.ext import (
    Application,
    CommandHandler,
    MessageHandler,
    filters,
    CallbackContext,
    CallbackQueryHandler
)
from alith import Agent
from web3 import Web3

# Initialize Alith Agent
agent = Agent(
    name="Telegram Bot Agent",
    model="gpt-4",
    preamble="You are an advanced AI assistant built by Alith."
)

# Initialize Telegram Bot
bot_token = os.getenv("TELEGRAM_BOT_TOKEN")
app = Application.builder().token(bot_token).build()

async def handle_message(update: Update, context: CallbackContext) -> None:
    user_text = update.message.text
    response = agent.prompt(user_text)
    await context.bot.send_message(chat_id=update.effective_chat.id, text=response)

# Set up handlers
app.add_handler(MessageHandler(filters.TEXT & (~filters.COMMAND), handle_message))

if __name__ == "__main__":
    print("Starting Telegram Bot...")
    app.run_polling()

Key Points:

  • Demonstrates how to create a Telegram bot using the Python telegram library.
  • Integrates Alith’s Agent for AI-based responses.
  • Expands into advanced features like token deployment, balance checks, and interactive menus in the full script.

Diagrams & Visual Aids

1. Alith AI Agent Workflow

flowchart TD
    A([Start]) --> B([Initialize Alith Agent])
    B --> C([Set Model & Preamble])
    C --> D([Receive User Prompt])
    D --> E([Agent Processes Prompt])
    E --> F([Generate Response using GPT-4])
    F --> G([Return & Display Response])
Loading

2. Telegram Bot Integration Flow

flowchart TD
    A([User Sends Message]) --> B([Telegram Bot Receives Message])
    B --> C{Is it a command?}
    C --|Yes|--> D([Process /balance or Deploy Token])
    C --|No|--> E([Pass message to Alith agent])
    E --> F([Generate AI Response])
    F --> G([Telegram Bot Sends Response])
Loading

Note: this version might be updated, please follow the official documentation for latest news and versions.

About

This repo provides a basic intro to learn how to use the Alith Agentic Framework

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages