Minimal OpenAI Chat Completions agent (session + tools).
Project description
pagent (English)
Lightweight async agent core for OpenAI-compatible Chat Completions.
Core Features
Session: conversation message buffer (session += {...}/reset())LLM: thin stateless wrapper overAsyncOpenAI- Providers:
DeepSeek,Ollama,Vllm,Sglang @tool()/FunctionTool: convert Python callables into tool schemasAgent: multi-turn tool loop until no tool calls ormax_turnsreached- Built-in tools:
clock,region(locale/timezone hints, not GPS)
Install
pip install pagent
From source:
cd pagent
uv sync
pip install -e .
Quick Start
import asyncio
import os
from pagent import Agent, LLM, Session, tool
@tool()
def get_weather(city: str) -> str:
"""Return a fake weather summary for the city."""
return f"It's sunny in {city} today."
async def main() -> None:
if not os.getenv("OPENAI_API_KEY"):
raise SystemExit("Please set OPENAI_API_KEY first.")
agent = Agent(
llm=LLM("gpt-4o-mini"),
session=Session("You are a concise assistant. Use tools when needed."),
tools=[get_weather],
max_turns=8,
)
result = await agent.run("What's the weather in Xiamen?")
print(result.content)
print(agent.stats)
asyncio.run(main())
Environment Variables
LLM(...)readsOPENAI_API_KEYby defaultDeepSeek(...)readsDEEPSEEK_API_KEYby default- Local providers can use
OLLAMA_API_KEY/VLLM_API_KEY/SGLANG_API_KEY(dummy key is used when missing)
DeepSeek
- Docs: DeepSeek API Docs
base_url:https://api.deepseek.com- default model:
deepseek-v4-flash
from pagent import DeepSeek
llm = DeepSeek() # or DeepSeek("deepseek-v4-pro")
Advanced fields can be passed through request_kwargs to chat.completions.create.
Local Deployment
If your server exposes OpenAI-compatible /v1/chat/completions, it should work directly:
Ollama:http://127.0.0.1:11434/v1Vllm:http://127.0.0.1:8000/v1Sglang:http://127.0.0.1:30000/v1
from pagent import Ollama
llm = Ollama("llama3.2")
Maintainer: Publish to PyPI
Included workflow: .github/workflows/publish.yml (triggered by GitHub release publish).
Recommended: Trusted Publishing (OIDC).
Notes
This library assumes OpenAI Chat Completions compatibility. If your backend API shape differs significantly, adapt at the gateway layer or override LLM.invoke.
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 pagent-0.1.1.tar.gz.
File metadata
- Download URL: pagent-0.1.1.tar.gz
- Upload date:
- Size: 6.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
29750a8faae84a878cdfee537ff1df33672a8948b153f1ce48672179dcab03eb
|
|
| MD5 |
d55d8772b1b12e54d055934c807b1a99
|
|
| BLAKE2b-256 |
67eb647974a2edaf48f5d662a0336a9cc104eb15c7ef6ff10747097863bf91c4
|
Provenance
The following attestation bundles were made for pagent-0.1.1.tar.gz:
Publisher:
publish.yml on SyncLionPaw/pagent
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pagent-0.1.1.tar.gz -
Subject digest:
29750a8faae84a878cdfee537ff1df33672a8948b153f1ce48672179dcab03eb - Sigstore transparency entry: 1484379895
- Sigstore integration time:
-
Permalink:
SyncLionPaw/pagent@78f29ba82538a24be33d7ee11c120e814f908eed -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/SyncLionPaw
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@78f29ba82538a24be33d7ee11c120e814f908eed -
Trigger Event:
release
-
Statement type:
File details
Details for the file pagent-0.1.1-py3-none-any.whl.
File metadata
- Download URL: pagent-0.1.1-py3-none-any.whl
- Upload date:
- Size: 9.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0a864ae6cfcda61e7cd29d26ee6cec162fae60c428f45d99079bf29f91a116a9
|
|
| MD5 |
fc8bd58cab45d56068fc57a94b84e1a4
|
|
| BLAKE2b-256 |
a6c273cc6d34ef33848f45471cb8890e8384652e74f9c24cc95e4f9c8580f3f6
|
Provenance
The following attestation bundles were made for pagent-0.1.1-py3-none-any.whl:
Publisher:
publish.yml on SyncLionPaw/pagent
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pagent-0.1.1-py3-none-any.whl -
Subject digest:
0a864ae6cfcda61e7cd29d26ee6cec162fae60c428f45d99079bf29f91a116a9 - Sigstore transparency entry: 1484379927
- Sigstore integration time:
-
Permalink:
SyncLionPaw/pagent@78f29ba82538a24be33d7ee11c120e814f908eed -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/SyncLionPaw
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@78f29ba82538a24be33d7ee11c120e814f908eed -
Trigger Event:
release
-
Statement type: