phi-agent — Python SDK
Build AI agents with Python. Write tools in Python, run on a Rust-powered agent runtime.
Quick Start
import asyncio
from phi_agent import Agent, tool
@tool
async def get_time() -> str:
"""Get the current date and time."""
from datetime import datetime
return datetime.now().strftime("%Y-%m-%d %H:%M:%S")
async def main():
agent = Agent(model="gpt-4o")
agent.register(get_time)
async for event in agent.run("What time is it?"):
match event.type:
case "thought_delta": print(f"💭 {event.text}", end="", flush=True)
case "text_delta": print(event.text, end="", flush=True)
case "tool_call_started":
print(f"\n🔧 {event.tool_name}...")
case "tool_call_finished":
print(f" → {event.summary}")
asyncio.run(main())
How It Works
The Python SDK communicates with the phi Rust binary via stdio NDJSON protocol.
The Rust runtime handles the agent loop, session management, LLM calls, and event
streaming — you only write tools in Python.
Python process Rust process
┌──────────────┐ stdio ┌──────────────────┐
│ phi_agent │◄─ NDJSON ─►│ phi serve │
│ (your tools) │ │ (agent runtime) │
└──────────────┘ └──────────────────┘
- Protocol specification: phi-agent repo
License
MIT
Release files for phi-agent 0.9.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| phi_agent-0.9.1.tar.gz | 13.2 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| phi_agent-0.9.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 26.0 kB
Release files / phi_agent-0.9.1.tar.gz
| Download URL | phi_agent-0.9.1.tar.gz |
|---|---|
| Size | 13.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ab9eee69d6d063e827a40f1c436a1b17c676e58cae49d5cf37f0f4403ae02d5d
|
|
BLAKE2b-256 checksum How to use checksums |
741d7468ce83aafac14b9536e46f28f97d51be424c7688fa03356670d5758831
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.10.17
|
Release files / phi_agent-0.9.1-py3-none-any.whl
| Download URL | phi_agent-0.9.1-py3-none-any.whl |
|---|---|
| Size | 12.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
94d92a74de8e181788b50748d3f4058357a53833d38561cf804e4a61cf29828e
|
|
BLAKE2b-256 checksum How to use checksums |
8bd6e270afee02113e9905a4f5f16a51175620f139a909f3a6c417b781968908
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.10.17
|