Merge pull request #41 from Madhuvod/ai-startup-agency-3rd
Fixed persistent issues in ai_services_agency/agency.py
This commit is contained in:
commit
9479080ca4
1 changed files with 102 additions and 60 deletions
|
|
@ -1,54 +1,73 @@
|
||||||
from typing import List, Literal, Dict, Optional
|
from typing import List, Literal, Dict, Optional
|
||||||
from agency_swarm import Agent, Agency, set_openai_key, BaseTool
|
from agency_swarm import Agent, Agency, set_openai_key, BaseTool
|
||||||
from pydantic import Field
|
from pydantic import Field, BaseModel
|
||||||
import streamlit as st
|
import streamlit as st
|
||||||
from instructor import OpenAISchema
|
|
||||||
import asyncio
|
|
||||||
|
|
||||||
# Tools
|
|
||||||
class AnalyzeProjectRequirements(BaseTool):
|
class AnalyzeProjectRequirements(BaseTool):
|
||||||
"""Tool for comprehensive project analysis"""
|
project_name: str = Field(..., description="Name of the project")
|
||||||
project_description: str = Field(..., description="Client's project description")
|
project_description: str = Field(..., description="Project description and goals")
|
||||||
business_requirements: str = Field(..., description="Business requirements and goals")
|
project_type: Literal["Web Application", "Mobile App", "API Development",
|
||||||
budget_constraints: Optional[str] = Field(None, description="Budget constraints if any")
|
"Data Analytics", "AI/ML Solution", "Other"] = Field(...,
|
||||||
|
description="Type of project")
|
||||||
def run(self):
|
budget_range: Literal["$10k-$25k", "$25k-$50k", "$50k-$100k", "$100k+"] = Field(...,
|
||||||
prompt = f"""
|
description="Budget range for the project")
|
||||||
Analyze this project request:
|
|
||||||
Project: {self.project_description}
|
class ToolConfig:
|
||||||
Business Requirements: {self.business_requirements}
|
name = "analyze_project"
|
||||||
Budget Constraints: {self.budget_constraints}
|
description = "Analyzes project requirements and feasibility"
|
||||||
|
one_call_at_a_time = True
|
||||||
|
|
||||||
|
def run(self) -> str:
|
||||||
|
"""Analyzes project and stores results in shared state"""
|
||||||
|
if self._shared_state.get("project_analysis", None) is not None:
|
||||||
|
raise ValueError("Project analysis already exists. Please proceed with technical specification.")
|
||||||
|
|
||||||
Provide a comprehensive analysis including:
|
analysis = {
|
||||||
1. Project scope and complexity
|
"name": self.project_name,
|
||||||
2. Estimated timeline
|
"type": self.project_type,
|
||||||
3. Key deliverables
|
"complexity": "high",
|
||||||
4. Technical requirements
|
"timeline": "6 months",
|
||||||
5. Potential challenges
|
"budget_feasibility": "within range",
|
||||||
"""
|
"requirements": ["Scalable architecture", "Security", "API integration"]
|
||||||
return self._llm.invoke(prompt)
|
}
|
||||||
|
|
||||||
|
self._shared_state.set("project_analysis", analysis)
|
||||||
|
return "Project analysis completed. Please proceed with technical specification."
|
||||||
|
|
||||||
class CreateTechnicalSpecification(BaseTool):
|
class CreateTechnicalSpecification(BaseTool):
|
||||||
"""Tool for creating detailed technical specifications"""
|
architecture_type: Literal["monolithic", "microservices", "serverless", "hybrid"] = Field(
|
||||||
requirements: str = Field(..., description="Project requirements")
|
...,
|
||||||
tech_context: Optional[str] = Field(None, description="Additional technical context")
|
description="Proposed architecture type"
|
||||||
|
)
|
||||||
def run(self):
|
core_technologies: str = Field(
|
||||||
prompt = f"""
|
...,
|
||||||
Create technical specifications for:
|
description="Comma-separated list of main technologies and frameworks"
|
||||||
Requirements: {self.requirements}
|
)
|
||||||
Technical Context: {self.tech_context or 'None provided'}
|
scalability_requirements: Literal["high", "medium", "low"] = Field(
|
||||||
|
...,
|
||||||
|
description="Scalability needs"
|
||||||
|
)
|
||||||
|
|
||||||
|
class ToolConfig:
|
||||||
|
name = "create_technical_spec"
|
||||||
|
description = "Creates technical specifications based on project analysis"
|
||||||
|
one_call_at_a_time = True
|
||||||
|
|
||||||
|
def run(self) -> str:
|
||||||
|
"""Creates technical specification based on analysis"""
|
||||||
|
project_analysis = self._shared_state.get("project_analysis", None)
|
||||||
|
if project_analysis is None:
|
||||||
|
raise ValueError("Please analyze project requirements first using AnalyzeProjectRequirements tool.")
|
||||||
|
|
||||||
Provide detailed technical analysis including:
|
spec = {
|
||||||
1. Architecture type and patterns
|
"project_name": project_analysis["name"],
|
||||||
2. Core technologies and frameworks
|
"architecture": self.architecture_type,
|
||||||
3. API requirements
|
"technologies": self.core_technologies.split(","),
|
||||||
4. Database design
|
"scalability": self.scalability_requirements
|
||||||
5. Security requirements
|
}
|
||||||
6. Scalability considerations
|
|
||||||
7. Development effort estimation
|
self._shared_state.set("technical_specification", spec)
|
||||||
"""
|
return f"Technical specification created for {project_analysis['name']}."
|
||||||
return self._llm.invoke(prompt)
|
|
||||||
|
|
||||||
def init_session_state() -> None:
|
def init_session_state() -> None:
|
||||||
"""Initialize session state variables"""
|
"""Initialize session state variables"""
|
||||||
|
|
@ -61,7 +80,7 @@ def main() -> None:
|
||||||
st.set_page_config(page_title="AI Services Agency", layout="wide")
|
st.set_page_config(page_title="AI Services Agency", layout="wide")
|
||||||
init_session_state()
|
init_session_state()
|
||||||
|
|
||||||
st.title("AI Services Agency 👨💼")
|
st.title("🚀 AI Services Agency")
|
||||||
|
|
||||||
# API Configuration
|
# API Configuration
|
||||||
with st.sidebar:
|
with st.sidebar:
|
||||||
|
|
@ -136,11 +155,19 @@ def main() -> None:
|
||||||
# Create agents
|
# Create agents
|
||||||
ceo = Agent(
|
ceo = Agent(
|
||||||
name="Project Director",
|
name="Project Director",
|
||||||
description="Experienced project director with expertise in technical project evaluation.",
|
description="You are a CEO of multiple companies in the past and have a lot of experience in evaluating projects and making strategic decisions.",
|
||||||
instructions="""
|
instructions="""
|
||||||
- Lead project analysis and strategic planning
|
You are an experienced CEO who evaluates projects. Follow these steps strictly:
|
||||||
- Evaluate project feasibility and resource requirements
|
|
||||||
- Make high-level decisions on project direction
|
1. FIRST, use the AnalyzeProjectRequirements tool with:
|
||||||
|
- project_name: The name from the project details
|
||||||
|
- project_description: The full project description
|
||||||
|
- project_type: The type of project (Web Application, Mobile App, etc)
|
||||||
|
- budget_range: The specified budget range
|
||||||
|
|
||||||
|
2. WAIT for the analysis to complete before proceeding.
|
||||||
|
|
||||||
|
3. Review the analysis results and provide strategic recommendations.
|
||||||
""",
|
""",
|
||||||
tools=[AnalyzeProjectRequirements],
|
tools=[AnalyzeProjectRequirements],
|
||||||
api_headers=api_headers,
|
api_headers=api_headers,
|
||||||
|
|
@ -152,9 +179,16 @@ def main() -> None:
|
||||||
name="Technical Architect",
|
name="Technical Architect",
|
||||||
description="Senior technical architect with deep expertise in system design.",
|
description="Senior technical architect with deep expertise in system design.",
|
||||||
instructions="""
|
instructions="""
|
||||||
- Design technical architecture and evaluate feasibility
|
You are a technical architect. Follow these steps strictly:
|
||||||
- Make technology stack recommendations
|
|
||||||
- Review technical specifications
|
1. WAIT for the project analysis to be completed by the CEO.
|
||||||
|
|
||||||
|
2. Use the CreateTechnicalSpecification tool with:
|
||||||
|
- architecture_type: Choose from monolithic/microservices/serverless/hybrid
|
||||||
|
- core_technologies: List main technologies as comma-separated values
|
||||||
|
- scalability_requirements: Choose high/medium/low based on project needs
|
||||||
|
|
||||||
|
3. Review the technical specification and provide additional recommendations.
|
||||||
""",
|
""",
|
||||||
tools=[CreateTechnicalSpecification],
|
tools=[CreateTechnicalSpecification],
|
||||||
api_headers=api_headers,
|
api_headers=api_headers,
|
||||||
|
|
@ -166,9 +200,8 @@ def main() -> None:
|
||||||
name="Product Manager",
|
name="Product Manager",
|
||||||
description="Experienced product manager focused on delivery excellence.",
|
description="Experienced product manager focused on delivery excellence.",
|
||||||
instructions="""
|
instructions="""
|
||||||
- Manage project scope and timeline
|
- Manage project scope and timeline giving the roadmap of the project
|
||||||
- Define product requirements
|
- Define product requirements and you should give potential products and features that can be built for the startup
|
||||||
- Ensure product quality
|
|
||||||
""",
|
""",
|
||||||
api_headers=api_headers,
|
api_headers=api_headers,
|
||||||
temperature=0.4,
|
temperature=0.4,
|
||||||
|
|
@ -235,16 +268,25 @@ def main() -> None:
|
||||||
try:
|
try:
|
||||||
# Get analysis from each agent using agency.get_completion()
|
# Get analysis from each agent using agency.get_completion()
|
||||||
ceo_response = agency.get_completion(
|
ceo_response = agency.get_completion(
|
||||||
message=f"Analyze this project proposal: {str(project_info)}",
|
message=f"""Analyze this project using the AnalyzeProjectRequirements tool:
|
||||||
recipient_agent=ceo,
|
Project Name: {project_name}
|
||||||
additional_instructions="Provide a strategic analysis of the project using the AnalyzeProjectRequirements tool to make best possible strategic decisions for the project."
|
Project Description: {project_description}
|
||||||
|
Project Type: {project_type}
|
||||||
|
Budget Range: {budget_range}
|
||||||
|
|
||||||
|
Use these exact values with the tool and wait for the analysis results.""",
|
||||||
|
recipient_agent=ceo
|
||||||
)
|
)
|
||||||
|
|
||||||
cto_response = agency.get_completion(
|
cto_response = agency.get_completion(
|
||||||
message=f"Analyze technical requirements: {str(project_info)}",
|
message=f"""Review the project analysis and create technical specifications using the CreateTechnicalSpecification tool.
|
||||||
recipient_agent=cto,
|
Choose the most appropriate:
|
||||||
additional_instructions="Evaluate technical feasibility using CreateTechnicalSpecification tool, eventually building a scalable and efficient tech product for the startup."
|
- architecture_type (monolithic/microservices/serverless/hybrid)
|
||||||
|
- core_technologies (comma-separated list)
|
||||||
|
- scalability_requirements (high/medium/low)
|
||||||
|
|
||||||
|
Base your choices on the project requirements and analysis.""",
|
||||||
|
recipient_agent=cto
|
||||||
)
|
)
|
||||||
|
|
||||||
pm_response = agency.get_completion(
|
pm_response = agency.get_completion(
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue