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
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
phi_agent-0.2.7.tar.gz
(12.5 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
phi_agent-0.2.7-py3-none-any.whl
(12.2 kB
view details)
File details
Details for the file phi_agent-0.2.7.tar.gz.
File metadata
- Download URL: phi_agent-0.2.7.tar.gz
- Upload date:
- Size: 12.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/7.0.0 CPython/3.10.17
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
424434871ed71e190f5d2fcbe767f9f51378c63358746425a321c4effd7c77ae
|
|
| MD5 |
b1824b213b462ac158e125927637733a
|
|
| BLAKE2b-256 |
ccbf382d1ffdf4f3342f91f197f324ded3cb208fc712b21bfb6b8094ead6e591
|
File details
Details for the file phi_agent-0.2.7-py3-none-any.whl.
File metadata
- Download URL: phi_agent-0.2.7-py3-none-any.whl
- Upload date:
- Size: 12.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/7.0.0 CPython/3.10.17
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b2fc84fbf590275e11940d7c3e54330fea58b92f8dc4488d02046dfa67904431
|
|
| MD5 |
c560052669269386f13389579447a2e0
|
|
| BLAKE2b-256 |
8b5727b667ae7f8d139cdd7f500bd10b4feed0b0fddb23eb8073171d33d219b8
|