| from agents import Runner, trace, gen_trace_id
|
| from writer_agent import writer_agent, ProformaInvoice
|
| from email_agent import email_agent
|
| import asyncio
|
|
|
| class Manager:
|
|
|
| async def run(self, data: dict):
|
| """ Run the process, yielding the status updates and the final report"""
|
| trace_id = gen_trace_id()
|
| with trace("Research trace", trace_id=trace_id):
|
| print(f"View trace: https://platform.openai.com/traces/trace?trace_id={trace_id}")
|
| yield f"View trace: https://platform.openai.com/traces/trace?trace_id={trace_id}"
|
| print("Starting research...")
|
| report = await self.writer_agent(data)
|
| yield "Creating the invoice..."
|
|
|
| await self.send_email(report)
|
| yield "Email sent, PI sent"
|
| yield report.proforma_invoice
|
|
|
|
|
|
|
| async def writer_agent(self, data: dict) -> ProformaInvoice:
|
| result = await Runner.run(
|
| writer_agent,
|
| data,
|
| )
|
| return result.final_output_as(ProformaInvoice)
|
|
|
| async def send_email(self, report: ProformaInvoice) -> None:
|
| print("Writing email...")
|
| result = await Runner.run(
|
| email_agent,
|
| report.proforma_invoice,
|
| )
|
| print("Email sent")
|
| return report |