Skip to main content

A lightweight, dependency-free LLM agent framework with direct HTTP-based provider integration

Project description

nagents

PyPI version Python versions CI codecov License: MIT Docs

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 aiohttp and aiosqlite required

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.
Google 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


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.21.tar.gz (92.8 kB view details)

Uploaded Source

Built Distribution

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

nagents-0.2.21-py3-none-any.whl (79.3 kB view details)

Uploaded Python 3

File details

Details for the file nagents-0.2.21.tar.gz.

File metadata

  • Download URL: nagents-0.2.21.tar.gz
  • Upload date:
  • Size: 92.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for nagents-0.2.21.tar.gz
Algorithm Hash digest
SHA256 83305fa609fa5fc1d2a87a8c9c3a04404cb7fbcb2b7bcc312d5df0336922da94
MD5 1dae72fed90cad1b52b59d6e949ddc65
BLAKE2b-256 3550f3363d32af6826cb0d06d2a020cffb218e52a99d0d5c157c7dc22ad5b620

See more details on using hashes here.

Provenance

The following attestation bundles were made for nagents-0.2.21.tar.gz:

Publisher: ci.yml on abi-jey/nagents

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file nagents-0.2.21-py3-none-any.whl.

File metadata

  • Download URL: nagents-0.2.21-py3-none-any.whl
  • Upload date:
  • Size: 79.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for nagents-0.2.21-py3-none-any.whl
Algorithm Hash digest
SHA256 5356a63a1c0455257d9c0402daab640c9163745dce4e4f3b78bf5fddc32eca15
MD5 6e688d1d6f3a1893c724d4147888f328
BLAKE2b-256 25bcb33b67644a1ff94be33cb6a079c5b7374f50f9effb0300649c43e2f53d17

See more details on using hashes here.

Provenance

The following attestation bundles were made for nagents-0.2.21-py3-none-any.whl:

Publisher: ci.yml on abi-jey/nagents

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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