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.2.22.tar.gz
(94.5 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.2.22-py3-none-any.whl
(81.3 kB
view details)
File details
Details for the file nagents-0.2.22.tar.gz.
File metadata
- Download URL: nagents-0.2.22.tar.gz
- Upload date:
- Size: 94.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.3.2 CPython/3.12.3 Linux/6.17.0-19-generic
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ae95b657908732239208786fcb9a106de2807bcb096d34f0a07daab328d87fbc
|
|
| MD5 |
99a9f723feb1c4c545d7a071182ec088
|
|
| BLAKE2b-256 |
7563897b162d123ee9c9eb9e6f5d91384b18ca85072627794510e86e0a9fb670
|
File details
Details for the file nagents-0.2.22-py3-none-any.whl.
File metadata
- Download URL: nagents-0.2.22-py3-none-any.whl
- Upload date:
- Size: 81.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.3.2 CPython/3.12.3 Linux/6.17.0-19-generic
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
359829e33f61a3381f21fd7ca29b7f504f81dbb24ced988b07848a160796f31d
|
|
| MD5 |
1f4489cb30fd140d3d2e5cde2653c951
|
|
| BLAKE2b-256 |
abb67c39123224acb2488a70e069b47726e020eb36fc5037af845c0da3fc05d3
|