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
Release history Release notifications | RSS feed
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.17.tar.gz
(161.0 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
agent1-0.1.17-py3-none-any.whl
(13.4 kB
view details)
File details
Details for the file agent1-0.1.17.tar.gz.
File metadata
- Download URL: agent1-0.1.17.tar.gz
- Upload date:
- Size: 161.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7d8a4595cd92541b90bfa2dd70f737f9ad779ebc477a35391f5de8df4fa12223
|
|
| MD5 |
c4969457dd2e0fb147b75cc9c8b6cdaf
|
|
| BLAKE2b-256 |
d3c6e1f183d3dbb49bc3f19f8a536694896be6c071e3bf7f884445f29106b759
|
File details
Details for the file agent1-0.1.17-py3-none-any.whl.
File metadata
- Download URL: agent1-0.1.17-py3-none-any.whl
- Upload date:
- Size: 13.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
91fb570a909b20f0938410aff210b8d04cc00090cd8592e8800599ef66d98cb3
|
|
| MD5 |
060eb49bf512babec36155c28504c618
|
|
| BLAKE2b-256 |
ef05cee169cd99b071f318c11712544f9004f7fdc05872d8257c78a3b475715d
|