File size: 1,399 Bytes
e0ce0f6 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | 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, # ✅ pass user fields directly!
)
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 |