Skip to main content

A simple LLM abstraction layer

Project description

agent1

A simple LLM abstraction layer for Python applications.

Features

  • Unified API: Single interface for multiple LLM providers (OpenAI, Anthropic, etc.)
  • Flexible Content Types: Support for text, images, audio, and file inputs
  • Message Abstraction: Unified message handling across different API types

Installation

pip install agent1

Quick Start

from agent1 import Message, Agent

# 1. Create a Message
message = Message(
    content="What is the capital of France?",
    role="user"
)

# 2. Create an Agent
agent = Agent(
    instruction="You are a helpful assistant.",
    model="gpt-4"
)

# 3. Load an Agent from config file
# agent = Agent.load("config/agent.toml")

# 4. Do work (synchronous)
response = agent.work([message])
print(response.content)

# 5. Stream responses
for chunk in agent.stream([message]):
    if hasattr(chunk, 'content'):
        print(chunk.content, end='', flush=True)

Advanced

Loading Agent from Config File

Create a config file (supports .toml, .json, .yaml, .yml):

# agent.toml
instruction = "You are a helpful assistant that specializes in Python programming."
model = "gpt-4"
temperature = 0.7

Load and use the agent:

from agent1 import Agent, Message

# Load agent from config file
agent = Agent.load("agent.toml")

message = Message(
    content="How do I create a list comprehension in Python?",
    role="user"
)

response = agent.work([message])
print(response.content)

Async Methods

For non-blocking operations, use async methods:

import asyncio
from agent1 import Agent, Message

async def main():
    agent = Agent(
        instruction="You are a helpful assistant.",
        model="gpt-4"
    )
    
    message = Message(
        content="Explain quantum computing in simple terms.",
        role="user"
    )
    
    # Async work
    response = await agent.work_async([message])
    print(response.content)
    
    # Async streaming
    async for chunk in agent.stream_async([message]):
        if hasattr(chunk, 'content'):
            print(chunk.content, end='', flush=True)

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

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

agent1-0.1.18.tar.gz (2.0 MB view details)

Uploaded Source

Built Distribution

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

agent1-0.1.18-py3-none-any.whl (9.7 kB view details)

Uploaded Python 3

File details

Details for the file agent1-0.1.18.tar.gz.

File metadata

  • Download URL: agent1-0.1.18.tar.gz
  • Upload date:
  • Size: 2.0 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.9

File hashes

Hashes for agent1-0.1.18.tar.gz
Algorithm Hash digest
SHA256 f74aa189f3b1957fee0c9ffb8708cac321256cf4d1332c0a905954903912ea45
MD5 13b1f8e69d09ca64527320b596163e54
BLAKE2b-256 3e9806dd5c348d6c2c2448890d463ba07dbfaacc099c709507ec1c78b57c4875

See more details on using hashes here.

File details

Details for the file agent1-0.1.18-py3-none-any.whl.

File metadata

  • Download URL: agent1-0.1.18-py3-none-any.whl
  • Upload date:
  • Size: 9.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.9

File hashes

Hashes for agent1-0.1.18-py3-none-any.whl
Algorithm Hash digest
SHA256 2aa0251293df46aecb4ebd407b4bdd0de8506e7020554d57fdaa978b1974ba86
MD5 640bbbe6d3c7c83ed3f1d900a6006663
BLAKE2b-256 d52ab9992f497da76a0b15eff311504f3fab74ad5c23dfd00be7f3954a98dbac

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