#!/usr/bin/env python3
"""
Generated test file for Tool Error Agent Test
Framework: openai-agents
Execution mode: async
Streaming: no"""

import os
import sentry_sdk
import asyncio

from agents import function_tool, Agent, Runner


sentry_sdk.init(
    dsn=os.environ.get("SENTRY_DSN"),
    traces_sample_rate=1.0,
    send_default_pii=True,
    stream_gen_ai_spans=True,
)

# Define tool functions using @function_tool decorator
@function_tool
def read_file(path: str):
    """Read the contents of a file"""
    raise Exception("FileNotFoundError: The file '/nonexistent/file.txt' does not exist")

# Create agent with tools
agent = Agent(
    name="file_assistant",
    instructions="An assistant that can read files",
    tools=[read_file],
    model="gpt-4o-mini",
)

async def main():
    # Turn 1: Build prompt from messages
    prompt = "Please read the file at /nonexistent/file.txt and tell me what it contains. Use the read_file tool."
    
    # Run agent
    result = await Runner.run(agent, input=prompt)
    
    # Print result
    print(f"Turn 1 Agent result: {result.final_output}")

if __name__ == "__main__":
    with sentry_sdk.start_transaction(op="test", name="Tool Error Agent Test"):
        asyncio.run(main())
    sentry_sdk.flush(timeout=5)
