third_party_models.py 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. """
  2. This example showcases how you can:
  3. 1. Easily setup an agency that utilizes third-party models (Claude, Gemini, Grok)
  4. 2. Use their native tools (anthropic's web search).
  5. 3. Combine them with unpatched models (to allow for oai's hosted tool usage)
  6. Pre-requisites:
  7. 1. Following env variables for set for respective models in the `.env` file:
  8. - ANTHROPIC_API_KEY for claude models
  9. - GOOGLE_API_KEY for gemini models
  10. - XAI_API_KEY for grok models
  11. - OPENAI_API_KEY for openai models
  12. 2. Install openai-agents optional litellm package by running `pip install 'openai-agents[litellm]'`
  13. 3. Install litellm[proxy] separatelly by running `pip install 'litellm[proxy]'`
  14. Run the agency by running `python examples/third_party_models.py`
  15. This will open the TUI for a startup validation agency with 3 agents:
  16. 1. strategy_agent - gpt agent coordinates and summarizes work of other agents.
  17. 2. market_research_agent - gemini agent that performs market research and competitive analysis.
  18. 3. technical_agent - claude agent that designs system architecture, generates MVP code, and provides technical implementation based on validated business requirements.
  19. At the start of the chat, you can ask the agent to validate a startup idea or build an MVP, for example:
  20. "I have an idea for a SaaS tool that helps small businesses manage their social media content. Can you do a quick research and validate this idea?"
  21. Then follow it up with:
  22. "Propose a system architecture for this idea and stack for an MVP."
  23. """
  24. import warnings
  25. import litellm
  26. from agents import ModelSettings
  27. from dotenv import load_dotenv
  28. from agency_swarm import Agency, Agent
  29. # Suppress Pydantic deprecation warnings from litellm
  30. warnings.filterwarnings("ignore", category=DeprecationWarning)
  31. load_dotenv()
  32. # Configure litellm to automatically add dummy tools for Anthropic
  33. litellm.modify_params = True
  34. strategy_agent = Agent(
  35. name="StrategyAgent",
  36. description="Synthesizes market research into actionable business strategies, product roadmaps, and coordinates between research and technical implementation.",
  37. instructions="""
  38. You are a strategic business consultant and product manager. Your role is to:
  39. 1. **Strategy Synthesis**: Transform market research into clear business strategies and action plans
  40. 2. **Product Planning**: Create detailed product roadmaps, feature prioritization, and MVP specifications
  41. 3. **Business Model Design**: Develop revenue models, pricing strategies, and go-to-market plans
  42. 4. **Coordination**: Bridge the gap between market insights and technical implementation
  43. 5. **Risk Assessment**: Identify potential challenges and mitigation strategies
  44. When receiving market research, always:
  45. - Extract key insights and translate them into strategic decisions
  46. - Prioritize features based on market validation and technical feasibility
  47. - Create clear, actionable specifications for the technical team
  48. - Provide business justification for each recommendation
  49. - Consider both short-term MVP and long-term product vision
  50. Be decisive, practical, and always tie recommendations back to market data.
  51. """,
  52. model="openai/gpt-5.4-mini",
  53. )
  54. market_research_agent = Agent(
  55. name="MarketResearchAgent",
  56. description="Conducts real-time market research, competitive analysis, and validates business ideas using web search capabilities.",
  57. instructions="""
  58. You are a market research specialist with access to real-time web search. Your role is to:
  59. 1. **Market Validation**: Research market demand, size, and growth potential for business ideas
  60. 2. **Competitive Analysis**: Identify competitors, analyze their features, pricing, and positioning
  61. 3. **Target Audience Research**: Find and analyze target demographics, user needs, and pain points
  62. 4. **Trend Analysis**: Identify current market trends, emerging technologies, and opportunities
  63. 5. **Pricing Research**: Analyze pricing strategies and market rates for similar products/services
  64. Always provide:
  65. - Current, factual data with sources
  66. - Quantitative metrics when available (market size, growth rates, etc.)
  67. - Specific competitor examples with their strengths/weaknesses
  68. - Clear recommendations based on research findings
  69. Use web search extensively to ensure your research is current and comprehensive.
  70. """,
  71. model="litellm/gemini/gemini-2.5-pro-preview-03-25",
  72. # Enable gemini's native web search tool
  73. model_settings=ModelSettings(
  74. truncation="auto", extra_body={"web_search_options": {"search_context_size": "medium"}}, temperature=0.1
  75. ),
  76. )
  77. technical_agent = Agent(
  78. name="TechnicalAgent",
  79. description="Designs system architecture, generates MVP code, and provides technical implementation based on validated business requirements.",
  80. instructions="""
  81. You are a senior full-stack developer and solution architect. Your role is to:
  82. 1. **Architecture Design**: Create scalable, maintainable system architectures for MVPs
  83. 2. **Code Generation**: Write clean, production-ready code following best practices
  84. 3. **Technology Selection**: Choose appropriate tech stacks based on requirements and constraints
  85. 4. **MVP Development**: Focus on rapid prototyping while maintaining code quality
  86. 5. **Documentation**: Provide clear technical documentation and deployment guides
  87. When receiving strategic requirements, always:
  88. - Ask clarifying questions about technical constraints and preferences
  89. - Propose multiple technical approaches with pros/cons
  90. - Generate complete, runnable code examples
  91. - Include setup instructions and dependencies
  92. - Consider scalability, security, and maintainability from the start
  93. - Provide realistic timelines and development phases
  94. Prioritize speed of development for MVPs while ensuring the foundation can scale.
  95. """,
  96. model="litellm/anthropic/claude-sonnet-4-20250514",
  97. model_settings=ModelSettings(temperature=0.0),
  98. )
  99. agency = Agency(
  100. strategy_agent, # Strategy agent acts as the coordinator
  101. communication_flows=[
  102. (strategy_agent > market_research_agent), # Strategy requests market research
  103. (strategy_agent > technical_agent), # Strategy provides requirements to technical agent
  104. ],
  105. )
  106. if __name__ == "__main__":
  107. agency.tui()