Skip to main content

Small OpenAI/Anthropic library to support chat templates, and function calls.

Project description

Agentlys

image image Actions status

⚠️ Warning: Since agentic capabilities are evolving fast, expect the API to change.

A lightweight Python library for building AI agents. Turn any Python function or class into AI tools. Supports OpenAI, Anthropic, async operations, and streaming conversations.

Features

  • Add functions: agent.add_function(my_function)
  • Add classes: agent.add_tool(my_class_instance)
  • MCP support
  • Multiple providers: OpenAI, Anthropic, ...
  • Async/await support
  • Image processing
  • Conversation streaming
  • Template system

Real-World Example: Code Development Agent

Agentlys excels at building development agents. Here's how agentlys-dev uses agentlys to create an AI developer:

from agentlys import Agentlys
# pip install 'agentlys-tools[all]'
from agentlys_tools.code_editor import CodeEditor
from agentlys_tools.terminal import Terminal

# Create a developer agent
agent = Agentlys(
    instruction="""You are a developer agent equipped with tools to:
    1. Edit code files
    2. Run terminal commands
    3. Test and debug applications""",
    provider="anthropic",
    model="claude-sonnet-4-20250514",
    name="Developer"
)

# Add development tools
code_editor = CodeEditor()
agent.add_tool(code_editor)

terminal = Terminal()
agent.add_tool(terminal)

# The agent can now autonomously develop, test, and deploy code
for message in agent.run_conversation("Create a FastAPI hello world app with tests"):
    print(message.to_markdown())

Installation

Install agentlys with all providers and features:

pip install 'agentlys[all]'

Or install with specific providers:

# OpenAI only
pip install 'agentlys[openai]'

# Anthropic only
pip install 'agentlys[anthropic]'

# With MCP support (Python 3.10+)
pip install 'agentlys[mcp]'

Usage

Functions

Turn regular Python functions into tools by using add_function()

  • Methods docstring, args and return type will be used to generate the tool description.
from agentlys import Agentlys

def get_weather(city: str) -> str:
    return f"Sunny in {city}"

agent = Agentlys()
agent.add_function(get_weather)
agent.ask("What's the weather in Tokyo?")

Classes (the killer feature)

Turn entire classes into tools by using add_tool()

  • Methods docstring, args and return type will be used to generate the tool description.
  • __llm__ method will be used to give AI the last state of the tool at each interaction.
import os

class FileManager:
    def __llm__(self):
        return "Files:\n" + "\n".join(os.listdir(self.directory))

    def read_file(self, path: str) -> str:
        """Read a file
        Args:
            path: Path is relative to the directory or absolute
        """
        with open(path) as f:
            return f.read()

    def write_file(self, path: str, content: str):
        with open(path, 'w') as f:
            f.write(content)

file_manager = FileManager()
agent = Agentlys()
agent.add_tool(file_manager)

# AI can now read/write files
for msg in agent.run_conversation("Read config.json and update the port to 8080"):
    print(msg.content)

Advanced Features

Image Support

from agentlys import Agentlys, Message
from PIL import Image

agent = Agentlys()
image = Image.open("examples/image.jpg")
message = Message(role="user", content="Describe this image", image=image)
response = agent.ask(message)

Template System

# Load agent from markdown template
agent = Agentlys.from_template("./agent_template.md")

Async Support

# Async operations
response = await agent.ask_async("Hello")
async for message in agent.run_conversation_async("Help me code"):
    print(message.content)

Configuration

# Set up your API keys
export OPENAI_API_KEY="your-key"
export ANTHROPIC_API_KEY="your-key"

# Choose your model (optional)
export AGENTLYS_MODEL="claude-sonnet-4-20250514"  # or gpt-5-mini

💡 Recommendation: Use Anthropic's Claude models for complex agentic behavior and tool use.

Use Cases

  • 🤖 AI Assistants: Build conversational assistants with tool access
  • 🛠️ Development Agents: Create agents that can code, test, and deploy (like agentlys-dev)
  • 📊 Data Analysis: Agents that can query databases, generate reports, visualize data
  • 🌐 Web Automation: Agents that interact with web APIs and services
  • 📋 Task Automation: Automate complex workflows with AI decision-making
  • 🎯 Custom Tools: Integrate your existing Python tools with AI

Documentation

Support

If you encounter any issues or have questions, please file an issue on the GitHub project page.

License

This project is licensed under the terms of the MIT license.

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

agentlys-0.20.0.tar.gz (31.4 kB view details)

Uploaded Source

Built Distribution

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

agentlys-0.20.0-py3-none-any.whl (27.9 kB view details)

Uploaded Python 3

File details

Details for the file agentlys-0.20.0.tar.gz.

File metadata

  • Download URL: agentlys-0.20.0.tar.gz
  • Upload date:
  • Size: 31.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.13

File hashes

Hashes for agentlys-0.20.0.tar.gz
Algorithm Hash digest
SHA256 7b99794e0263b8cc936d224d2fd85e33ae2d5952809da682601fb6cf50d7bff7
MD5 ab5b087273469f8bdf342796562e698a
BLAKE2b-256 9bccf33d77d0e9f1b11d1370879208b8f2fd37da20b2d6c8fc23bf08e52053e4

See more details on using hashes here.

File details

Details for the file agentlys-0.20.0-py3-none-any.whl.

File metadata

  • Download URL: agentlys-0.20.0-py3-none-any.whl
  • Upload date:
  • Size: 27.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.13

File hashes

Hashes for agentlys-0.20.0-py3-none-any.whl
Algorithm Hash digest
SHA256 32de3c3db095040d488c2d40815c2d1b0b09a00d6738f74434c4b76b37abc710
MD5 5a579a2bf2268309dbca0065eff77bc4
BLAKE2b-256 259eebcff9d7a9e1daab65ae03de2f1c3845c2e1c2144df6344017bbf862c586

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