Skip to main content

Async agent orchestration for Python

Project description

pygents

Async agent orchestration for 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
  • Fixed kwargs — decorator kwargs (e.g. @tool(permission="admin")) are merged into every invocation; call-time kwargs override
  • Hooks — async callbacks at turn, agent, and tool level
  • Serializationto_dict() / from_dict() for turns and agents

Design decisions

  • Turn identity: Turn instances no longer have a built-in uuid. If you need identifiers, store them yourself in metadata or wrap Turn in a higher-level domain object.

  • Turn arguments: Turn.__init__ takes args before kwargs, and metadata is the final parameter:

    Turn(
        "tool_name",
        args=[...],
        kwargs={...},
        timeout=...,
        start_time=...,
        end_time=...,
        stop_reason=...,
        metadata={...},
    )
    

    This keeps positional arguments explicit while reserving metadata purely for user-level annotations.

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.2.1.tar.gz (12.4 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.2.1-py3-none-any.whl (14.4 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for pygents-0.2.1.tar.gz
Algorithm Hash digest
SHA256 f5658a6e165804ae21ba001ca8962af9ee4841ed232876c94a934fd36b76f7b7
MD5 3a3d2e567cbcb13c0f4a67b0f4053df0
BLAKE2b-256 ff8105b6622f16e02f4e3c2b4622076103f09407a063d9313eb69ec5efba3c45

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pygents-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 14.4 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.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b2408b67a687f9d07cee9837bb627cea15e2a7a6e21ebae25d465c5e6a43ab50
MD5 de5330a7a9d9d6a5412c2ef422ae0eb3
BLAKE2b-256 a6a20cd9a4a02f8f3cd2f84aecfa6fbbd28ae463130282166a9494ebad992ddb

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