File size: 17,832 Bytes
c287226
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3da6761
c287226
7e2f346
d388506
7e2f346
c287226
d388506
 
 
 
 
 
 
c287226
 
d388506
c287226
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d388506
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c287226
d388506
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c287226
d388506
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c287226
d388506
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c287226
 
 
3da6761
c287226
 
5f637fd
c287226
d388506
c287226
 
 
 
 
3da6761
 
 
d388506
 
 
c287226
 
 
 
 
 
 
 
 
 
 
d388506
c287226
 
 
d388506
c287226
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d388506
c287226
 
 
 
 
 
 
 
 
 
 
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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
import asyncio
from typing import Any

from agno.agent import Agent
from agno.models.openai import OpenAIChat
from agno.tools.googlesearch import GoogleSearchTools
from agno.utils.pprint import pprint_run_response
from agno.workflow.v2.types import WorkflowExecutionInput
from agno.workflow.v2.workflow import Workflow
from pydantic import BaseModel, Field

from dotenv import load_dotenv
import os

script_dir = os.path.dirname(os.path.abspath(__file__))
env_path = os.path.join(script_dir, '.env')
load_dotenv(env_path)

# --- Atla Insights Configuration ---
from atla_insights import configure, instrument, instrument_agno, instrument_openai, mark_success, mark_failure, tool, set_metadata

# Model configuration - using same model across all agents but you can change them to any model you want
DEFAULT_MODEL_ID = "gpt-4o"

# Define metadata for tracing
def get_metadata(model_id):
    return {
        "model": model_id,
        "prompt": "v1.1",
        "environment": "prod",
        "agent_name": "Startup Idea Validator"
    }

# Configure Atla Insights with metadata - REQUIRED FIRST
configure(token=os.getenv("ATLA_INSIGHTS_TOKEN"), metadata=get_metadata(DEFAULT_MODEL_ID))

# Instrument based on detected framework and LLM provider
instrument_agno("openai")  # Agno framework with OpenAI

# --- Response models ---
class IdeaClarification(BaseModel):
    originality: str = Field(..., description="Originality of the idea.")
    mission: str = Field(..., description="Mission of the company.")
    objectives: str = Field(..., description="Objectives of the company.")


class MarketResearch(BaseModel):
    total_addressable_market: str = Field(
        ..., description="Total addressable market (TAM) with specific dollar amount."
    )
    total_addressable_market_calculation: str = Field(
        ..., description="Step-by-step calculation methodology used to derive TAM."
    )
    total_addressable_market_sources: str = Field(
        ..., description="Specific data sources and citations used for TAM calculation."
    )
    serviceable_available_market: str = Field(
        ..., description="Serviceable available market (SAM) with specific dollar amount."
    )
    serviceable_available_market_calculation: str = Field(
        ..., description="Step-by-step calculation methodology used to derive SAM from TAM."
    )
    serviceable_obtainable_market: str = Field(
        ..., description="Serviceable obtainable market (SOM) with specific dollar amount."
    )
    serviceable_obtainable_market_calculation: str = Field(
        ..., description="Step-by-step calculation methodology used to derive SOM from SAM."
    )
    market_size_validation: str = Field(
        ..., description="Self-validation check: Does SOM < SAM < TAM? Are calculations logical and consistent?"
    )
    target_customer_segments: str = Field(..., description="Target customer segments with detailed demographics, needs, and market sizes.")
    data_quality_assessment: str = Field(
        ..., description="Assessment of the reliability and recency of the data sources used."
    )


class CompetitorAnalysis(BaseModel):
    competitors: str = Field(..., description="List of identified competitors.")
    swot_analysis: str = Field(..., description="SWOT analysis for each competitor.")
    positioning: str = Field(
        ..., description="Startup's potential positioning relative to competitors."
    )


class ValidationReport(BaseModel):
    executive_summary: str = Field(
        ..., description="Executive summary of the validation."
    )
    idea_assessment: str = Field(..., description="Assessment of the startup idea.")
    market_opportunity: str = Field(..., description="Market opportunity analysis.")
    competitive_landscape: str = Field(
        ..., description="Competitive landscape overview."
    )
    recommendations: str = Field(..., description="Strategic recommendations.")
    next_steps: str = Field(..., description="Recommended next steps.")


# --- Agent creation functions ---
def create_agents(model_id: str = DEFAULT_MODEL_ID):
    """Create all agents with the specified model"""
    
    idea_clarifier_agent = Agent(
        name="Idea Clarifier",
        model=OpenAIChat(id=model_id),
        instructions=[
            "Given a user's startup idea, your goal is to refine that idea.",
            "Evaluate the originality of the idea by comparing it with existing concepts.",
            "Define the mission and objectives of the startup.",
            "Provide clear, actionable insights about the core business concept.",
        ],
        add_history_to_messages=True,
        add_datetime_to_instructions=True,
        response_model=IdeaClarification,
        debug_mode=False,
    )

    market_research_agent = Agent(
        name="Market Research Agent",
        model=OpenAIChat(id=model_id), 
        tools=[GoogleSearchTools()],
        instructions=[
            "You are provided with a startup idea and the company's mission and objectives.",
            "Estimate the total addressable market (TAM), serviceable available market (SAM), and serviceable obtainable market (SOM).",
            "Define target customer segments and their characteristics.",
            "Search the web for resources and data to support your analysis.",
            "Provide specific market size estimates with supporting data sources.",
        ],
        add_history_to_messages=True,
        add_datetime_to_instructions=True,
        response_model=MarketResearch,
        debug_mode=False,
    )

    competitor_analysis_agent = Agent(
        name="Competitor Analysis Agent",
        model=OpenAIChat(id=model_id),  
        tools=[GoogleSearchTools()],
        instructions=[
            "You are provided with a startup idea and market research data.",
            "Identify existing competitors in the market.",
            "Perform Strengths, Weaknesses, Opportunities, and Threats (SWOT) analysis for each competitor.",
            "Assess the startup's potential positioning relative to competitors.",
            "Search for recent competitor information and market positioning.",
        ],
        add_history_to_messages=True,
        add_datetime_to_instructions=True,
        response_model=CompetitorAnalysis,
        debug_mode=False,
    )

    report_agent = Agent(
        name="Report Generator",
        model=OpenAIChat(id=model_id),  
        instructions=[
            "You are provided with comprehensive data about a startup idea including clarification, market research, and competitor analysis.",
            "Synthesize all information into a comprehensive validation report.",
            "Provide clear executive summary, assessment, and actionable recommendations.",
            "Structure the report professionally with clear sections and insights.",
            "Include specific next steps for the entrepreneur.",
        ],
        add_history_to_messages=True,
        add_datetime_to_instructions=True,
        response_model=ValidationReport,
        debug_mode=False,
    )
    
    return idea_clarifier_agent, market_research_agent, competitor_analysis_agent, report_agent


