SDK for tracking and testing OpenAI API calls
Project description
Playgent
Record and test your OpenAI agent traces.
Installation
pip install playgent
Quick Start
Step 1: Instrument your agent to record traces
import json
from typing import List
import dotenv
import os
dotenv.load_dotenv()
from playgent.openai import OpenAI # Drop-in replacement for OpenAI
from playgent import record, trace
client = OpenAI() # Automatically tracks all OpenAI calls
# Your agent functions here
def add_to_todo_list(task: str) -> str:
# ... your implementation
pass
@record # This decorator records the entire trace
def infer(input_text: str, model: str = "gpt-4", tools_list: List = None):
messages = [{"role": "user", "content": input_text}]
# Your agent logic with OpenAI calls
response = client.chat.completions.create(
model=model,
messages=messages,
tools=tools_list
)
# Process response and handle tool calls...
return response
# Use trace context manager to auto-create traces
with trace() as sess:
result = infer("Add 'buy milk' to my todo list")
Step 2: Run tests via replay
After annotating traces with expected outcomes on the Playgent dashboard:
from playgent import replay_test, evaluate
from example_agent import infer
# Test using a recorded trace ID
test_case_id = "6996b53a-1ebf-403a-8770-10ed001391c3"
with replay_test(test_case_id) as (trace_id, endpoint_events):
for event in endpoint_events:
infer(**event.arguments)
result = evaluate(test_case_id, trace_id)
That's it! Two steps:
- Instrument - Add
@recorddecorator and useplaygent.openai.OpenAI - Test - Replay annotated traces and evaluate results
Environment Setup
Create a .env file:
PLAYGENT_API_KEY=your-playgent-api-key
OPENAI_API_KEY=your-openai-api-key
Full Examples
See example_agent.py and example_agent_test.py for complete working examples.
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
playgent-0.1.3.tar.gz
(36.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
playgent-0.1.3-py3-none-any.whl
(39.6 kB
view details)
File details
Details for the file playgent-0.1.3.tar.gz.
File metadata
- Download URL: playgent-0.1.3.tar.gz
- Upload date:
- Size: 36.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
44d87843da3b584b10ca89625abc515729173bc8a6ac323fd6350fb71c263bc6
|
|
| MD5 |
814d9ab0a1153e49ce5644d611daa411
|
|
| BLAKE2b-256 |
d705e89e6f2f386cf82b513bdf41e2cd69fcf50089cc38d01f5afae173c7f0d7
|
File details
Details for the file playgent-0.1.3-py3-none-any.whl.
File metadata
- Download URL: playgent-0.1.3-py3-none-any.whl
- Upload date:
- Size: 39.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4dc3b202737478889b688a77f2c0a553e8b785c537aa8ebc788de12e9f51378c
|
|
| MD5 |
f2062a0499d9b20415fba2a6ece3ffb4
|
|
| BLAKE2b-256 |
c425658d68ed5175b7c87e7b824f4e09d3108f127c5bb6791870ed9becc305b1
|