Skip to main content

A lightweight async framework for structuring and running AI agents in Python

Project description

pygents

A lightweight async framework for structuring and running AI agents in Python. Define tools, queue turns, stream results.

Install

pip install pygents

Requires Python 3.12+.

Example

import asyncio
from pygents import Agent, Turn, tool

@tool()
async def greet(name: str) -> str:
    return f"Hello, {name}!"

async def main():
    agent = Agent("greeter", "Greets people", [greet])
    # Use kwargs:
    await agent.put(Turn("greet", kwargs={"name": "World"}))
    # Or positional args:
    await agent.put(Turn("greet", args=["World"]))

    async for turn, value in agent.run():
        print(value)  # "Hello, World!"

asyncio.run(main())

Tools are async functions. Turns say which tool to run and with what args. Agents process a queue of turns and stream results. The loop exits when the queue is empty.

Features

  • Streaming — agents yield (turn, value) as results are produced
  • Inter-agent messaging — agents can send turns to each other
  • Dynamic arguments — callable positional args and kwargs evaluated at runtime
  • Timeouts — per-turn, default 60s
  • Per-tool locking — opt-in serialization for shared state (lock is acquired inside the tool wrapper, so turn-level hooks run outside the tool lock)
  • Fixed kwargs — decorator kwargs (e.g. @tool(permission="admin")) are merged into every invocation; call-time kwargs override
  • Hooks@hook(hook_type, lock=..., **fixed_kwargs) decorator; hooks stored as a list and selected by type; turn, agent, tool, and memory hooks; same fixed_kwargs and lock options as tools
  • Serializationto_dict() / from_dict() for turns and agents

Docs

Full documentation: uv run mkdocs serve. MkDocs is an optional dependency—install with pip install -e ".[docs]" (or use uv run as above) so the library itself does not depend on it.

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

pygents-0.4.5.tar.gz (15.5 kB view details)

Uploaded Source

Built Distribution

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

pygents-0.4.5-py3-none-any.whl (18.6 kB view details)

Uploaded Python 3

File details

Details for the file pygents-0.4.5.tar.gz.

File metadata

  • Download URL: pygents-0.4.5.tar.gz
  • Upload date:
  • Size: 15.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.25

File hashes

Hashes for pygents-0.4.5.tar.gz
Algorithm Hash digest
SHA256 fea1d3af9b1532880dc30b9ade585bf1b53d52cdc91a0434d0e76d2623c760d8
MD5 0087b4e94adb0bc19db3c2d984c84712
BLAKE2b-256 886788c02c157c40079dcd7329f3314f4fc8925639f8fe69baff04aee622f158

See more details on using hashes here.

File details

Details for the file pygents-0.4.5-py3-none-any.whl.

File metadata

  • Download URL: pygents-0.4.5-py3-none-any.whl
  • Upload date:
  • Size: 18.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.25

File hashes

Hashes for pygents-0.4.5-py3-none-any.whl
Algorithm Hash digest
SHA256 da08948cdab660a9757d425781abbf15d4ee6cf475d63cf8afae8a1d2d7c5a67
MD5 580cd6302744b8ec8c8a4eba858f8a5c
BLAKE2b-256 c4daa38bc23fa0b865bfbc536fea3aba8963891ea2a5fc217d1b1202578606ae

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