Skip to main content

phi-agent Python SDK — build AI agents with Python, powered by Rust runtime

Project description

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

Project details


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.1.0.tar.gz (9.3 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.1.0-py3-none-any.whl (9.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: phi_agent-0.1.0.tar.gz
  • Upload date:
  • Size: 9.3 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.1.0.tar.gz
Algorithm Hash digest
SHA256 34a3e519453449750548f4769f7594f42beabe2de7a0c30cba9a73c82e49cd1c
MD5 242328d09e8b5d39bfe4749f31c8468f
BLAKE2b-256 b3489551b9de9ebb470c4bda43dff27f366f116631b933f2712fa90ac67a34b8

See more details on using hashes here.

File details

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

File metadata

  • Download URL: phi_agent-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 9.3 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.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 93754f4014233cd1fda8dd690388a2733cb28128c308c9389e0c544b1ebe10d1
MD5 072b442646eee3542fad9bcbbe6492ab
BLAKE2b-256 0372996b3a7bb9df3bd0005806b4622fc1f244997079ba064c824bda396b6a0a

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