Skip to main content

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)   │
└──────────────┘             └──────────────────┘

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.9.1.tar.gz (13.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

phi_agent-0.9.1-py3-none-any.whl (12.8 kB view details)

Uploaded Python 3

File details

Details for the file phi_agent-0.9.1.tar.gz.

File metadata

  • Download URL: phi_agent-0.9.1.tar.gz
  • Upload date:
  • Size: 13.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.10.17

File hashes

Hashes for phi_agent-0.9.1.tar.gz
Algorithm Hash digest
SHA256 ab9eee69d6d063e827a40f1c436a1b17c676e58cae49d5cf37f0f4403ae02d5d
MD5 7c09bf0e2d2c61a7866608a7d41c50d2
BLAKE2b-256 741d7468ce83aafac14b9536e46f28f97d51be424c7688fa03356670d5758831

See more details on using hashes here.

File details

Details for the file phi_agent-0.9.1-py3-none-any.whl.

File metadata

  • Download URL: phi_agent-0.9.1-py3-none-any.whl
  • Upload date:
  • Size: 12.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.10.17

File hashes

Hashes for phi_agent-0.9.1-py3-none-any.whl
Algorithm Hash digest
SHA256 94d92a74de8e181788b50748d3f4058357a53833d38561cf804e4a61cf29828e
MD5 b66579e77a2a074e9d4da6963a12aedd
BLAKE2b-256 8bd6e270afee02113e9905a4f5f16a51175620f139a909f3a6c417b781968908

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