A lightweight, dependency-free LLM agent framework with direct HTTP-based provider integration
Project description
nagents
A lightweight LLM agent framework with direct HTTP-based provider integration.
Features
- Multi-Provider Support: OpenAI, Anthropic Claude, and Google Gemini APIs
- Streaming Events: Real-time text chunks, tool calls, and usage statistics
- Tool Execution: Register Python functions as tools with automatic schema generation
- Session Management: SQLite-based conversation persistence
- Batch Processing: Process multiple requests efficiently
- Minimal Dependencies: Only
aiohttpandaiosqliterequired
Installation
pip install nagents
Quick Start
import asyncio
from nagents import Agent, Provider, ProviderType
async def main():
# Create a provider
provider = Provider(
provider_type=ProviderType.OPENAI_COMPATIBLE,
api_key="your-api-key",
model="gpt-4o-mini",
)
# Create an agent
agent = Agent(provider=provider)
# Run a conversation
async for event in agent.run("Hello, how are you?"):
if hasattr(event, 'chunk'):
print(event.chunk, end="")
await agent.close()
asyncio.run(main())
Providers
nagents supports three provider types:
| Provider | Type | Models |
|---|---|---|
| OpenAI | ProviderType.OPENAI_COMPATIBLE |
gpt-4o, gpt-4o-mini, etc. |
| Anthropic | ProviderType.ANTHROPIC |
claude-3-5-sonnet, claude-3-opus, etc. |
ProviderType.GEMINI_NATIVE |
gemini-2.0-flash, gemini-1.5-pro, etc. |
With Tools
def get_weather(city: str) -> str:
"""Get the current weather for a city."""
return f"Weather in {city}: Sunny, 22°C"
agent = Agent(
provider=provider,
tools=[get_weather],
)
async for event in agent.run("What's the weather in Paris?"):
...
With Session Persistence
from pathlib import Path
from nagents import SessionManager
session_manager = SessionManager(Path("sessions.db"))
agent = Agent(
provider=provider,
session_manager=session_manager,
)
# Use a specific session ID for conversation continuity
async for event in agent.run("Remember my name is Alice", session_id="user-123"):
...
Documentation
License
MIT
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
nagents-0.1.0.tar.gz
(44.8 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
nagents-0.1.0-py3-none-any.whl
(48.4 kB
view details)
File details
Details for the file nagents-0.1.0.tar.gz.
File metadata
- Download URL: nagents-0.1.0.tar.gz
- Upload date:
- Size: 44.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.2 CPython/3.12.3 Linux/6.14.0-37-generic
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7a00921db7439d276b994be5907a6609b5624733cd22ecfed03ebf2285306502
|
|
| MD5 |
74c74ac103c22271aba153117d0401e9
|
|
| BLAKE2b-256 |
c1f27e17b71dd287016cd17c0155f11277c3d43f9df0ca43ec2252307fdb5549
|
File details
Details for the file nagents-0.1.0-py3-none-any.whl.
File metadata
- Download URL: nagents-0.1.0-py3-none-any.whl
- Upload date:
- Size: 48.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.2 CPython/3.12.3 Linux/6.14.0-37-generic
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ec970d705cf021cb256820ee5d53f2c62dd4d7400e87c81de2ce6f975f8677cd
|
|
| MD5 |
07577688d123cbee3629310bddd16d87
|
|
| BLAKE2b-256 |
5694d39631ec3f90fe0ccdeb92b169f8b8d0b47aef6adb536075061aebe4448c
|