Skip to main content

chatloop

A reusable agentic chat library with tool-calling loop, multi-provider LLM support, and MCP integration.

Install

pip install chatloop[openai]          # OpenAI provider
pip install chatloop[anthropic]       # Anthropic provider
pip install chatloop[google]          # Google Generative AI provider
pip install chatloop[all]             # All providers + MCP
pip install chatloop[fastapi]         # FastAPI integration

Quick Start

import asyncio
from chatloop import ChatLoop, tool

@tool(description="Add two numbers")
async def add(context, a: int, b: int):
    return {"result": a + b}, None

async def main():
    loop = ChatLoop(
        provider="openai",
        model="gpt-4o",
        api_key="sk-...",
        tools=[add],
    )
    response = await loop.ask("What is 2 + 3?")
    print(response.answer)

asyncio.run(main())

Multi-Provider

# OpenAI
loop = ChatLoop(provider="openai", model="gpt-4o", api_key="...")

# Anthropic
loop = ChatLoop(provider="anthropic", model="claude-sonnet-4-5-20250514", api_key="...")

# Google
loop = ChatLoop(provider="google", model="gemini-2.0-flash", api_key="...")

MCP Servers

from chatloop import ChatLoop
from chatloop.mcp import MCPServer

postgres = MCPServer(
    command="npx", args=["-y", "@modelcontextprotocol/server-postgres", DB_URL],
    name="postgres",
)

async with ChatLoop(
    provider="openai", model="gpt-4o", api_key="...",
    mcp_servers=[postgres],
) as loop:
    response = await loop.ask("What tables exist in the database?")

FastAPI Integration

from fastapi import FastAPI
from chatloop import ChatLoop
from chatloop.integrations.fastapi import create_router

app = FastAPI()
loop = ChatLoop(provider="openai", model="gpt-4o", api_key="...", tools=[...])
app.include_router(create_router(loop=loop, prefix="/chat"))

License

MIT

Metadata

Release files for chatloop 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for chatloop 0.1.0
File Size Uploaded
chatloop-0.1.0.tar.gz 25.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for chatloop 0.1.0
File Interpreter ABI Platform
chatloop-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 48.2 kB

Release files / chatloop-0.1.0.tar.gz

Download URL chatloop-0.1.0.tar.gz
Size 25.5 kB
Tags Source
SHA-256 checksum
How to use checksums
111b74ffeec80359a23007a5c6243e5f4f680002bc5483b5a9df5c20405a04c4
BLAKE2b-256 checksum
How to use checksums
150f5806c9c8048e85ded8460ec924ded6cb26973e8dabc581dfdf319cfccc1d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.9.26 {"installer":{"name":"uv","version":"0.9.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / chatloop-0.1.0-py3-none-any.whl

Download URL chatloop-0.1.0-py3-none-any.whl
Size 22.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f17ba0a5a4423d91a79bacf6e512a736722aa13af475b89a41b458f702e68d86
BLAKE2b-256 checksum
How to use checksums
b62905a5950fbd19c798e319f6ddd8480118e1662a7bb27539d65c30b95d0f1c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.9.26 {"installer":{"name":"uv","version":"0.9.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page