A reusable agentic chat library with tool-calling loop, multi-provider LLM support, and MCP integration.
Project description
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
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
chatloop-0.1.0.tar.gz
(25.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
chatloop-0.1.0-py3-none-any.whl
(22.7 kB
view details)
File details
Details for the file chatloop-0.1.0.tar.gz.
File metadata
- Download URL: chatloop-0.1.0.tar.gz
- Upload date:
- Size: 25.5 kB
- Tags: Source
- Uploaded using 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}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
111b74ffeec80359a23007a5c6243e5f4f680002bc5483b5a9df5c20405a04c4
|
|
| MD5 |
1862483d3b1e9f56e644fc6e596d4364
|
|
| BLAKE2b-256 |
150f5806c9c8048e85ded8460ec924ded6cb26973e8dabc581dfdf319cfccc1d
|
File details
Details for the file chatloop-0.1.0-py3-none-any.whl.
File metadata
- Download URL: chatloop-0.1.0-py3-none-any.whl
- Upload date:
- Size: 22.7 kB
- Tags: Python 3
- Uploaded using 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}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f17ba0a5a4423d91a79bacf6e512a736722aa13af475b89a41b458f702e68d86
|
|
| MD5 |
52c000a5fd6df8c4a54c164a9fcb8246
|
|
| BLAKE2b-256 |
b62905a5950fbd19c798e319f6ddd8480118e1662a7bb27539d65c30b95d0f1c
|