Get AI summaries of any video or article — Sign up free
Building News AI Agents Using CrewAI And Google Gemini Pro LLM Models thumbnail

Building News AI Agents Using CrewAI And Google Gemini Pro LLM Models

Krish Naik·
5 min read

Based on Krish Naik's video on YouTube. If you like this content, support the original creators by watching, liking and subscribing to their content.

TL;DR

Create a Python 3.10 virtual environment and install dependencies from requirements.txt before building the CrewAI agents.

Briefing

The core takeaway is that a multi-agent workflow can generate a structured “news-style” report by chaining specialized agents—one that researches and one that writes—while using Google Gemini Pro (via LangChain) instead of OpenAI. The setup matters because CrewAI’s default examples assume an OpenAI API key, so swapping in Gemini Pro enables a practical, lower-friction path for building agentic applications with a non-OpenAI model.

The build starts from scratch: a Python 3.10 virtual environment is created, dependencies are installed from a requirements.txt, and environment variables are loaded with load_dotenv. Two model integrations are used: CrewAI for agent orchestration, and LangChain’s Google Gemini interface (chat Google generative AI) to connect the agents to Google’s Gemini Pro. The Gemini API key is obtained from Google AI Studio (AI studio.google.com/a/…/api key), then stored in an environment variable (the transcript references GOOGLE_API_KEY / “Google API key” loaded via os.getenv).

On the agent side, the workflow defines a “news researcher” agent and a “news writer” agent. The researcher’s role is to uncover “groundbreaking technologies” and produce a clear summary with market opportunities and risks; it’s configured with memory enabled and delegation allowed so it can coordinate tool use and handoffs. The writer agent is tasked with turning the research into an article: it’s instructed to compose an in-depth, industry-impact-focused piece formatted as Markdown.

A key enabling component is a search tool. The researcher agent is connected to a Google search capability implemented through SerpAPI-style tooling (the transcript uses “ser.dev” as a “world fastest and cheapest Google search API,” with an API key stored in the environment). This tool is imported into the CrewAI tool layer and then attached to the researcher so the agent can pull current information from the web, rather than relying solely on the model’s internal knowledge.

Tasks formalize the chain. A “research task” demands a comprehensive three-paragraph report on the latest AI trend, explicitly requesting pros, cons, narrative clarity, market opportunities, and potential risks. A “writer task” then requires a four-paragraph Markdown article that explains the trend and its impact on the industry. These tasks are bound to the corresponding agents.

Finally, the agents are assembled into a Crew with a sequential process: the researcher runs first, then the writer consumes the researcher’s output. Execution is kicked off with crew.kickoff using an input topic—example given: “AI in healthcare.” During execution, the researcher performs iterative web searches, compiles findings, and passes a synthesized result to the writer, which produces the final blog artifact (the transcript references an output file like new_blog_post.md). The run also surfaces a common integration issue—an import/initialization mismatch around the LangChain Gemini class—followed by a corrected workflow where the search tool successfully retrieves top titles and the agents complete the article generation.

Cornell Notes

CrewAI is used to orchestrate two cooperating agents—one that researches and one that writes—so they can produce a news-style article about a given topic. The system swaps out OpenAI for Google Gemini Pro by wiring LangChain’s Google Gemini chat model into the agents and loading the Gemini API key from environment variables. A web search tool (via ser.dev/SerpAPI-style integration) is attached to the researcher so it can gather current information, then pass a synthesized summary to the writer. Tasks specify output formats: a three-paragraph research report (including pros/cons, market opportunities, and risks) followed by a four-paragraph Markdown blog post. Running the crew in sequential mode ensures the writer waits for the researcher’s findings.

How does the build avoid OpenAI while still using CrewAI’s agent framework?

CrewAI is kept for orchestration, but the LLM backend is replaced. The agents are configured with a Gemini chat model imported from LangChain (chat Google generative AI) and initialized with a Gemini model name (the transcript references “Google gin Pro” and later uses “gemini 1.5 flash”) plus a Google API key loaded from environment variables via os.getenv after load_dotenv. This prevents needing an OpenAI API key, which the CrewAI docs default to.

What roles do the two agents play, and how do they interact?

The “news researcher” agent is responsible for web-backed investigation: it aims to uncover the next big AI trend, gather pros/cons, and frame market opportunities and risks. The “news writer” agent then converts that research into a coherent article. Interaction happens through CrewAI’s task handoff: in sequential mode, the researcher completes its task first, and the writer receives the researcher’s output as the basis for the final blog.

Why is a search tool essential in this workflow?

The researcher agent is connected to a Google search API tool (the transcript uses ser.dev, described as a fast/cheap Google search API with an API key). This tool enables the agent to retrieve current articles and titles from the web, then synthesize them into the required three-paragraph report. Without the tool, the system would rely more heavily on the model’s internal knowledge rather than up-to-date sources.

How do the tasks enforce the structure of the final output?

The research task specifies a “comprehensive three paragraphs long report” on the latest AI trend, explicitly calling for pros, cons, market opportunities, and potential risks. The writer task then specifies a “four paragraph article” formatted as Markdown and saved as a blog post file (the transcript references new_blog_post.md). These constraints guide the agents’ outputs into predictable formats.

What does sequential execution change compared with other process modes?

Sequential mode ensures strict ordering: the researcher’s task must finish before the writer starts. That ordering is crucial because the writer’s instructions assume it can build on the researcher’s synthesized findings. The transcript contrasts this with an “h le process” mentioned for a later video, but the implemented run uses process.sequential.

What integration error appeared, and what does it illustrate?

An error occurred around importing/initializing chat Google generative AI from LangChain (the transcript shows a mismatch like “name chat Google generative a is not defined” and mentions a spelling mistake). After correcting the import/initialization, the workflow proceeds: the system performs web searches via the search tool and then produces the final article. It highlights that small class-name/import issues can break agent initialization even when the overall architecture is correct.

Review Questions

  1. When swapping from OpenAI to Gemini in CrewAI, which components must be configured: the agent LLM, the API key loading, or the Crew process? Explain your reasoning.
  2. What exact elements are required in the research task output, and how do those requirements map to the writer task’s article structure?
  3. How does attaching the search tool to the researcher change the quality or reliability of the generated news-style report?

Key Points

  1. 1

    Create a Python 3.10 virtual environment and install dependencies from requirements.txt before building the CrewAI agents.

  2. 2

    Load Gemini and search API keys via environment variables using load_dotenv and os.getenv to keep secrets out of code.

  3. 3

    Define two agents with distinct responsibilities: a news researcher (web-backed trend analysis) and a news writer (article generation).

  4. 4

    Attach a web search tool (ser.dev/SerpAPI-style) to the researcher so it can gather current sources and synthesize pros/cons.

  5. 5

    Use CrewAI tasks to enforce output structure: a three-paragraph research report followed by a four-paragraph Markdown blog post.

  6. 6

    Run the crew with process.sequential so the writer waits for the researcher’s findings before drafting the final article.

  7. 7

    Expect and debug integration issues around LangChain Gemini class imports/initialization; small naming mismatches can prevent the LLM from being created.

Highlights

CrewAI can generate a complete news-style blog by chaining a researcher agent and a writer agent in sequential mode.
Replacing OpenAI with Google Gemini Pro requires wiring LangChain’s Gemini chat model into the agents and loading a Google API key from environment variables.
A dedicated Google search API tool (ser.dev) lets the researcher pull current titles and information, then synthesize pros/cons, risks, and market opportunities.
Task definitions act like templates: three paragraphs for research, four paragraphs in Markdown for the final article.

Topics

Mentioned