import time, sys, os, json from crewai import Agent, Task, Crew, LLM model = sys.argv[1] llm = LLM(model=f"openai/{model}", base_url="https://api.x.ai/v1", api_key=os.environ["XAI_API_KEY"], temperature=0) csv = open("invoices.csv").read() clerk = Agent(role="UK bookkeeping assistant", goal="Prepare accurate credit-control summaries for a UK small business", backstory="You help a small UK firm chase unpaid invoices. UK standard VAT rate is 20%.", llm=llm, verbose=True) t = Task(description=f"Today is 2026-10-14. All invoices below are unpaid. Data:\n{csv}\n" "1) For each invoice compute VAT at 20% and gross total (GBP, 2dp). 2) List which invoices are overdue (due date before today). " "3) Give the total gross amount overdue. 4) Draft a short, polite UK-English chaser email to the customer with the oldest overdue invoice.", expected_output="A table of invoices with net, VAT, gross; the overdue list; total gross overdue; a chaser email.", agent=clerk) s=time.time(); crew=Crew(agents=[clerk], tasks=[t]); out = crew.kickoff(); print("\n=====FINAL=====\n", out.raw); print(f"\nELAPSED {time.time()-s:.1f}s") u=out.token_usage; print("USAGE", json.dumps({"prompt_tokens":u.prompt_tokens,"completion_tokens":u.completion_tokens,"cached_prompt_tokens":getattr(u,"cached_prompt_tokens",0),"requests":u.successful_requests}))