The Synth OpenAI clients provide the same functionality as the original OpenAI clients, but automatically track all AI messages when used within methods decorated with trace_event.

Usage

from synth_sdk import AsyncOpenAI, OpenAI
import uuid

class Agent:
    def __init__(self):
        self.system_instance_id = str(uuid.uuid4())
        self.system_name = "Example_System"
        self.client = AsyncOpenAI()  # or OpenAI() for sync

    @trace_event_async(
        event_type="solve_problem",
    )
    async def solve_problem(self, problem: str):
        # Messages are automatically tracked - no need for track_messages
        response = await self.client.chat.completions.create(
            model="gpt-4",
            messages=[
                {"role": "system", "content": "You are a problem solver."},
                {"role": "user", "content": problem}
            ],
            temperature=0.7
        )
        return response.choices[0].message.content

The client automatically tracks:

  • Input messages
  • Output messages
  • Model parameters
  • Tool calls and responses

Note: When using these clients within trace_event decorated methods, you don’t need to use track_messages as all interactions are automatically tracked.