Pygent is a PyTorch-like framework for composing stateless LLM agents from reusable Module graphs. Version 0.2 provides a single Execution owner for direct and managed calls, an asyncio Runtime, observable model/tool events, OpenAI-compatible adapters, portable tools and MCP adapters, ReAct, SQLite recovery, and HTTP/SSE workers.
Pygent 0.2 第一原则 is the repository's highest authority. Module-specific first principles, SDK contracts, tests, examples, and code derive from it.
from pygent import AIMessage, Context, Module, UserMessage
class Echo(Module[UserMessage, AIMessage]):
async def forward(self, message, context):
output = AIMessage(content=message.content.upper())
return output, context + message + output
message, context = await Echo().invoke(UserMessage(content="hello"), Context())Direct invoke(), stream(), and start() need no Runtime. Bind the same graph to LocalRuntime when the application needs bounded concurrency, cancellation, deadlines, remote placement, durable history, or advanced Execution control. Both modes execute the same forward() graph and return (message, context); see the 0.2 Execution contract.
- Layered documentation
- Execution contract
- Module, Context, Runtime
- Agent, LLM, Tool
- Executionnable service example
- Native full-path load system
uv sync --all-extras
uv run pytest -q
uv run ruff check src tests examples benchmarks
uv run mypy src benchmarks
uv build
python -m examples.service.main
uv run --extra performance python -m benchmarks run synthetic-smokePython 3.11+ is required. Apache-2.0; see LICENSE.