Skip to main content

Minimal OpenAI Chat Completions agent (session + tools).

Project description

pagent (English)

CI

Language: 中文 | English

Lightweight async agent core for OpenAI-compatible Chat Completions.

Core Features

  • Session: conversation message buffer (session += {...} / reset())
  • LLM: thin stateless wrapper over AsyncOpenAI
  • Providers: DeepSeek, Ollama, Vllm, Sglang
  • @tool() / FunctionTool: convert Python callables into tool schemas
  • Agent: multi-turn tool loop until no tool calls or max_turns reached
  • 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(...) reads OPENAI_API_KEY by default
  • DeepSeek(...) reads DEEPSEEK_API_KEY by 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/v1
  • Vllm: http://127.0.0.1:8000/v1
  • Sglang: 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pagent-0.1.1.tar.gz (6.8 kB view details)

Uploaded Source

Built Distribution

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

pagent-0.1.1-py3-none-any.whl (9.1 kB view details)

Uploaded Python 3

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

Hashes for pagent-0.1.1.tar.gz
Algorithm Hash digest
SHA256 29750a8faae84a878cdfee537ff1df33672a8948b153f1ce48672179dcab03eb
MD5 d55d8772b1b12e54d055934c807b1a99
BLAKE2b-256 67eb647974a2edaf48f5d662a0336a9cc104eb15c7ef6ff10747097863bf91c4

See more details on using hashes here.

Provenance

The following attestation bundles were made for pagent-0.1.1.tar.gz:

Publisher: publish.yml on SyncLionPaw/pagent

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

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

Hashes for pagent-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 0a864ae6cfcda61e7cd29d26ee6cec162fae60c428f45d99079bf29f91a116a9
MD5 fc8bd58cab45d56068fc57a94b84e1a4
BLAKE2b-256 a6c273cc6d34ef33848f45471cb8890e8384652e74f9c24cc95e4f9c8580f3f6

See more details on using hashes here.

Provenance

The following attestation bundles were made for pagent-0.1.1-py3-none-any.whl:

Publisher: publish.yml on SyncLionPaw/pagent

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