This guide provides instructions for integrating Phidata with the Truefoundry AI Gateway.

What is Phidata?

Phidata is a framework for building AI applications with memory, knowledge, and tools. It provides a comprehensive platform for creating intelligent agents that can maintain context across conversations, access external knowledge bases, and use various tools to accomplish complex tasks.

Key Features of Phidata

  • Memory & Context: Built-in memory capabilities that allow agents to remember previous conversations and maintain context across interactions
  • Knowledge Integration: Seamless integration with vector databases and knowledge bases for RAG (Retrieval-Augmented Generation) applications
  • Tool Integration: Extensive library of tools for web search, file operations, data analysis, and custom function calling
  • Agent Orchestration: Framework for building and orchestrating multiple specialized agents that can work together on complex tasks

Prerequisites

Before integrating Phidata with TrueFoundry, ensure you have:
  1. TrueFoundry Account: Create a Truefoundry account and follow our Gateway Quick Start
  2. Phidata Installation: Install Phidata using pip: pip install -U phidata

Setup Process

1. Configure Phidata with TrueFoundry

You will get your ‘truefoundry-api-key’, ‘truefoundry-gateway-url’ and model name directly from the unified code snippet

2. Basic Setup with Phidata

Connect to TrueFoundry by configuring the OpenAI LLM in Phidata with your TrueFoundry gateway:
from phi.agent import Agent
from phi.llm.openai import OpenAIChat

llm = OpenAIChat(
    base_url="your-truefoundry-base-url",
    api_key="your-truefoundry-api-key",
    model='openai-main/gpt-4o'  # Use any model from any provider
)

agent = Agent(
    llm=llm,
    description="You help people with their questions.",
    instructions=["tell fun and amazing facts about the topic"],
)

# Print a response to the client
agent.print_response("tell something about sabertooth tiger.", markdown=True)
Replace:
  • your-truefoundry-api-key with your actual TrueFoundry API key
  • your-truefoundry-base-url with your TrueFoundry Gateway URL
  • Use your desired model in the format provider-main/model-name

3. Environment Variables Configuration

For persistent configuration across your Phidata applications, set these environment variables:
export OPENAI_API_KEY="your-truefoundry-api-key"
export OPENAI_BASE_URL="your-truefoundry-base-url"

Usage Examples

Basic Agent Example

When you run the agent example above, you’ll get a response like this:
Example response from Phidata agent showing information about sabertooth tigers

Response Image

Observability and Governance

Monitor your Phidata applications through TrueFoundry’s metrics tab: TrueFoundry metrics With TrueFoundry’s AI gateway, you can monitor and analyze:
  • Performance Metrics: Track key latency metrics like Request Latency, Time to First Token (TTFS), and Inter-Token Latency (ITL) with P99, P90, and P50 percentiles
  • Cost and Token Usage: Gain visibility into your application’s costs with detailed breakdowns of input/output tokens and the associated expenses for each model
  • Usage Patterns: Understand how your application is being used with detailed analytics on user activity, model distribution, and team-based usage
  • Agent Performance: Monitor individual agent performance and tool usage patterns
  • Rate limit and Load balancing: Set up rate limiting, load balancing and fallback for your models