Skip to content

Commit

Permalink
ADDED: API for investment risk analyst agent
Browse files Browse the repository at this point in the history
  • Loading branch information
AquibPy committed Jun 25, 2024
1 parent c425c7a commit e1f5b66
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 3 deletions.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,17 @@ percentage, missing keywords, and profile summary.
- **Error Handling for Transcripts:** If the transcript is not available, it returns a message indicating that the transcript is not available for transcription.
- **AI Summary Generation:** The AI model generates a structured summary of the transcript focusing on main points, critical information, key takeaways, examples or case studies, quotes, and actionable steps.

### 25. Investment Risk Analyst Agent

- **Route:** `/investment_risk_agent`
- **Description:** This API endpoint coordinates a team of AI agents to perform comprehensive investment risk analysis and strategy development.
- **Feature:**
- **Input Data:** Users can provide input data including stock selection, initial capital, risk tolerance, trading strategy preference, and news impact consideration.
- **Data Analysis:** The data analyst agent processes the input data to extract relevant financial information.
- **Strategy Development:** The trading strategy agent formulates a suitable trading strategy based on the analyzed data and user preferences.
- **Risk Assessment:** The risk management agent evaluates potential risks associated with the trading strategy and suggests mitigation measures.
- **Execution Planning:** The execution agent develops a detailed plan for executing the trading strategy, considering the assessed risks.

## Usage

Each endpoint accepts specific parameters as described in the respective endpoint documentation. Users can make POST requests to these endpoints with the required parameters to perform the desired tasks.
Expand Down
40 changes: 40 additions & 0 deletions api.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
from sendgrid.helpers.mail import Mail
from uuid import uuid4
from tech_news_agent.crew import run_crew
from investment_risk_analyst_agent.crew import run_investment_crew
from langchain.agents import AgentExecutor
from langchain_core.prompts import ChatPromptTemplate
from langchain_cohere.react_multi_hop.agent import create_cohere_react_agent
Expand Down Expand Up @@ -791,6 +792,45 @@ async def process_video(request: Request, video_url: str = Form(...)):
return ResponseText(response=summary)
except Exception as e:
raise HTTPException(status_code=500, detail=str(e))

@app.post("/investment_risk_agent",description="""
This route implements an investment risk analyst agent system using a crew of AI agents.
Each agent is responsible for different aspects of financial trading and risk management,
working together to analyze data, develop trading strategies, assess risks, and plan executions.
NOTE : Output will take more than 5 minutes as multiple agents are working together.
""")
@limiter.limit("2/30minute")
async def run_risk_investment_agent(request:Request,stock_selection: str = Form("AAPL"),
risk_tolerance : str = Form("Medium"),
trading_strategy_preference: str = Form("Day Trading")):
try:
input_data = {"stock_selection": stock_selection,
"risk_tolerance": risk_tolerance,
"trading_strategy_preference": trading_strategy_preference,
"news_impact_consideration": True
}
print(input_data)
cache_key = f"investment_risk_agent:{input_data}"
cached_response = redis.get(cache_key)
if cached_response:
print("Retrieving response from Redis cache")
return ResponseText(response=cached_response.decode("utf-8"))

report = run_investment_crew(input_data)
redis.set(cache_key, report, ex=10)
db = MongoDB()
payload = {
"endpoint": "/investment_risk_agent",
"input_data" : input_data,
"Investment_report": report
}
mongo_data = {"Document": payload}
result = db.insert_data(mongo_data)
print(result)
return ResponseText(response=report)
except Exception as e:
return {"error": str(e)}

if __name__ == '__main__':
import uvicorn
Expand Down
6 changes: 3 additions & 3 deletions investment_risk_analyst_agent/crew.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from investment_risk_analyst_agent.agents import data_analyst_agent,trading_strategy_agent,execution_agent,risk_management_agent
from investment_risk_analyst_agent.tasks import data_analysis_task,strategy_development_task,risk_assessment_task,execution_planning_task

llm=ChatGoogleGenerativeAI(model="gemini-1.5-flash",
llm=ChatGoogleGenerativeAI(model="gemini-1.5-flash-latest",
verbose=True,
temperature=0.7,
google_api_key=os.getenv("GOOGLE_API_KEY"))
Expand All @@ -29,7 +29,7 @@
verbose=True
)

def run_crew(input_data):
def run_investment_crew(input_data):
result = financial_trading_crew.kickoff(inputs=input_data)
return result

Expand All @@ -41,4 +41,4 @@ def run_crew(input_data):
'trading_strategy_preference': 'Day Trading',
'news_impact_consideration': True
}
print(run_crew(input_data=financial_trading_inputs))
print(run_investment_crew(input_data=financial_trading_inputs))

0 comments on commit e1f5b66

Please sign in to comment.