{"id":43927692,"url":"https://github.com/paulomtts/pygents","last_synced_at":"2026-03-01T01:16:13.211Z","repository":{"id":336805574,"uuid":"1151043370","full_name":"paulomtts/pygents","owner":"paulomtts","description":"A framework for building agents.","archived":false,"fork":false,"pushed_at":"2026-02-21T04:18:31.000Z","size":270,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2026-02-21T08:47:36.454Z","etag":null,"topics":["agents","ai","framework","python"],"latest_commit_sha":null,"homepage":"https://paulomtts.github.io/pygents/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/paulomtts.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-02-06T01:39:04.000Z","updated_at":"2026-02-21T04:18:36.000Z","dependencies_parsed_at":"2026-02-19T01:01:25.474Z","dependency_job_id":null,"html_url":"https://github.com/paulomtts/pygents","commit_stats":null,"previous_names":["paulomtts/pygents"],"tags_count":29,"template":false,"template_full_name":null,"purl":"pkg:github/paulomtts/pygents","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/paulomtts%2Fpygents","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/paulomtts%2Fpygents/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/paulomtts%2Fpygents/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/paulomtts%2Fpygents/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/paulomtts","download_url":"https://codeload.github.com/paulomtts/pygents/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/paulomtts%2Fpygents/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29957138,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-28T22:53:01.873Z","status":"ssl_error","status_checked_at":"2026-02-28T22:52:50.699Z","response_time":90,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["agents","ai","framework","python"],"created_at":"2026-02-06T23:11:47.054Z","updated_at":"2026-03-01T01:16:13.200Z","avatar_url":"https://github.com/paulomtts.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# pygents\n\nA lightweight async framework for structuring and running AI agents in Python. Define tools, queue turns, stream results.\n\n## Install\n\n```bash\npip install pygents\n```\n\nRequires Python 3.12+.\n\n## Example\n\n```python\nimport asyncio\nfrom pygents import Agent, Turn, tool\n\n@tool()\nasync def greet(name: str) -\u003e str:\n    return f\"Hello, {name}!\"\n\nasync def main():\n    agent = Agent(\"greeter\", \"Greets people\", [greet])\n    # Use kwargs:\n    await agent.put(Turn(\"greet\", kwargs={\"name\": \"World\"}))\n    # Or positional args:\n    await agent.put(Turn(\"greet\", args=[\"World\"]))\n\n    async for turn, value in agent.run():\n        print(value)  # \"Hello, World!\"\n\nasyncio.run(main())\n```\n\nTools 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.\n\n## Features\n\n- **Streaming** — agents yield `(turn, value)` as results are produced\n- **Inter-agent messaging** — agents can send turns to each other\n- **Dynamic arguments** — callable positional args and kwargs evaluated at runtime\n- **Timeouts** — per-turn, default 60s\n- **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)\n- **Fixed kwargs** — decorator kwargs (e.g. `@tool(permission=\"admin\")`) are merged into every invocation; call-time kwargs override\n- **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\n- **Subtools** — `@my_tool.subtool()` and `doc_tree()` for hierarchical tool docs (name, description, recursive subtools)\n- **Serialization** — `to_dict()` / `from_dict()` for turns and agents\n\n## Design Decisions\n\n**Agent/Turn hook boundary** — `TurnHook` covers events fired by the Turn itself (`BEFORE_RUN`, `AFTER_RUN`, `ON_TIMEOUT`, `ON_ERROR`, `ON_COMPLETE`). `AgentHook` covers agent-loop events (`BEFORE_TURN`, `AFTER_TURN`, `ON_TURN_VALUE`, `BEFORE_PUT`, `AFTER_PUT`, `ON_PAUSE`, `ON_RESUME`). `ON_TURN_VALUE` stays on Agent because it fires after routing (agent logic). Turn-lifecycle hooks can be registered on an agent via `agent.turn_hooks` (or the `@agent.on_error` / `@agent.on_timeout` / `@agent.on_complete` decorators) and are automatically propagated to every turn the agent runs.\n\n**Hook attachment style** — Hooks are attached via method decorators on the instance (`@agent.before_turn`, `@turn.on_complete`, `@my_tool.before_invoke`) rather than constructor parameters. This keeps the API surface explicit and enables IDE autocompletion of hook signatures.\n\n**Subtools** — Subtools are normal registered tools (in `ToolRegistry`) that are also attached to a parent for hierarchical documentation. Use `@my_tool.subtool()` to register a subtool; use `doc_tree()` on any tool to get a recursive structure of name, description, and subtools (no runtime timing). Registry keys are scoped to the parent (e.g. `manage_users.create_user`) so different parents can have subtools with the same short name; use that scoped name in turns and lookups. Agents given a root tool accept turns for that tool and all its subtools.\n\n**Tool call arguments** — Invoking a tool with extra positional or keyword arguments does not raise; only the parameters accepted by the tool function are forwarded. Missing required parameters still raise `TypeError` when the underlying function is called. This allows callers (e.g. agents or external systems) to pass a superset of arguments without errors.\n\n## Docs\n\nFull 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.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpaulomtts%2Fpygents","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpaulomtts%2Fpygents","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpaulomtts%2Fpygents/lists"}