Skip to main content

A lightweight Python AI agent framework

Project description

Axi-EasyAgent

中文文档 | English Documentation

A lightweight Python AI agent framework with conversation management, tool calling, and memory persistence capabilities.

How lightweight is it?

001.png

Why Axi-EasyAgent?

Do you know how much space a typical AI library takes nowadays? Up to 200MB! That's larger than a web browser!
If you only want AI to call your functions, how much of that 200MB do you actually need? The answer is right here.

Features

  • 🤖 Smart Conversations: Streaming conversation support based on OpenAI-compatible APIs
  • 🔧 Tool Calling: Automatically convert Python functions into AI-callable tools
  • 💾 Memory Management: Built-in conversation memory system with persistent storage and auto-compression
  • Async Processing: Full async programming support for improved response efficiency
  • 🔄 Streaming Output: Real-time streaming responses for enhanced user experience

Installation

pip install axi-easyagent

Quick Start

1. Environment Configuration

Configure environment variables, or hardcode them directly in your code (not recommended)

OPENAI_BASE_URL=https://dashscope.aliyuncs.com/compatible-mode/v1
OPENAI_API_KEY=your-api-key-here

Note: easyagent does not automatically read .env files. Please load them yourself.

2. Quick Start Example

import asyncio
from typing import Annotated
from easyagent import Agent

async def get_weather(city: str) -> str:
    """Get weather information"""
    return f"The weather in {city} is sunny"

def get_weather_detail(city: Annotated[str, "Can be precise to district, e.g.: Shanghai/Qingpu District"]) -> str:
    """Get detailed weather information"""
    return f"Detailed weather info for {city}: Temperature 25°C, Humidity 60%"

async def main():
    agent = Agent(
        "deepseek-v4-flash",
        tools=[get_weather, get_weather_detail],
        prompt="Keep responses brief"
    )
    
    while (msg := input("You: ")) != "q":
        async for output in agent.chat(msg):
            print(output, end="")
        print()

if __name__ == "__main__":
    asyncio.run(main())

3. Memory Persistence

import os
from easyagent import Agent, Memory

# Load existing memory or create new memory
if os.path.exists("./memory.json"):
    memory = Memory.load("./memory.json")
else:
    memory = Memory()
    memory.add_message("Hello!")  # role: user
    memory.add_message("You're bad!")  # role: assistant

agent = Agent("deepseek-v4-flash", memory=memory)

# Save memory after conversation
memory.save("./memory.json")

Core Components

Agent Class

The core agent class responsible for managing conversations, tool calls, and memory.

Parameters:

  • model (str): Model name
  • base_url (str, optional): API base URL
  • api_key (str, optional): API key
  • memory (Memory, optional): Memory instance
  • prompt (str, optional): System prompt
  • tools (list[Callable], optional): Available tools list
  • complete_memory (bool): Whether to save tool call and thinking processes to memory
  • max_tool_call (int): Maximum tool call limit

Memory Class

Conversation memory management class that inherits from list, supporting message CRUD operations and persistence. If you want to customize memory management, you can inherit from the Memory class and implement relevant methods.

Main Methods:

  • add_user_message(message): Add user message
  • add_assistant_message(message): Add assistant message
  • load(json_file): Load memory from JSON file
  • save(json_file): Save memory to JSON file
  • compress(): Compress memory by removing reasoning content and tool call records

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

axi_easyagent-0.1.0.tar.gz (6.7 kB view details)

Uploaded Source

Built Distribution

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

axi_easyagent-0.1.0-py3-none-any.whl (7.3 kB view details)

Uploaded Python 3

File details

Details for the file axi_easyagent-0.1.0.tar.gz.

File metadata

  • Download URL: axi_easyagent-0.1.0.tar.gz
  • Upload date:
  • Size: 6.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.8 {"installer":{"name":"uv","version":"0.11.8","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for axi_easyagent-0.1.0.tar.gz
Algorithm Hash digest
SHA256 5be3e9a1ad10fb9d92f461545eff48455b03e4831358a6ed7513dea18ee2831b
MD5 580d57946070e7f00ed180526819c37a
BLAKE2b-256 d0c03fba80b0275065fc66d9e78bd09c8790a7fbb9722a0b96465ea29d435d87

See more details on using hashes here.

File details

Details for the file axi_easyagent-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: axi_easyagent-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 7.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.8 {"installer":{"name":"uv","version":"0.11.8","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for axi_easyagent-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a84f37856979e51eef253c8bc7826923e82ce25ef02f7fa88a0caef8d4c83c6c
MD5 c51f94f30c5e58a93cadf8bb5001ea12
BLAKE2b-256 502d67abff19271f26edbbfe9f5466877c69b33278c1dfd37d6ec56419ffcc62

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