# --- Execution function ---
@instrument("Startup Idea Validation Workflow")
async def startup_validation_execution(
    workflow: Workflow,
    execution_input: WorkflowExecutionInput, # This is a Pydantic model to ensure type safety
    startup_idea: str,
    model_id: str = DEFAULT_MODEL_ID,
    progress_callback=None,
    **kwargs: Any,
) -> str:
    """Execute the complete startup idea validation workflow"""

    # Set dynamic metadata for this execution
    set_metadata(get_metadata(model_id))

    # Create agents with the specified model
    idea_clarifier_agent, market_research_agent, competitor_analysis_agent, report_agent = create_agents(model_id)

    # Get inputs
    message: str = execution_input.message
    idea: str = startup_idea

    if not idea:
        mark_failure()
        return "❌ No startup idea provided"

    if progress_callback:
        progress_callback(f"πŸš€ Starting startup idea validation for: {idea}")
        progress_callback(f"πŸ’‘ Validation request: {message}")
        progress_callback(f"πŸ€– Using model: {model_id}")
    else:
        print(f"πŸš€ Starting startup idea validation for: {idea}")
        print(f"πŸ’‘ Validation request: {message}")
        print(f"πŸ€– Using model: {model_id}")

    # Phase 1: Idea Clarification
    if progress_callback:
        progress_callback(f"\n🎯 PHASE 1: IDEA CLARIFICATION & REFINEMENT")
        progress_callback("=" * 60)
    else:
        print(f"\n🎯 PHASE 1: IDEA CLARIFICATION & REFINEMENT")
        print("=" * 60)

    clarification_prompt = f"""
    {message}
    
    Please analyze and refine the following startup idea:
    
    STARTUP IDEA: {idea}
    
    Evaluate:
    1. The originality of this idea compared to existing solutions
    2. Define a clear mission statement for this startup
    3. Outline specific, measurable objectives
    
    Provide insights on how to strengthen and focus the core concept.
    """

    if progress_callback:
        progress_callback(f"πŸ” Analyzing and refining the startup concept...")
    else:
        print(f"πŸ” Analyzing and refining the startup concept...")

    try:
        clarification_result = await idea_clarifier_agent.arun(clarification_prompt)
        idea_clarification = clarification_result.content

        if progress_callback:
            progress_callback(f"βœ… Idea clarification completed")
            progress_callback(f"πŸ“ Mission: {idea_clarification.mission[:100]}...")
        else:
            print(f"βœ… Idea clarification completed")
            print(f"πŸ“ Mission: {idea_clarification.mission[:100]}...")

    except Exception as e:
        mark_failure()
        return f"❌ Failed to clarify idea: {str(e)}"

    # Phase 2: Market Research
    if progress_callback:
        progress_callback(f"\nπŸ“Š PHASE 2: MARKET RESEARCH & ANALYSIS")
        progress_callback("=" * 60)
    else:
        print(f"\nπŸ“Š PHASE 2: MARKET RESEARCH & ANALYSIS")
        print("=" * 60)

    market_research_prompt = f"""
    Based on the refined startup idea and clarification below, conduct comprehensive market research:
    
    STARTUP IDEA: {idea}
    ORIGINALITY: {idea_clarification.originality}
    MISSION: {idea_clarification.mission}
    OBJECTIVES: {idea_clarification.objectives}
    
    Please research and provide:
    1. Total Addressable Market (TAM) - overall market size
    2. Serviceable Available Market (SAM) - portion you could serve
    3. Serviceable Obtainable Market (SOM) - realistic market share
    4. Target customer segments with detailed characteristics
    
    Use web search to find current market data and trends.
    """

    if progress_callback:
        progress_callback(f"πŸ“ˆ Researching market size and customer segments...")
    else:
        print(f"πŸ“ˆ Researching market size and customer segments...")

    try:
        market_result = await market_research_agent.arun(market_research_prompt)
        market_research = market_result.content

        if progress_callback:
            progress_callback(f"βœ… Market research completed")
            progress_callback(f"🎯 TAM: {market_research.total_addressable_market[:100]}...")
        else:
            print(f"βœ… Market research completed")
            print(f"🎯 TAM: {market_research.total_addressable_market[:100]}...")

    except Exception as e:
        mark_failure()
        return f"❌ Failed to complete market research: {str(e)}"

    # Phase 3: Competitor Analysis
    if progress_callback:
        progress_callback(f"\n🏒 PHASE 3: COMPETITIVE LANDSCAPE ANALYSIS")
        progress_callback("=" * 60)
    else:
        print(f"\n🏒 PHASE 3: COMPETITIVE LANDSCAPE ANALYSIS")
        print("=" * 60)

    competitor_prompt = f"""
    Based on the startup idea and market research below, analyze the competitive landscape:
    
    STARTUP IDEA: {idea}
    TAM: {market_research.total_addressable_market}
    SAM: {market_research.serviceable_available_market}
    SOM: {market_research.serviceable_obtainable_market}
    TARGET SEGMENTS: {market_research.target_customer_segments}
    
    Please research and provide:
    1. Identify direct and indirect competitors
    2. SWOT analysis for each major competitor
    3. Assessment of startup's potential competitive positioning
    4. Market gaps and opportunities
    
    Use web search to find current competitor information.
    """

    if progress_callback:
        progress_callback(f"πŸ”Ž Analyzing competitive landscape...")
    else:
        print(f"πŸ”Ž Analyzing competitive landscape...")

    try:
        competitor_result = await competitor_analysis_agent.arun(competitor_prompt)
        competitor_analysis = competitor_result.content

        if progress_callback:
            progress_callback(f"βœ… Competitor analysis completed")
            progress_callback(f"πŸ† Positioning: {competitor_analysis.positioning[:100]}...")
        else:
            print(f"βœ… Competitor analysis completed")
            print(f"πŸ† Positioning: {competitor_analysis.positioning[:100]}...")

    except Exception as e:
        mark_failure()
        return f"❌ Failed to complete competitor analysis: {str(e)}"

    # Phase 4: Final Validation Report
    if progress_callback:
        progress_callback(f"\nπŸ“‹ PHASE 4: COMPREHENSIVE VALIDATION REPORT")
        progress_callback("=" * 60)
    else:
        print(f"\nπŸ“‹ PHASE 4: COMPREHENSIVE VALIDATION REPORT")
        print("=" * 60)

    report_prompt = f"""
    Synthesize all the research and analysis into a comprehensive startup validation report:
    
    STARTUP IDEA: {idea}
    
    IDEA CLARIFICATION:
    - Originality: {idea_clarification.originality}
    - Mission: {idea_clarification.mission}
    - Objectives: {idea_clarification.objectives}
    
    MARKET RESEARCH:
    - TAM: {market_research.total_addressable_market}
    - SAM: {market_research.serviceable_available_market}
    - SOM: {market_research.serviceable_obtainable_market}
    - Target Segments: {market_research.target_customer_segments}
    
    COMPETITOR ANALYSIS:
    - Competitors: {competitor_analysis.competitors}
    - SWOT: {competitor_analysis.swot_analysis}
    - Positioning: {competitor_analysis.positioning}
    
    Create a professional validation report with:
    1. Executive summary
    2. Idea assessment (strengths/weaknesses)
    3. Market opportunity analysis
    4. Competitive landscape overview
    5. Strategic recommendations
    6. Specific next steps for the entrepreneur
    """

    if progress_callback:
        progress_callback(f"πŸ“ Generating comprehensive validation report...")
    else:
        print(f"πŸ“ Generating comprehensive validation report...")

    try:
        final_result = await report_agent.arun(report_prompt)
        validation_report = final_result.content

        if progress_callback:
            progress_callback(f"βœ… Validation report completed")
        else:
            print(f"βœ… Validation report completed")

    except Exception as e:
        mark_failure()
        return f"❌ Failed to generate final report: {str(e)}"

    # Final summary
    summary = f"""
    πŸŽ‰ STARTUP IDEA VALIDATION COMPLETED!
    
    πŸ“Š Validation Summary:
    β€’ Startup Idea: {idea}
    β€’ Idea Clarification: βœ… Completed
    β€’ Market Research: βœ… Completed
    β€’ Competitor Analysis: βœ… Completed
    β€’ Final Report: βœ… Generated
    
    πŸ“ˆ Key Market Insights:
    β€’ TAM: {market_research.total_addressable_market[:150]}...
    β€’ Target Segments: {market_research.target_customer_segments[:150]}...
    
    πŸ† Competitive Positioning:
    {competitor_analysis.positioning[:200]}...
    
    πŸ“‹ COMPREHENSIVE VALIDATION REPORT:
    
    ## Executive Summary
    {validation_report.executive_summary}
    
    ## Idea Assessment
    {validation_report.idea_assessment}
    
    ## Market Opportunity
    {validation_report.market_opportunity}
    
    ## Competitive Landscape
    {validation_report.competitive_landscape}
    
    ## Strategic Recommendations
    {validation_report.recommendations}
    
    ## Next Steps
    {validation_report.next_steps}
    
    ⚠️ Disclaimer: This validation is for informational purposes only. Conduct additional due diligence before making investment decisions.
    """

    # Mark successful completion
    mark_success()
    return summary


# --- Workflow definition ---
startup_validation_workflow = Workflow(
    name="Startup Idea Validator",
    description="Comprehensive startup idea validation with market research and competitive analysis",
    steps=startup_validation_execution,
    workflow_session_state={},  # Initialize empty workflow session state
)


if __name__ == "__main__":

    async def main():
        from rich.prompt import Prompt

        # Get idea from user
        idea = Prompt.ask(
            "[bold]What is your startup idea?[/bold]\n✨",
            default="A marketplace for Christmas Ornaments made from leather",
        )

        print("πŸ§ͺ Testing Startup Idea Validator with New Workflow Structure")
        print("=" * 70)

        try:
            result = await startup_validation_workflow.arun(
                message="Please validate this startup idea with comprehensive market research and competitive analysis",
                startup_idea=idea,
                model_id=DEFAULT_MODEL_ID,
            )

            pprint_run_response(result, markdown=True)
            mark_success()
            
        except Exception as e:
            print(f"❌ Application failed: {str(e)}")
            mark_failure()
            raise

    asyncio.run(main())