A lightweight AI Agent framework
Project description
ThinAgents
A lightweight, pluggable AI Agent framework for Python.
Build LLM-powered agents that can use tools, remember conversations, and connect to external resources with minimal code. ThinAgents leverages litellm under the hood for its language model interactions.
Installation
pip install thinagents
Basic Usage
Create an agent and interact with an LLM in just a few lines:
from thinagents import Agent
agent = Agent(
name="Greeting Agent",
model="openai/gpt-4o-mini",
)
response = await agent.arun("Hello, how are you?")
print(response.content)
Tools
Agents can use Python functions as tools to perform actions or fetch data.
from thinagents import Agent
def get_weather(city: str) -> str:
return f"The weather in {city} is sunny."
agent = Agent(
name="Weather Agent",
model="openai/gpt-4o-mini",
tools=[get_weather],
)
response = await agent.arun("What is the weather in Tokyo?")
print(response.content)
Tools with Decorator
For richer metadata and parameter validation, use the @tool decorator:
from thinagents import Agent, tool
@tool(name="get_weather")
def get_weather(city: str) -> str:
"""Get the weather for a city."""
return f"The weather in {city} is sunny."
agent = Agent(
name="Weather Pro",
model="openai/gpt-4o-mini",
tools=[get_weather],
)
You can also use Pydantic models for parameter schemas:
from pydantic import BaseModel, Field
from thinagents import tool
class MultiplyInputSchema(BaseModel):
a: int = Field(description="First operand")
b: int = Field(description="Second operand")
@tool(name="multiply_tool", pydantic_schema=MultiplyInputSchema)
def multiply(a: int, b: int) -> int:
return a * b
Returning Content and Artifact
Sometimes, a tool should return both a summary (for the LLM) and a large artifact (for downstream use):
from thinagents import tool
@tool(return_type="content_and_artifact")
def summarize_and_return_data(query: str) -> tuple[str, dict]:
data = {"rows": list(range(10000))}
summary = f"Found {len(data['rows'])} rows for query: {query}"
return summary, data
response = await agent.arun("Summarize the data for X")
print(response.content) # Sent to LLM
print(response.artifact) # Available for downstream use
Async Usage
ThinAgents is async by design. You can stream responses or await the full result:
# Streaming
async for chunk in agent.astream("List files and get weather", conversation_id="1"):
print(chunk.content, end="", flush=True)
# Or get the full response at once (non-streaming)
response = await agent.arun("List files and get weather", conversation_id="1")
print(response.content)
Memory
Agents can remember previous messages and tool results by attaching a memory backend.
from thinagents.memory import InMemoryStore
agent = Agent(
name="Memory Demo",
model="openai/gpt-4o-mini",
memory=InMemoryStore(), # Fast, in-memory storage
)
conv_id = "demo-1"
print(await agent.arun("Hi, I'm Alice!", conversation_id=conv_id))
print(await agent.arun("What is my name?", conversation_id=conv_id))
# → "Your name is Alice."
Persistent Memory
from thinagents.memory import FileMemory, SQLiteMemory
file_agent = Agent(
name="File Mem Agent",
model="openai/gpt-4o-mini",
memory=FileMemory(storage_dir="./agent_mem"),
)
db_agent = Agent(
name="SQLite Mem Agent",
model="openai/gpt-4o-mini",
memory=SQLiteMemory(db_path="./agent_mem.db"),
)
Storing Tool Artifacts
Enable artifact storage in memory:
agent = Agent(
...,
memory=InMemoryStore(store_tool_artifacts=True),
)
Model Context Protocol (MCP) Integration
Connect your agent to external resources (files, APIs, etc.) using MCP.
agent = Agent(
name="MCP Agent",
model="openai/gpt-4o-mini",
mcp_servers=[
{
"transport": "sse",
"url": "http://localhost:8100/sse"
},
{
"transport": "stdio",
"command": "npx",
"args": [
"-y",
"@modelcontextprotocol/server-filesystem",
"/path/to/dir"
]
},
],
)
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
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
File details
Details for the file thinagents-0.0.21.tar.gz.
File metadata
- Download URL: thinagents-0.0.21.tar.gz
- Upload date:
- Size: 3.6 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f457d3f73e908202660c1ce827d2906eddfbdd20bbee2eb1b02cccf6c10e1697
|
|
| MD5 |
0e787c96db34d0e231ea8b7af769cd62
|
|
| BLAKE2b-256 |
d715488e76e620b01713326e2337964ab0ce131055ba273c279097c729c6b35a
|
File details
Details for the file thinagents-0.0.21-py3-none-any.whl.
File metadata
- Download URL: thinagents-0.0.21-py3-none-any.whl
- Upload date:
- Size: 3.8 MB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b4e5d3aa2b5562d63b0a187b2f3d4c223e5a77593149880dfd95feb9c0c4ddbe
|
|
| MD5 |
16b230f80a34787cabcc333e76b1bc0f
|
|
| BLAKE2b-256 |
30fa24cd2cc07712c5a6f2ac370613784fe9140869ca1532654405165c3da09e
|