Spaces:
Runtime error
Runtime error
Commit
·
3b4b8d6
1
Parent(s):
b283074
Add application files
Browse files
app.py
CHANGED
|
@@ -2005,6 +2005,49 @@ After the tool completes, provide a summary of:
|
|
| 2005 |
last_final_answer = thought
|
| 2006 |
|
| 2007 |
elif event_type == "agent_complete":
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2008 |
# Save all to knowledge base (with deduplication)
|
| 2009 |
merge_to_knowledge_base(prospects_found, contacts_found, emails_drafted)
|
| 2010 |
|
|
@@ -2091,6 +2134,29 @@ After the tool completes, provide a summary of:
|
|
| 2091 |
return
|
| 2092 |
|
| 2093 |
elif event_type == "agent_max_iterations":
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2094 |
# Save what we found so far (with deduplication)
|
| 2095 |
merge_to_knowledge_base(prospects_found, contacts_found, emails_drafted)
|
| 2096 |
|
|
@@ -2098,7 +2164,7 @@ After the tool completes, provide a summary of:
|
|
| 2098 |
"icon": "⏱️",
|
| 2099 |
"icon_class": "warning",
|
| 2100 |
"title": "Max iterations reached",
|
| 2101 |
-
"detail": "Discovery stopped but
|
| 2102 |
})
|
| 2103 |
|
| 2104 |
summary_html = f'''<div class="progress-summary" style="background: linear-gradient(135deg, #f39c12 0%, #e67e22 100%);">
|
|
|
|
| 2005 |
last_final_answer = thought
|
| 2006 |
|
| 2007 |
elif event_type == "agent_complete":
|
| 2008 |
+
# Auto-generate emails if AI didn't draft any but we have contacts
|
| 2009 |
+
if contacts_found and not emails_drafted:
|
| 2010 |
+
progress_steps.append({
|
| 2011 |
+
"icon": "✉️",
|
| 2012 |
+
"icon_class": "tool",
|
| 2013 |
+
"title": "Auto-drafting outreach emails...",
|
| 2014 |
+
"detail": f"Creating personalized emails for {len(contacts_found)} contacts"
|
| 2015 |
+
})
|
| 2016 |
+
yield build_accordion(progress_steps)
|
| 2017 |
+
|
| 2018 |
+
for c in contacts_found:
|
| 2019 |
+
if c.get("email"):
|
| 2020 |
+
contact_name = c.get("name", "").split()[0] if c.get("name") else "there"
|
| 2021 |
+
company = c.get("company", "your company")
|
| 2022 |
+
title = c.get("title", "")
|
| 2023 |
+
|
| 2024 |
+
email_body = f"""Hi {contact_name},
|
| 2025 |
+
|
| 2026 |
+
I came across {company} and was impressed by your work in the industry. As {title}, I thought you might be interested in how {client_name} is helping similar companies achieve better results.
|
| 2027 |
+
|
| 2028 |
+
We specialize in solutions that could benefit {company}'s growth objectives. I'd love to share some insights that have worked well for companies in your space.
|
| 2029 |
+
|
| 2030 |
+
Would you be open to a quick 15-minute call this week to explore if there's a fit?
|
| 2031 |
+
|
| 2032 |
+
Best regards,
|
| 2033 |
+
{client_name} Team"""
|
| 2034 |
+
|
| 2035 |
+
emails_drafted.append({
|
| 2036 |
+
"to": c.get("email"),
|
| 2037 |
+
"subject": f"Quick question about {company}'s growth plans",
|
| 2038 |
+
"body": email_body,
|
| 2039 |
+
"prospect_company": company,
|
| 2040 |
+
"created_at": datetime.now().strftime("%Y-%m-%d %H:%M")
|
| 2041 |
+
})
|
| 2042 |
+
|
| 2043 |
+
progress_steps.append({
|
| 2044 |
+
"icon": "✅",
|
| 2045 |
+
"icon_class": "success",
|
| 2046 |
+
"title": f"Drafted {len(emails_drafted)} outreach emails",
|
| 2047 |
+
"detail": "Ready for review in the Emails tab"
|
| 2048 |
+
})
|
| 2049 |
+
yield build_accordion(progress_steps)
|
| 2050 |
+
|
| 2051 |
# Save all to knowledge base (with deduplication)
|
| 2052 |
merge_to_knowledge_base(prospects_found, contacts_found, emails_drafted)
|
| 2053 |
|
|
|
|
| 2134 |
return
|
| 2135 |
|
| 2136 |
elif event_type == "agent_max_iterations":
|
| 2137 |
+
# Auto-generate emails if we have contacts but no emails
|
| 2138 |
+
if contacts_found and not emails_drafted:
|
| 2139 |
+
for c in contacts_found:
|
| 2140 |
+
if c.get("email"):
|
| 2141 |
+
contact_name = c.get("name", "").split()[0] if c.get("name") else "there"
|
| 2142 |
+
company = c.get("company", "your company")
|
| 2143 |
+
title = c.get("title", "")
|
| 2144 |
+
email_body = f"""Hi {contact_name},
|
| 2145 |
+
|
| 2146 |
+
I came across {company} and was impressed by your work. As {title}, I thought you might be interested in how {client_name} is helping similar companies.
|
| 2147 |
+
|
| 2148 |
+
Would you be open to a quick 15-minute call this week?
|
| 2149 |
+
|
| 2150 |
+
Best regards,
|
| 2151 |
+
{client_name} Team"""
|
| 2152 |
+
emails_drafted.append({
|
| 2153 |
+
"to": c.get("email"),
|
| 2154 |
+
"subject": f"Quick question about {company}'s growth plans",
|
| 2155 |
+
"body": email_body,
|
| 2156 |
+
"prospect_company": company,
|
| 2157 |
+
"created_at": datetime.now().strftime("%Y-%m-%d %H:%M")
|
| 2158 |
+
})
|
| 2159 |
+
|
| 2160 |
# Save what we found so far (with deduplication)
|
| 2161 |
merge_to_knowledge_base(prospects_found, contacts_found, emails_drafted)
|
| 2162 |
|
|
|
|
| 2164 |
"icon": "⏱️",
|
| 2165 |
"icon_class": "warning",
|
| 2166 |
"title": "Max iterations reached",
|
| 2167 |
+
"detail": "Discovery stopped but results saved"
|
| 2168 |
})
|
| 2169 |
|
| 2170 |
summary_html = f'''<div class="progress-summary" style="background: linear-gradient(135deg, #f39c12 0%, #e67e22 100%);">
|