Skip to main content

Python tools for building AI agents and managing LLM deployments

Project description

pi-agent

Python tools for building AI agents and managing LLM deployments.

This repository is an open-source Python reimplementation of core ideas from Pi (JS/TS), starting with a provider-agnostic agent runtime that is composable and SDK-friendly.

Status

Phase 1 and an initial Phase 2 slice are implemented:

  • Core typed domain model for messages, content blocks, tools, usage, model config
  • Async event stream primitive with terminal-result handling
  • Agent loop runtime with turn/tool orchestration and steering/follow-up queues
  • Stateful Agent wrapper with prompt/continue/abort/wait APIs
  • Provider abstraction (pi_ai) with registry + runtime adapter
  • Providers:
    • mock provider
    • OpenAI Responses provider (with streaming deltas)
    • OpenAI Completions-compatible provider (with streaming deltas)
  • Strict checks and tests (ruff, mypy, pytest)

Roadmap details are tracked in PLAN.md.

Requirements

  • Python >=3.11
  • uv

Install

pip install pi-agent
from pi_agent.agent_core import Agent, Model

Development

uv sync
uv run ruff check .
uv run mypy src tests
uv run pytest -q

Package layout

src/pi_agent/agent_core/
  types.py         # domain model + event types + runtime protocols
  event_stream.py  # generic async stream + assistant stream specialization
  agent_loop.py    # turn execution + tool execution loop
  agent.py         # high-level agent state wrapper

src/pi_agent/pi_ai/
  types.py         # provider request + provider protocol
  registry.py      # provider registry + defaults
  runtime.py       # stream/complete APIs + Agent adapter
  providers/mock.py
  providers/openai.py
  providers/openai_completions.py

End-to-end example

Run:

uv sync --extra openai
export OPENAI_API_KEY=your_key_here
uv run python examples/agent_e2e.py

This example uses OpenAI (gpt-5-mini), routes calls through pi_ai, invokes a tool, and prints the final assistant response.

Streaming example (OpenAI)

Run:

uv sync --extra openai
export OPENAI_API_KEY=your_key_here
uv run python examples/openai_streaming.py

This example prints streaming delta events (text_delta, and tool-call events when present) from the OpenAI provider.

Build and publish

uv build
uvx twine check dist/*
uv publish

Releases

Tag-based releases use .github/workflows/release.yml and expect:

  • pyproject.toml version matches the tag (vX.Y.Z).
  • A matching CHANGELOG.md section exists (## [X.Y.Z] - YYYY-MM-DD).

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

pi_agent-0.1.0.tar.gz (24.3 kB view details)

Uploaded Source

Built Distribution

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

pi_agent-0.1.0-py3-none-any.whl (31.4 kB view details)

Uploaded Python 3

File details

Details for the file pi_agent-0.1.0.tar.gz.

File metadata

  • Download URL: pi_agent-0.1.0.tar.gz
  • Upload date:
  • Size: 24.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.0 {"installer":{"name":"uv","version":"0.10.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for pi_agent-0.1.0.tar.gz
Algorithm Hash digest
SHA256 7d12ca4e3d95c6eeb9e3e18ec4ae0c6b015e4c104254a198b2c7248322ba48d1
MD5 bf78ae01d0d8a612e3dc2d92a3af7b37
BLAKE2b-256 afb4afac3e838ffa160bacddaba4cdc544ace2148efff0e3f3ee2509c708836f

See more details on using hashes here.

File details

Details for the file pi_agent-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: pi_agent-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 31.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.0 {"installer":{"name":"uv","version":"0.10.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for pi_agent-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 76178ad95c729f574100abadce7b08ce15fd1209df170c55e495eb0f4826aae5
MD5 f42d5529d9e0b95c7b7cf2c4ceafe757
BLAKE2b-256 5ebfd6c4871cd360b71007f00a0cf26bbf2d8330a8e5acb2bf6cc25c643f5ec7

See more details on using hashes here.

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