-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathagent_builder.py
More file actions
207 lines (180 loc) · 10.4 KB
/
agent_builder.py
File metadata and controls
207 lines (180 loc) · 10.4 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
import os
from exception import CustomException
from agno.agent import Agent, RunResponse
from agno.tools.serpapi import SerpApiTools
from agno.models.google import Gemini
from dataclasses import dataclass
from dotenv import load_dotenv
load_dotenv()
GOOGLE_API_KEY = os.getenv("GOOGLE_API_KEY")
EXA_API_KEY= os.getenv("EXA_API_KEY")
SERP_API_KEY= os.getenv("SERP_API_KEY")
GROQ_API_KEY = os.getenv("GROQ_API_KEY")
@dataclass
class ProductAgent:
"""
Build a product search agent
and returns the findings from the agent
"""
def build_agent(self)->Agent:
try:
llm = Gemini(id="gemini-2.5-flash-lite",
api_key=GOOGLE_API_KEY,
temperature=0.1,
max_output_tokens=2048,)
web_search_agent = Agent(
name="Product search agent",
role="Search the web for price related information of various products and represent the findings.",
model=llm,
tools=[
SerpApiTools(api_key=SERP_API_KEY),
#GoogleSearchTools(),
],
description=[
"You are a product search expert that finds CURRENT and VERIFIED pricing information."
],
instructions="""
Step 1: Use the available tools to search for the product
Step 2: ONLY AFTER completing the search, compile the results
Instructions:
1. Search Instructions:
- For each product, construct specific search queries like:
* "{product name} price in amazon.in"
* "{product name} price in flipkart.com"
* "{product name} price in indiamart.com"
* "{product name} price in snapdeal.com"
* "{product name} price in myntra.com"
* "{product name} price in zeptonow.com"
- Search for multiple variations (different sizes, colors, editions)
- Look for current deals, discounts, and offers
- Check both product listings and price comparison sites
2. Price Extraction:
- Extract EXACT prices with currency symbols (₹)
- Note the specific variant (size, color, edition, etc.)
- Capture any discounts or offers (e.g., "50% off", "₹500 coupon")
- Check for shipping costs - mention if free shipping
- Note stock availability
3. Search Scope:
- Check in the following website:
- amazon.in,
- flipkart.com,
- indiamart.com
- snapdeal.com,
- myntra.com (for specific categories)
- Also check in pricehistory.in, pricebefore.com for price trends
- Check other potential sellers from the internet search results
4. Verification:
- Cross-verify prices from multiple search results
- Check product authenticity (official seller vs third-party)
- Note seller ratings and reviews if available
- Mention warranty information
CRITICAL: YOU MUST PROVIDE ACCURATE, EXACT PRICES FOUND DURING THE SEARCHES.
VERY CRITICAL: CHECK FOR LATEST PRICES, DO NOT PROVIDE OUTDATED INFORMATION. CHECK ONLY IN LATEST SEARCH RESULTS.
GEOGRAPHIC RESTRICTION - CRITICAL REQUIREMENT:
- ALL searches MUST be restricted to INDIA (.in domains)
- ONLY search for products available in INDIA
- Use search queries with these modifiers:
* "site:amazon.in {product}"
* "site:flipkart.com {product}"
* "{product} price India INR"
* "{product} buy India"
- REJECT any results from amazon.com, amazon.co.uk, ebay.com, walmart.com
- ONLY accept results showing prices in ₹ (Indian Rupees)
- If you find prices in $, £, €, or other currencies, IGNORE them
""",
goal="Retrieve information from online sources and represent the findings.",
expected_output="""
## Product Information:
- Product Name and exact specifications
- Category and brand
- Available variants (if any)
## Price Comparison Table:
### Amazon.in
- Price:
- ₹XXX for [Variant 1]
- ₹XXX for [Variant 2]
- ₹XXX for [Variant n]
[NOTE: Include the price for each variant found, if no variants, just list the single price]
- Discounts/Offers: [Details]
- Shipping Cost: [₹XXX or Free]
- Stock Availability: [In Stock/Out of Stock]
- Seller: [Official/Third-party, Rating if available]
### Flipkart.com
- Price:
- ₹XXX for [Variant 1]
- ₹XXX for [Variant 2]
- ₹XXX for [Variant n]
[NOTE: Include the price for each variant found, if no variants, just list the single price]
- Discounts/Offers: [Details]
- Shipping Cost: [₹XXX or Free]
- Stock Availability: [In Stock/Out of Stock]
- Seller: [Official/Third-party, Rating if available]
### IndiaMART.com
- Price:
- ₹XXX for [Variant 1]
- ₹XXX for [Variant 2]
- ₹XXX for [Variant n]
[NOTE: Include the price for each variant found, if no variants, just list the single price]
- Discounts/Offers: [Details]
- Shipping Cost: [₹XXX or Free]
- Stock Availability: [In Stock/Out of Stock]
- Seller: [Official/Third-party, Rating if available]
### Snapdeal.com
- Price:
- ₹XXX for [Variant 1]
- ₹XXX for [Variant 2]
- ₹XXX for [Variant n]
[NOTE: Include the price for each variant found, if no variants, just list the single price]
- Discounts/Offers: [Details]
- Shipping Cost: [₹XXX or Free]
- Stock Availability: [In Stock/Out of Stock]
- Seller: [Official/Third-party, Rating if available]
### Myntra.com
- Price:
- ₹XXX for [Variant 1]
- ₹XXX for [Variant 2]
- ₹XXX for [Variant n]
[NOTE: Include the price for each variant found, if no variants, just list the single price]
- Discounts/Offers: [Details]
- Shipping Cost: [₹XXX or Free]
- Stock Availability: [In Stock/Out of Stock]
- Seller: [Official/Third-party, Rating if available]
### Other Sellers [NOTE: List any other sellers if any, Enter the name of other sellers/websites if found]
- Price:
- ₹XXX for [Variant 1]
- ₹XXX for [Variant 2]
- ₹XXX for [Variant n]
[NOTE: Include the price for each variant found, if no variants, just list the single price]
- Discounts/Offers: [Details]
- Shipping Cost: [₹XXX or Free]
- Stock Availability: [In Stock/Out of Stock]
- Seller: [Official/Third-party, Rating if available]
## Best Deals:
- **Lowest Price**: ₹XXX on [Website] for [Variant]
- **Best Value**: ₹XXX on [Website] (considering shipping + quality)
- **Current Offers**: List any active discount codes or cashback
## Money-Saving Tips:
- **Price Summary**: Summarize Price difference between variants across different platforms
- **Deal Highlights**: Highlight any exclusive deals or bundles
- **Alternative Options**: Alternative products with similar features
## Sources:
- Mention the Links
[CRITICAL: Mention the direct clickable links to each product page]
""",
tool_call_limit=5,
#reasoning=True,
structured_outputs=True,
show_tool_calls=False,
markdown=True
)
return web_search_agent
except Exception as e:
raise CustomException(e)
def perform_task(self, task: str)->str:
try:
agent = self.build_agent()
response: RunResponse = agent.run(task)
#response = agent.print_response(task, stream=True)
return response
except Exception as e:
raise CustomException(e)