-
-
Stock Compare RT - AI Agent built using Tavily and Lllama
-
Stock Compare RT - List of over 10,000 stocks to choose from
-
Stock Compare RT - Source links included, Investment recommendation given
-
Stock Compare RT - Top 10 investment factors to compare your chosen stocks with
-
Stock Compare RT Report which you can download
Stock Compare RT is an AI investment agent that compares any pair of 10,000+ stocks based on a top 10 investment factor and gives an investment recommendation. The stock comparison is based on "RT" (real-time) Internet search using Tavily to get the latest relevant financial data, and Llama to make the recommendation. Also, a summary of the whole analysis and an optional report are generated (by Llama). The advisor user can also enter their own custom investment factors to do the comparison, such as comparing AI strategy or latest analyst sentiment about Trump tariff policy impact. This agent gives its advisor user the combination of latest financial data and expert AI analysis made possible through Tavily and Lllama.
All prompts used by the agent app are stored in 14 prompt files. This allows prompt tweaks without touching the code. I crafted 10 of the prompts to be used as search queries that Tavily could also use in generating its LLM response, enabled through the advanced setting of its search API's include_answer parameter. I set max_results in the API to return the top 5 results from the period I set for the time_range parameter: 1 year. Tavily automatically sorts the results by date, ensuring the agent gets the most recent data to use. To ensure the relevance of the results, I set the topic parameter to finance, conveniently one of the 3 topics supported by Tavily. Another convenience is that citations are included in the generated response, allowing the advisor user to drill-down on the links and confirm against hallucinations.
For comparing the investment factor results from Tavily to give a recommendation, I chose to use Llama 3.3 70B Instruct over other open-source models (including other Llama models) because I found from testing it gave the best quality analysis of financial data while also not taking too long to do that analysis. From my logs, the model takes about 2.5 seconds for the comparison and about half a second for the summary. Also I do the comparisons of the 2 stocks concurrently in separate threads, so you as the user don't need to wait for 5 seconds, you only wait 2.5 seconds to see the 2 comparisons displayed side-by-side in the UI, with each comparison displayed as soon as it's returned by Llama (thanks to the async yield support in Gradio, the UI framework I use). Even though a 2.5 second wait isn't too long, it's still long enough for a user to be distracted and go off to another browser tab. So when the summary is displayed, I do text to speech (TTS) to have the summary read aloud. This audibly notifies you the comparison of the 2 stocks you wanted is done, and you can check out the analyses for stock A and B, their detailed comparison, and the summary with the recommendation.
For generating the optional report which you can download to save your stock comparison and recommendation, I chose to use Llama 3.1 8B Instruct. I didn't stick with 3.3 70B because the task of generating the report doesn't require inference, it's only leveraging the LLM's training to format the comparison and recommendation results in a clear and attractively styled investor report. I made this pragmatic choice because using the less powerful 3.1 8B model is faster and cheaper than 3.3 70B.
In my testing I found the Tavily API occasionally returns a 502 Bad Gateway error. To avoid this intermittent error from interrupting the user experience, I used the Tenacity library to implement a retry with exponential backoff. The number of retries is configurable and defaults to 2, which should be enough to bypass intermittent errors. I also use Tenacity to implement a retry for my calls to Llama 3.3 and 3.1, although the algorithm is based on the rate limit documented by the LLM cloud provider, Nebius. I actually didn't see the 429 Rate Limit error in my calls to Llama because my testing didn't exceed the requests per minute threshold in my Nebius account, but I still implemented the retry proactively in case Stock Compare RT catches fire and tons of investment advisors use it :)
This agent is a useful, time-saving tool for advisors in the era of AI to compare stocks using the combined strengths of Tavily and Llama.
Built With
- docker
- google-cloud
- gradio
- langchain
- llama
- nebius
- prompt-engineering
- python3.12
- tavily
- tenacity
- text-to-speech

Log in or sign up for Devpost to join the conversation.