"""L3: Multi-agent customer support automation. A support rep drafts an answer using the CrewAI docs, then a QA specialist reviews it. Needs only GEMINI_API_KEY in .env. Run: python L3_customer_support.py """ import os from dotenv import load_dotenv from crewai import Agent, Task, Crew, LLM from crewai_tools import ScrapeWebsiteTool load_dotenv() if not (os.getenv("GEMINI_API_KEY") or os.getenv("GOOGLE_API_KEY")): raise SystemExit("Missing GEMINI_API_KEY. Add it to the .env file next to this script.") gemini_llm = LLM(model=os.getenv("GEMINI_MODEL", "gemini/gemini-3.8-flash")) # Scrapes one page of the CrewAI docs. No API key needed for this tool. docs_scrape_tool = ScrapeWebsiteTool( website_url="https://docs.crewai.com/en/concepts/memory" ) support_agent = Agent( role="Senior Support Representative", goal="Be the most friendly and helpful " "support representative in your team", backstory=( "You work at crewAI (https://crewai.com) and " "are now working on providing " "support to {customer}, a super important customer " "for your company. " "You need to make sure that you provide the best support! " "Make sure to provide full complete answers, " "and make no assumptions." ), llm=gemini_llm, allow_delegation=False, verbose=True, ) # allow_delegation defaults to True, so this agent can hand work back # to the support representative. support_quality_assurance_agent = Agent( role="Support Quality Assurance Specialist", goal="Get recognition for providing the " "best support quality assurance in your team", backstory=( "You work at crewAI (https://crewai.com) and " "are now working with your team " "on a request from {customer} ensuring that " "the support representative is " "providing the best support possible.\n" "You need to make sure that the support representative " "is providing full complete answers, and make no assumptions." ), llm=gemini_llm, verbose=True, ) # Tools can be attached to an agent (usable in every task) or to a single # task, as below. Task level tools win over agent level tools. inquiry_resolution = Task( description=( "{customer} just reached out with a super important ask:\n" "{inquiry}\n\n" "{person} from {customer} is the one that reached out. " "Make sure to use everything you know " "to provide the best support possible. " "You must strive to provide a complete " "and accurate response to the customer's inquiry." ), expected_output=( "A detailed, informative response to the " "customer's inquiry that addresses " "all aspects of their question.\n" "The response should include references " "to everything you used to find the answer, " "including external data or solutions. " "Ensure the answer is complete, " "leaving no questions unanswered, and maintain a helpful and friendly " "tone throughout." ), tools=[docs_scrape_tool], agent=support_agent, ) quality_assurance_review = Task( description=( "Review the response drafted by the Senior Support Representative " "for {customer}'s inquiry. " "Ensure that the answer is comprehensive, accurate, and adheres to the " "high-quality standards expected for customer support.\n" "Verify that all parts of the customer's inquiry " "have been addressed " "thoroughly, with a helpful and friendly tone.\n" "Check for references and sources used to " "find the information, " "ensuring the response is well-supported and " "leaves no questions unanswered." ), expected_output=( "A final, detailed, and informative response " "ready to be sent to the customer.\n" "This response should fully address the " "customer's inquiry, incorporating all " "relevant feedback and improvements.\n" "Don't be too formal, we are a chill and cool company " "but maintain a professional and friendly tone throughout." ), agent=support_quality_assurance_agent, ) # The notebook used memory=True here. Crew memory needs an embedding model on # top of the chat model, and CrewAI's default embedder is OpenAI, so it is off # by default to keep this runnable with a Gemini key alone. See README.md. crew = Crew( agents=[support_agent, support_quality_assurance_agent], tasks=[inquiry_resolution, quality_assurance_review], verbose=True, ) if __name__ == "__main__": inputs = { "customer": "Creighton University", "person": "Steven Fernandes", "inquiry": "I need help with learning Steven's AI research", } result = crew.kickoff(inputs=inputs) print("\n\n===== FINAL OUTPUT =====\n") print(result)