How I Made 3 AI Agents Work Together for Smarter Reports!

Build a three-agent AI pipeline using CrewAI that analyzes SEC filings, regulatory changes, and market sentiment to generate investment reports. One agent searches the web, another queries 372,000 SEC documents via Snowflake, and a third synthesizes findings into actionable recommendations for portfolio companies.
Chapters
Hey there. In this video, I'm going to show you exactly how to build a regulatory intelligence system using 3 CrewAI agents. One of them will be analyzing web data using Serper to be able to search the web. Another will query over 372,000 SEC filings through the Snowflake MCP server. And a third will analyze everything that has been generated by the previous 2 agents and combine everything into a professional report. So let's get started. All right. So before we actually get to the code and looking at how you can connect your Snowflake MCP to CrewAI. Let's start with the final report. Once we've put everything together, we have the code running. When we run an example, what does the final output look like? And this is it right here. It's, uh, I ran one here for FDA substitute regulatory impact report. So basically what I did, I went and found a regulation from FDA that was released, and it's this number right here, RIN, um, that full number, use of salt substitutes to reduce sodium content in standardized foods. So I'm guessing they're trying to replace the regular sodium content within food using some salt substitutes. its use because people are probably having a lot of high blood pressure and other— some side effects from using sodium. From that, I gave it that regulation and also gave it industry to focus on. So mostly manufacturing, food manufacturing companies. Since we have already indexed all the SEC filings within the last year and it's already saved within Snowflake database, so all I need to do is now give it to the agent, which the first agent does first research on all. And here it is right here. The first agent just goes through all the regulatory intelligence, figures out this is the regulation link you gave me. It's just going to scrape all the data from that, read it, and also just do extra searches on that regulation to figure out all the information. And then after that, it triggers the second agent, which the second agent now has access to our data that's in Snowflake using the Snowflake MCP server. And I created 2 tools within Snowflake, which it already comes with the MCP server, but I had to like configure it a little bit. So there's one Cortex Search and Cortex Analytics. So the search one does what it— what you can tell already, semantic search over all the material that I've saved in the database. And then the analytics will do the analysis on top of that data that I have as well. So what this second agent does, so the first one we know it does the analysis fetching on the web. This second one, based on the research that this one has done and to begin with, like, hey, this is the regulation. It goes ahead and tries to find companies that that first regulation will probably affect or is affecting within the Snowflake SEC filings data. And you can imagine that being mostly food manufacturing companies that will be affected in there. And so tries to find all of them, look at all their filings, if there was anything mentioned there that could potentially make them be in trouble or really wary if I'm I'm an asset manager, for example, for an asset management company, maybe I'm assigned to like several companies that I'm in charge of like making sure like, okay, I follow up all the details about them every day. I'm always on top of it. So if I need to rebalance the portfolio for customers, for example, I would need to see this company is probably going to be exposed by this new regulation and they're going to— their shares are going to tank. So I want to save up my, you know, you have fiduciary responsibility to save your customers and then make profit in a sense. So in this case, that's what this second agent is doing, trying to find all those companies that are affected by that regulation. And then the final agent here basically takes all the information that's been generated by these first 2 and then also does some extra analysis on the wearables. So just going and fetching any market sentiments, any news that's come out about that regulation or any of those companies, for example, and then generates a final report, which is this. This is the final report that we are looking at right now. And so if we look at the final report, we see the regulatory analysis here section, just kind of going over what that regulation is about, specific details. And also there's a section here for portfolio company analysis. So it starts off with the high-risk direct impact companies that are found within that SEC and the The reason here, I give it only 3, maximum of 3 to search, maximum of 3 companies, just to save upon costs for me querying that database within Snowflake. But you can just free range, let it access those 320-something thousand files that I actually had to save within my, or index within my database. And I'm going to show you that in a second. And the first one here was Palmetto Gourmet Foods, and they already got their CIK number. And it goes over like their business, direct food manufacturer, filings analysis, 79 filings were found. And this is data from just the last 1 year. of filings from SEC because it's a lot of files. That's a lot. And then there's disclosure intensity. There's risk assessments, products likely subject to standard of identity modifications. And then there's investment implications, may require R&D investment for product reformulation. So that's interesting already. And then there's medium risk, Darling Ingredients Incorporated. And then there's just also their stuff there, agri-food technology, ingredient supplier and processor. And then there's also Safe Foods. It's agri-food technology, post-harvest treatments. So So already kind of identified some of the things they might have there as well. Market trends, sentiment analysis, and this is where it went and got the sentiment analysis as well. Competitive landscape. Then it did risk assessment metrics. So this is pretty good 'cause then it's able to give you some time horizon, secondary impact, compliance cost, supply chain positioning, innovation opportunities, primary impact, product reformulation, increased ingredient demand, consumer trend alignment, and things like that. And then it's kind of giving you a recommendation here. Immediate actions, 0 to 6 months, monitor rule finalization, track FDA comment period and final rule publication, company communications, supply chain mapping. and all that stuff. So that's kind of like the full report right there that it generated for us. So it looks pretty good so far. And this is just on 3 companies 'cause I restricted it to 3. Imagine if you had just left it open, you could probably just access any even companies that I hadn't thought about that probably will be affected by these regulations. So that's just a good use case potentially for an asset manager at some company at the moment. Next portion, now we're going to go over the code and look at how this was implemented with CrewAI and the Snowflake MCP server. Now I'll do a quick walkthrough of how to set up everything and then we're going to go to the code, which is the last piece really. And so here I have a README within the root of this folder that you can— that will help you kind of walk you through this entire steps. And here I'm just describing what the project is about. And then here is kind of like the system overview. You have some of the stuff that we will need here. So CrewAI for the orchestration of the agents, Snowflake MCP, and this will give you more of like a direct connection to your enterprise data warehouse where you have the data. If you create an account, you probably get some sample database where there's some sample data you can use, but there's one that I used in this if you want to follow along. If you go to their marketplace, and I'm going to show you a picture down there, you can get these SEC filings. It's under, uh, Cyberson. Cyberson was a company that was supplying some of this data to Snowflake, and I think it's still So you get more real-time SEC data, financial data there as well. So that's what I used. It's free. You can just kind of clone it to your, or get it to your environment within stuff like Data Warehouse. And so you can use it. And then also Serper DevTool. This is just for web search. It's also free. They give you a bunch of credits. And so this is kind of how our architecture looks like. So you can imagine it here. We start off with a regulatory URL input. You give it the URL and maybe you select also the industry that you want it to focus on, or you can leave it blank and it will kind of figure it out itself. And then the first agent, what it does, it does regulatory intelligence, is uses Serper DevTool here to search the web. And then once it's done, it goes to the second agent, which is the SEC filing analyst. And SEC filing analyst looks at the— uses the Snowflake MCP SEC database that I already had in my Snowflake account and uses this MCP to be able to access that data. And what it does, there's an analytics engine, basically a Cortex analyst that does analysis of the data if you want to do some analysis on it. And then there's also a Cortex search, basically does search over that, of those filings in that database. So it searches over using semantic search there as well. And then once this is done and it's using that tool, it it to the market news analyst, which kind of does market research on the web, figures out what's the sentiment, what people are saying. And then finally, when it's done, it generates the professional investment report that we looked at a few moments ago. And so if we look at this and then go back down here to the requirements, how do you get set up? Some of the things that I want to highlight here, of course, there's prerequisites, a simple few there, should be pretty direct. And then time investment. This is something that it took me quite a bit here to set up, was this is Snowflake configuration. If you don't have a Snowflake account, you've never created one before, that might take you a minute to just kind of set that part up. It's a one-time thing. You do it and you'll be good. And then the other piece here is the Cortex Search indexing. So when you get the data, you want to index it first so that the Cortex Search is able to do search over it using RAG at the end of the day. So with the data that I used, which is from the SEC filings, I think I indexed over 372,299. And that's just data of all the SEC filings that I got. And this is just only for the past one year. And so you can imagine if it's longer, then it's probably a matter of days before it gets indexed. So the indexing took around 49 minutes to index all that data. I'm sure this probably would get faster over time and maybe I just need to configure something in there to use a better compute there as well. But this is just based on my experience. And then there's also testing and validation. You don't really need much of that at all. If it works, you'll see. If it doesn't, you will know. But following this tutorial that I set up should help you a lot. And once you clone that, there's also, you need to get the secrets from Snowflake. So if you go to your account, it's pretty direct. I've given you some instructions here on how to do that. And I've also created a .env file example here where all this is preset in there. All you need to do is just replace them and then delete this .example. and just leave the .env to look like this. And then your agent is able to use those secrets there as well. Now, this is how you set up your Snowflake account. Uh, there's instruction there. I don't want to go into that too much because there's so much material out there. They have a really good documentation on that, and also they have some videos on that as well. But this is where I got the SEC filings data. So you would go to Marketplace. So if once you have signed into your Snowsight account, you will see here on the side that there's a Marketplace. If you click Marketplace, and Marketplace is where they have just a bunch of different datasets that might be interesting to you. Some of them are paid, some of free. This is free. For example, this is the Snowflake public data products and these are the SEC filings. And I think these were supplied by Syverson. And so if you come here to the database, you pick the database that you've already created. I created a database, but this database is the one that for SEC filings, and then you pick your role and then you get it. The first thing I wanted to do was just explore the data, figure out, you know, what's up with the data. And so you can see this is my databases that I have there. This was the SEC filings data. And what I did, I ran this query to kind of figure out, okay, what's— you're just going to preview the data, see what's in there. And this is what it gave me. I was able to look at some sample data in there as well. And then after that, we need to set up the Cortex Search, which I just told you there to enhance the analytics better. And so you need to enable that first on your account. And so what I did here, I cloned that entire dataset here and I created a new database and basically added all the datasets to that database. So I have more control over that because I have more control over that database. I can do more like read and write, change stuff in there as well. So that was the purpose of that. After that, I was able to set to use this to index all the data that's within that database. And here you see these are my worksheet. I had one for exploring, of course, their data, which is up there, and then creating the table and loading the data and then creating the database. And then this one is the Cortex setup. If you want, I can share these examples, but it's pretty straightforward on how to do this as well on their website. But this took about 49 minutes for me to run. And you can see here, 49 minutes and 57 seconds to index all of them. So this one was finished just to verify that everything was done and finished. But here was more of like making sure that I enabled tracking. And this is enable monitoring performance and usage of the Cortex search here and query tracking. Specifically, so here's where I just verify that the data was indexed, and you can see that that was 372,299 documents that were indexed. And yeah, that's quite a lot actually. Now that's pretty fast if you just factor in time-wise how long it takes to do that. Now indexing time, yep, again that's about 49 minutes. Very, you know, very, very reasonable for that amount of data. And then you have progress monitoring. Of course, there's a lot of things you can do on the Snowflake platform itself that I won't be able to cover in this tutorial, but just to give you a glimpse of what that is, another very important aspect that I had to do was the semantic model configuration. At the moment, what I did, I just used the YAML format. I created a YAML file and you can find that here as well. So this is the entire semantic. Basically, I'm just kind of giving my agent a cheat sheet on what to do with the data that I already have there. And I have some details here as well. Basically, just going to tell it, if you want to query the data, give it some examples so that when it's doing stuff, it doesn't have to try several times and fail and cost me tokens-wise. So this is why I had to use that. So you can create that. I created that, copy mine. I already added it to the Reaper as well. Copy, use the same thing. And you can just kind of even use the models to be able to prompt and help you refine for whatever dataset that you have there. And so that's the point of that. If you keep going down here, agent configuration, I'm going to go through that here in a second. And then there's just an example of how to pass in the input there. Some extra stuff there that I added. So feel free to read through this. And I think here's another important piece about just setting up the Snowflake MCP server and some of the troubleshooting issues that I ran into that I think would be very important for you when you're following along with this demo. Let's go back to this section, which I think is important before we run our agent here. Of course, this is our crew.py file. We do have all our agents here. And we've already kind of added them here in the config. So the YAML, so you have the 3 agents, intelligence analyst, security analyst, and the news analyst. And then same thing here, we have 3 tasks for each of those agents. So you create the task and you assign the agent as well. And then once those are done in this crew.py file, we import them here and actually instantiate them with the agent class definition for the agents and then task decorator for all the tasks as well. And then we put them together here in a crew. But the other crucial piece, right? Each of the agents need a tool. So for example, this regulatory analyst needs the Serper DevTool. For the portfolio security analyst needs the Snowflake MCP server tool. So here's where you pass in. But how do you instantiate the MCP server tool for Snowflake, right? This is where you do that. So first of all, you need to bring in your Snowflake credentials and you also need the Snowflake demo config. And I'm going to show you that in a second here. That just kind of guides the agent to get to your account. But here is kind of like the meaty chunk of kind of configuring a Snowflake MCP server. Once you set this up and you can just use this as is, basically you're passing the command uvx and then all the arguments here, This is already directly from Snowflake. It's already provided. You just need to change your config path, which will take it from here. And I already saved that config file. I'll show you where that is. And then the username account and the PAT, which is your personal access token. All of them are here and I've already saved them in our .env file. So let's go to this demo config file before we run it. So if you go to this demo config file, so this is where you're just listing all the services that you want your agents to use, all the tools. So first of all, yeah, we have SCC filing search. That's the name we're going to give to this service. And this is the search service to just be able to search our documentation. You can add many of them if you have different services, but for this we're just using the SCC filing And then just giving a description also. Search service that provides semantic search over that many SEC filings that we index from this date and this date. And database, we also MCP demo. That's my database within Snowflake. And then the public schema name, it's public within my Snowflake database as well. And then we have the columns that are within my database. And then I limited it to 3 here, which is like limit to 3 outputs that it returns back. And I reduced it so that it could just reduce the context. Because when I was using OpenAI model for this, it kept running out of the context window because of the materials that was being returned. But now that I'm using Gemini, I could maybe Let's try 5. If it fails, I'll reduce it. So in this case, it might just reduce it to that. And this limit parameter was added recently by Snowflake. So you can up this however much you want or reduce it. I think it's 1,000 if I'm not wrong, the highest limit pending verification. But I think that's the goal of this. I added 3 to reduce the amount of context so that it doesn't run out of the context window. But I've changed it to 5 since Gemini has a bigger context window. And then we have your analyst services that I created as well. And in this one, I just created an SEC filing analytics service. And then it's a semantic model, which we passed it here. Which I'm going to show you that in a second. And then the description here of what it does. So regulatory risk monitoring and compliance analysis service for SEC filings, ask questions about filing patterns, regulatory events, risk categories, filing frequency and all that. So being able to do some math a little bit. And so this is where I defined all that semantic model. And like I mentioned, this way you're basically guiding the agent to reduce the amount of work it has to do. You're kind of giving it a cheat sheet in a sense. And this is where I'm even like even telling it, this is an example of a query you could run to do this specific thing. And then you use that as an example. So that way we're reduce the amount of time our agent has to try different things before we get it right. So trying to reduce that time so that just like one shot, get it done, move on, save us on tokens and also makes it a fast and smooth experience for the user. So now that we've seen those, those are the main portions of our code base and I'll share this code. So you'll feel free to go ahead and run it and then play around with it. So I'm going to find a link to one of the latest regulations. We're going to pass an industry and run it and we'll see what the output becomes. So for this run, I'm going to change up things a little bit. Instead of using FDA, I'm going to use SEC and I'm going to pick this first regulation here. So final rule here, daily computation of customer and broker-dealer reserve requirements under the broker-dealer customer protection. I'm not sure what exactly is going on there, but let's just use that. Now that we have the link of the regulation from SEC, now let's go ahead and run our agent. And we're going to give it that link to the regulation and also give it the industry as financial services. So this is going to take a minute here to kickstart. And let's just wait. I think my Wi-Fi is a little bit slower now. All right. So let's give it the link to the regulation and let's do financial services. And it's going to kick up. So it's going to take a while to run it here. I'm going to speed up this portion and then we'll catch you on the other side. So the agent kicked off here. It's already going. You see the first agent is doing some research. This is the text that it passed in. It says SEC, the number, final rule analysis. It went and gathered some data from there and it also asked another query. So SEC government tried to find that exact regulation there, did extra searches, of course. And the agent is thinking through this and thinking, what is the best query I can ask to get a good output essentially. And that's what it's doing. It's just going and getting that there directly and it's trying to fill as much context as possible. And then once that's done, you can see here that it goes and the second agent here essentially is going and trying to use the MCP from Snowflake now. So you can see it's already going through it and asking questions. And you can see here daily computation of customer broker dealer service requirements or customer protection. And it's going through it and you can see like it already gathered some data directly just using semantic search from Snowflake, and he's using the Cortex search, and it's gotten some stuff, and it's still going and still thinking. So while that's still going, I'm going to speed up some portions of this video, um, so don't mind me. All right, so our agent is finished. It's finished the job. So you see here, it's already gone and generated the final report. But now let's go ahead and review what it just did. And if we go here to outputs, we'll see the— first of all, the raw output from Snowflake. Let's see how that matches that. And now this should be in Markdown. If we see here, these are Based on SEC filings, Stifel Financial Corporation shows a high degree of regulatory exposure concerning the new SEC regulation on daily computation of reserve requirements for broker-dealers. Their filings explicitly mention the use of alternative methods for net capital calculations under rule, whatever that is, and acknowledge the upcoming requirement for daily computation, indicating awareness and preparation. So the company is already preparing for that, and I think they have until from like December 2025 to June 2026 or something of the sort. And then there's also Robinhood, while also significant broker-dealer, has shown a lower ratio of relevant regulatory mentions, so 11.6%, and has not specifically referenced the daily computation requirements or the alternative methods in relation to these regulations in analyzed filings. And so what it found from all of the documents that it could gather was just 2 companies, so Stifel Financial Corp and Robinhood Markets Inc. So filing analysis, it generated one for Financial Corp, found exactly where in their documentation they're mentioning this within their filings. And then the Robinhood Here they mentioned a reserve requirement and net capital generally, but not specific disclosures regarding the daily computation mandates or alternative methods were found in analysis. My guess is these companies already know what that is. They're going to readjust or assemble. They're already doing it because I think they were required to do it weekly. Now they are required to do it daily, and that's going to be the new rule that's coming out. So that's interesting. And then there's risk rankings there. There's historical patterns, a filing sure pattern of acknowledging and preparing for regulatory changes related to daily competition alternative methods. Robinhood filings indicate general compliance but no specific historical pattern related to this regulatory particular daily competition rule. And then there's portfolio impact. So Stifel Corp potential impact on operation, operational costs and compliance strategies. Robinhood Markets indirect impact possible due to industry-wide shifts. Future filings should be monitored. Affected companies, of course, I think it repeated itself there a little bit. No, I don't think it did. So that's good. Then there's just kind of like details here. Filing analysis. This is something that asset manager will be interested in or even you if you're trying to maybe figure out this new regulation came out, Could DAI offer services to these financial services if they don't have that to kind of help them even be compliant with this regulation, right? So that could be a consulting gig right there that you can identify from this. So you can see this already, Robinhood Markets, but I don't think this is a good, if you're thinking about this as a consulting opportunity, it might not be 'cause I think they can spin this up really easily internally for some of the companies. And then there's historical patterns, portfolio impact, all this. And this is just like the raw data that it got from the financial filings and then analysis there as well. Kind of goes through what it found within the files itself. And once that is done, let's go ahead and now look at the final report. So here's the final report it generated. So daily competition of customer, of course that's a rule. Daily competition of broker dealers. Executive summary: this report analyzes the impact of SEC amended customer protection, specifically focusing on the requirement for daily competition of deposits. Okay, of course. Okay, so I think here it says affected firms, primarily large broker dealers utilizing the alternative method and exceeding a $500 million asset threshold, face significant operational and technological challenges in adapting to daily calculations. While the industry supports enhanced investor protection, the implementation necessitates substantial investment in IT systems and compliance oversight. So like I said, opportunities, right? But they're big investment firms. If you offer them this solution, they probably will take it. But I also feel like their IT should be able to spin this up pretty easily from weekly to daily. So key findings here, there's a market opportunity that they found and then industry response, portfolio impacts, investment thesis for firms like Stifel, potential impacts on operational costs, compliance strategies warrant close monitoring. So it kind of walks you through basically the methodology there and then data sources where you found it. Summary rule industry expert and stakeholder commentary. For example, SIFMA statements. I think that's we went and found and read through that. And then there's also regulatory analysis looking at the regulation, what exactly that is. And I think that's what I said earlier. Final rule adopted with a compliance date extended by six months to June 30, 2026. So that's very active at the moment. And then you have the key regulatory provisions. Of course, portfolio company analysis. So this is the risk impact. So Stifel there as high, and then Robinhood as medium. And then you have market sentiment analysis, of course, from what people are saying. And then we have this risk assessment we saw in the initial one. Primary impact, increased operational compliance, potential direct, indirect operational adjustments there as well. And so if we go down, it goes all the way to immediate actions need to be taken less than the next 6 months, long-term outlook, monitoring metrics and all this. I don't think this is a major regulation that's going to shift how they shift markets or anything for that It's just an operational thing that they have to do internally. But the goal of this demo is really to show you if there was a regulation out there that's coming up that's significant and that's going to cause basically a major shift in a lot of most companies and things that happen, then you can see that being very important to be able to have this analysis here. And if there's somebody doing this manually right now, reading through them, that's a lot of time to spend to do that. So this cuts that down really easily. So with that, I'm going to share the link to everything that we just went through here in the demo once we're done. But this is all I wanted to share and show you how to do this yourself. If you have any questions, please leave it in the comments. Also, don't forget to subscribe for more content like this. We're going to go deeper into agents and how to build agents and also using Snowflake and other MCP servers out there as well. So until next time, peace. Peace.
More from Tony

Summarize Videos and Research Companies with CrewAI + Gemini Models [Quickstart Guide]

How to Make Your AI Agents More Reliable with CrewAI Task Guardrails (Step-by-Step Tutorial)








