Skip to main content

General-purpose Python agent framework with pystator integration

Project description

PyGubernator

General-purpose Python agent framework with pystator integration: lifecycle state machines, LLM agents with tools, pipelines, Kafka/in-memory transport, and batch/stream runners.

Install

pip install pygubernator

Optional extras:

pip install pygubernator[llm]      # LiteLLM provider
pip install pygubernator[kafka]    # Kafka transport
pip install pygubernator[charter]   # pycharter
pip install pygubernator[catalyst]  # pycatalyst
pip install pygubernator[all]

Quick start

from pygubernator import Message, InMemoryTransport, run_stream
from pygubernator.agents import PipelineAgent
# … define agents and run run_stream / run_batch with a transport

Optional control-plane layers

pygubernator remains stateless at its core. Optional layers can be installed as extras:

pip install "pygubernator[api,db,postgres,ui]"
  • API layer: FastAPI control plane (pygubernator api, optional --host / --port / --no-reload)
  • Persistence layer: SQLAlchemy models + migrations under src/pygubernator/db/
  • UI layer: Next.js control plane (pygubernator ui dev|serve|build, same flags as pycharter/pystator: --api-url, --host/--port for serve, --api-url/--port for dev)

Main control-plane routes:

  • /api/v1/agents (registry + versions + activation)
  • /api/v1/runs (list/detail/control/replay, create runs via POST)
  • /api/v1/observability (events/metrics/traces)
  • /api/v1/policies (policy assignments/alerts/audit)

Registry-Driven Agents

PyGubernator supports a turnkey workflow where agents registered in the API can be instantiated and executed with automatic observability:

from pygubernator.spec import create_llm_agent_from_version
from pygubernator.runners import run_batch_with_db
from pygubernator.llm._provider import LiteLLMProvider
from pygubernator.db.session import SessionLocal
from pygubernator.db.models import AgentVersion

# Load version from database
db = SessionLocal()
version = db.get(AgentVersion, version_id)

# Create agent from stored metadata
agent = create_llm_agent_from_version(
    version=version,
    llm_provider_factory=lambda m: LiteLLMProvider(model=m or "gpt-4o-mini")
)

# Execute with automatic run lifecycle and event persistence
result = await run_batch_with_db(
    agent=agent,
    transport=transport,
    topic="input",
    db_session_factory=SessionLocal,
    agent_id=version.agent_id,
    agent_version_id=version.id
)

Key features:

  • Spec / assembly (pygubernator.spec): Build agents from version-like records (create_llm_agent_from_version)
  • Automatic run_id threading: Events automatically correlated to runs
  • Convenience helpers: run_stream_with_db / run_batch_with_db manage run lifecycle
  • HTTP client: ControlPlaneClient for API operations (optional)
  • Tool loading: Tools loaded from version metadata

See Integration Guide and Run Lifecycle for details.

Configuration

Settings can be loaded from environment variables with the prefix PYGUBERNATOR_, for example:

  • PYGUBERNATOR_AGENT_ID
  • PYGUBERNATOR_LLM_MODEL
  • PYGUBERNATOR_KAFKA_BOOTSTRAP_SERVERS
  • PYGUBERNATOR_KAFKA_GROUP_ID (default consumer group name: pygubernator)

Use AgentSettings.from_env() to populate AgentSettings.

For control-plane services, pygubernator also supports a pygubernator.cfg file (same style as pycharter/pystator). Resolution order:

  1. environment variables
  2. ./pygubernator.cfg
  3. ~/.pygubernator/pygubernator.cfg
  4. project root config (near alembic.ini)

See pygubernator.cfg.example for:

  • PYGUBERNATOR_DATABASE_URL
  • PYGUBERNATOR_UI_THEME / PYGUBERNATOR_UI_APP_NAME
  • PYGUBERNATOR_AUTH_USERS / PYGUBERNATOR_AUTH_JWT_SECRET

Authentication bootstrap:

  • Configure initial users in PYGUBERNATOR_AUTH_USERS (env or pygubernator.cfg).
  • Set PYGUBERNATOR_AUTH_JWT_SECRET (env or pygubernator.cfg) before using /api/v1/auth/login.
  • Use Authorization: Bearer <token> for protected API routes (X-API-Token is not supported).

Development

make install-dev
make check

Git: ignored files must not be committed

.gitignore only affects untracked files. If something was committed before it was ignored (or was added with git add -f), Git keeps tracking it until you remove it from the index:

make git-untrack-ignored
# or: ./scripts/git-untrack-ignored.sh
git status   # expect many "deleted" (index-only) paths — working tree unchanged
git commit -m "chore: stop tracking gitignored build/local files"

After that, git add and git commit will not re-add those paths. Keep using pygubernator.cfg.example in the repo; copy to pygubernator.cfg locally (ignored).

Contributing and security

Publishing

Version is managed with setuptools-scm. Prefer GitHub tag pushes (e.g. v0.1.0) and Trusted Publishing to PyPI; see .github/workflows/publish.yml and the Makefile publish / publish-test targets.

Rename note

This package was previously developed as pykairos. The PyPI distribution and import package are now pygubernator. Replace imports (import pygubernator), pip install pygubernator, and migrate environment variables from PYKAIROS_* to PYGUBERNATOR_*. The base exception type is GubernatorError (formerly KairosError).

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

pygubernator-0.0.5.tar.gz (385.0 kB view details)

Uploaded Source

Built Distribution

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

pygubernator-0.0.5-py3-none-any.whl (418.6 kB view details)

Uploaded Python 3

File details

Details for the file pygubernator-0.0.5.tar.gz.

File metadata

  • Download URL: pygubernator-0.0.5.tar.gz
  • Upload date:
  • Size: 385.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pygubernator-0.0.5.tar.gz
Algorithm Hash digest
SHA256 8f6331bbb338149ca206d9308162197f13b355c5a0c2d9e80c209dd26c07f909
MD5 348971f829124486a8b14d057571a86b
BLAKE2b-256 63eb698566eb9a2e0bc2acd05ca3b6338725e69199526fcba5951053645c6bef

See more details on using hashes here.

Provenance

The following attestation bundles were made for pygubernator-0.0.5.tar.gz:

Publisher: publish.yml on optophi/pygubernator

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

File details

Details for the file pygubernator-0.0.5-py3-none-any.whl.

File metadata

  • Download URL: pygubernator-0.0.5-py3-none-any.whl
  • Upload date:
  • Size: 418.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pygubernator-0.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 e4184870a4cd839a0e5d0e59979a9658e9fa2bb8264b031bae5a37f6d58199a0
MD5 d21b45b7970374fbb3cfb30a83f229e4
BLAKE2b-256 0eb2d8bd86ab35138a0edd80c9256750911d20db426e52fbd1a7d0e7bf9f629b

See more details on using hashes here.

Provenance

The following attestation bundles were made for pygubernator-0.0.5-py3-none-any.whl:

Publisher: publish.yml on optophi/pygubernator

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