stevafernandes commited on
Commit
450f43c
·
verified ·
1 Parent(s): f8f9aa1

Upload 4 files

Browse files
Files changed (4) hide show
  1. README.md +55 -7
  2. app.py +54 -0
  3. customer_support.py +141 -0
  4. requirements.txt +6 -0
README.md CHANGED
@@ -1,13 +1,61 @@
1
  ---
2
- title: Hf
3
- emoji: 🦀
4
- colorFrom: pink
5
- colorTo: yellow
6
  sdk: gradio
7
  sdk_version: 6.28.0
8
- python_version: '3.13'
9
  app_file: app.py
10
- pinned: false
11
  ---
12
 
13
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
+ title: Customer Support Crew
 
 
 
3
  sdk: gradio
4
  sdk_version: 6.28.0
 
5
  app_file: app.py
 
6
  ---
7
 
8
+ # Multi-agent customer support automation
9
+
10
+ A support representative answers a customer question using the CrewAI docs, then a QA specialist reviews the answer. Shows role playing, delegation and attaching a tool to a single task.
11
+
12
+ ## Setup
13
+
14
+ Unzip this folder and open it in VS Code, then in the terminal:
15
+
16
+ ```bash
17
+ python -m venv venv
18
+
19
+ # macOS / Linux
20
+ source venv/bin/activate
21
+ # Windows
22
+ venv\Scripts\activate
23
+
24
+ pip install -r requirements.txt
25
+ ```
26
+
27
+ Now the API key. Copy `.env.example` to a file called `.env` in this same
28
+ folder and paste your key into it:
29
+
30
+ ```bash
31
+ cp .env.example .env # Windows: copy .env.example .env
32
+ ```
33
+
34
+ ```
35
+ GEMINI_API_KEY=your-actual-key-here
36
+ ```
37
+
38
+ Get a key at https://aistudio.google.com/apikey. It is free to start and it is
39
+ the only key this script needs.
40
+
41
+ In VS Code, press Ctrl+Shift+P, choose "Python: Select Interpreter" and pick the
42
+ one inside `venv`. Then run:
43
+
44
+ ```bash
45
+ python customer_support.py
46
+ ```
47
+
48
+ The agents narrate what they are doing as they go, and the finished result is
49
+ printed at the end under FINAL OUTPUT.
50
+
51
+
52
+ ## Deploy on Hugging Face
53
+
54
+ 1. Create a new Space at https://huggingface.co/new-space and choose the Gradio SDK.
55
+ 2. Upload `app.py`, `customer_support.py`, `requirements.txt` and this `README.md`.
56
+ Do not upload `.env`.
57
+ 3. In the Space's Settings, under "Variables and secrets", add a secret named
58
+ `GEMINI_API_KEY` holding your key.
59
+
60
+ `app.py` is the web page the Space serves. To try it locally, run
61
+ `pip install gradio==6.28.0` and then `python app.py`.
app.py ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Gradio front end for customer_support.py, used as the Hugging Face Space.
2
+
3
+ Run locally: python app.py
4
+ """
5
+
6
+ import gradio as gr
7
+
8
+ from customer_support import crew
9
+
10
+ # Free Hugging Face accounts run Gradio Spaces on ZeroGPU, which refuses to
11
+ # start an app without a @spaces.GPU function. This one is never called.
12
+ try:
13
+ import spaces
14
+
15
+ @spaces.GPU
16
+ def zerogpu_startup():
17
+ pass
18
+ except ImportError:
19
+ pass
20
+
21
+
22
+ def answer(customer, person, inquiry):
23
+ result = crew.kickoff(
24
+ inputs={"customer": customer, "person": person, "inquiry": inquiry}
25
+ )
26
+ return result.raw
27
+
28
+
29
+ demo = gr.Interface(
30
+ fn=answer,
31
+ inputs=[
32
+ gr.Textbox(label="Customer", value="DeepLearningAI"),
33
+ gr.Textbox(label="Person", value="Andrew Ng"),
34
+ gr.Textbox(
35
+ label="Inquiry",
36
+ lines=4,
37
+ value="I need help with setting up a Crew "
38
+ "and kicking it off, specifically "
39
+ "how can I add memory to my crew? "
40
+ "Can you provide guidance?",
41
+ ),
42
+ ],
43
+ outputs=gr.Markdown(),
44
+ title="Multi-agent customer support automation",
45
+ description="A support representative answers the inquiry using the "
46
+ "CrewAI docs, then a QA specialist reviews the answer.",
47
+ flagging_mode="never",
48
+ # The crew object is shared, so requests must run one at a time.
49
+ concurrency_limit=1,
50
+ )
51
+
52
+
53
+ if __name__ == "__main__":
54
+ demo.launch()
customer_support.py ADDED
@@ -0,0 +1,141 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """L3: Multi-agent customer support automation.
2
+
3
+ A support rep drafts an answer using the CrewAI docs, then a QA specialist
4
+ reviews it. Needs only GEMINI_API_KEY in .env.
5
+
6
+ Run: python L3_customer_support.py
7
+ """
8
+
9
+ import os
10
+
11
+ from dotenv import load_dotenv
12
+ from crewai import Agent, Task, Crew, LLM
13
+ from crewai_tools import ScrapeWebsiteTool
14
+
15
+ load_dotenv()
16
+
17
+ if not (os.getenv("GEMINI_API_KEY") or os.getenv("GOOGLE_API_KEY")):
18
+ raise SystemExit("Missing GEMINI_API_KEY. Add it to the .env file next to this script.")
19
+
20
+ gemini_llm = LLM(model=os.getenv("GEMINI_MODEL", "gemini/gemini-3.8-flash"))
21
+
22
+ # Scrapes one page of the CrewAI docs. No API key needed for this tool.
23
+ docs_scrape_tool = ScrapeWebsiteTool(
24
+ website_url="https://docs.crewai.com/en/concepts/memory"
25
+ )
26
+
27
+
28
+ support_agent = Agent(
29
+ role="Senior Support Representative",
30
+ goal="Be the most friendly and helpful "
31
+ "support representative in your team",
32
+ backstory=(
33
+ "You work at crewAI (https://crewai.com) and "
34
+ "are now working on providing "
35
+ "support to {customer}, a super important customer "
36
+ "for your company. "
37
+ "You need to make sure that you provide the best support! "
38
+ "Make sure to provide full complete answers, "
39
+ "and make no assumptions."
40
+ ),
41
+ llm=gemini_llm,
42
+ allow_delegation=False,
43
+ verbose=True,
44
+ )
45
+
46
+ # allow_delegation defaults to True, so this agent can hand work back
47
+ # to the support representative.
48
+ support_quality_assurance_agent = Agent(
49
+ role="Support Quality Assurance Specialist",
50
+ goal="Get recognition for providing the "
51
+ "best support quality assurance in your team",
52
+ backstory=(
53
+ "You work at crewAI (https://crewai.com) and "
54
+ "are now working with your team "
55
+ "on a request from {customer} ensuring that "
56
+ "the support representative is "
57
+ "providing the best support possible.\n"
58
+ "You need to make sure that the support representative "
59
+ "is providing full complete answers, and make no assumptions."
60
+ ),
61
+ llm=gemini_llm,
62
+ verbose=True,
63
+ )
64
+
65
+
66
+ # Tools can be attached to an agent (usable in every task) or to a single
67
+ # task, as below. Task level tools win over agent level tools.
68
+ inquiry_resolution = Task(
69
+ description=(
70
+ "{customer} just reached out with a super important ask:\n"
71
+ "{inquiry}\n\n"
72
+ "{person} from {customer} is the one that reached out. "
73
+ "Make sure to use everything you know "
74
+ "to provide the best support possible. "
75
+ "You must strive to provide a complete "
76
+ "and accurate response to the customer's inquiry."
77
+ ),
78
+ expected_output=(
79
+ "A detailed, informative response to the "
80
+ "customer's inquiry that addresses "
81
+ "all aspects of their question.\n"
82
+ "The response should include references "
83
+ "to everything you used to find the answer, "
84
+ "including external data or solutions. "
85
+ "Ensure the answer is complete, "
86
+ "leaving no questions unanswered, and maintain a helpful and friendly "
87
+ "tone throughout."
88
+ ),
89
+ tools=[docs_scrape_tool],
90
+ agent=support_agent,
91
+ )
92
+
93
+ quality_assurance_review = Task(
94
+ description=(
95
+ "Review the response drafted by the Senior Support Representative "
96
+ "for {customer}'s inquiry. "
97
+ "Ensure that the answer is comprehensive, accurate, and adheres to the "
98
+ "high-quality standards expected for customer support.\n"
99
+ "Verify that all parts of the customer's inquiry "
100
+ "have been addressed "
101
+ "thoroughly, with a helpful and friendly tone.\n"
102
+ "Check for references and sources used to "
103
+ "find the information, "
104
+ "ensuring the response is well-supported and "
105
+ "leaves no questions unanswered."
106
+ ),
107
+ expected_output=(
108
+ "A final, detailed, and informative response "
109
+ "ready to be sent to the customer.\n"
110
+ "This response should fully address the "
111
+ "customer's inquiry, incorporating all "
112
+ "relevant feedback and improvements.\n"
113
+ "Don't be too formal, we are a chill and cool company "
114
+ "but maintain a professional and friendly tone throughout."
115
+ ),
116
+ agent=support_quality_assurance_agent,
117
+ )
118
+
119
+
120
+ # The notebook used memory=True here. Crew memory needs an embedding model on
121
+ # top of the chat model, and CrewAI's default embedder is OpenAI, so it is off
122
+ # by default to keep this runnable with a Gemini key alone. See README.md.
123
+ crew = Crew(
124
+ agents=[support_agent, support_quality_assurance_agent],
125
+ tasks=[inquiry_resolution, quality_assurance_review],
126
+ verbose=True,
127
+ )
128
+
129
+
130
+ if __name__ == "__main__":
131
+ inputs = {
132
+ "customer": "DeepLearningAI",
133
+ "person": "Andrew Ng",
134
+ "inquiry": "I need help with setting up a Crew "
135
+ "and kicking it off, specifically "
136
+ "how can I add memory to my crew? "
137
+ "Can you provide guidance?",
138
+ }
139
+ result = crew.kickoff(inputs=inputs)
140
+ print("\n\n===== FINAL OUTPUT =====\n")
141
+ print(result)
requirements.txt ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ # Versions pinned to what these scripts were tested against.
2
+ # The [google-genai] extra is required. Without it crewai raises
3
+ # "Google Gen AI native provider not available" as soon as you build the LLM.
4
+ crewai[google-genai]==1.15.21
5
+ crewai-tools==1.15.21
6
+ python-dotenv==1.2.3