<RETURN_TO_BASE

Build an Autonomous Multi-Agent Writing Pipeline

Learn to create a collaborative AI agent system using CrewAI and Gemini.

Overview

In this tutorial, we implement a powerful two-agent CrewAI system that collaborates using the Gemini Flash model. We set up our environment, authenticate securely, define specialized agents, and orchestrate tasks from research to structured writing. This hands-on experience demonstrates modern agent workflows powered by LLMs and shows how multi-agent pipelines can be practical, modular, and developer-friendly.

Setting Up the Environment

We begin by installing the required CrewAI packages to ensure everything runs smoothly in Colab:

import os
import sys
import getpass
from textwrap import dedent
 
print("Installing CrewAI and tools... (this may take 1-2 mins)")
!pip install -q crewai crewai-tools
 
from crewai import Agent, Task, Crew, Process, LLM

This setup lays the foundation for our multi-agent workflow.

Authenticating with the Gemini API

Next, we authenticate our system by securely retrieving or entering the Gemini API key:

print("\n--- API Authentication ---")
api_key = None
 
try:
   from google.colab import userdata
   api_key = userdata.get('GEMINI_API_KEY')
   print("✅ Found GEMINI_API_KEY in Colab Secrets.")
except Exception:
   pass
 
if not api_key:
   print("ℹ Key not found in Secrets.")
   api_key = getpass.getpass("🔑 Enter your Google Gemini API Key: ")
 
os.environ["GEMINI_API_KEY"] = api_key
 
if not api_key:
   sys.exit("❌ Error: No API Key provided. Please restart and enter a key.")

This ensures reliable communication between our agent framework and the LLM.

Configuring the Gemini Flash Model

Here, we configure the Gemini Flash model that our agents rely on for reasoning and generation:

gemini_flash = LLM(
   model="gemini/gemini-2.0-flash",
   temperature=0.7
)

This configuration balances creativity and precision, becoming the shared intelligence driving our agent tasks.

Defining Agents in the System

Next, we define our two specialized agents:

researcher = Agent(
   role='Tech Researcher',
   goal='Uncover cutting-edge developments in AI Agents',
   backstory=dedent("""
You are a veteran tech analyst with a knack for finding emerging trends before they become mainstream. You specialize in Autonomous AI Agents and Large Language Models.
"""),
   verbose=True,
   allow_delegation=False,
   llm=gemini_flash
)
 
writer = Agent(
   role='Technical Writer',
   goal='Write a concise, engaging blog post about the researcher's findings',
   backstory=dedent("""
You transform complex technical concepts into compelling narratives. You write for a developer audience who wants practical insights without fluff.
"""),
   verbose=True,
   allow_delegation=False,
   llm=gemini_flash
)

These agents work in tandem—one uncovers insights while the other transforms them into well-written content.

Creating Tasks for the Agents

We then create tasks that clearly define the responsibilities for each agent:

research_task = Task(
   description=dedent("""
Conduct a simulated research analysis on 'The Future of Agentic AI in 2025'. Identify three key trends: 1. Multi-Agent Orchestration 2. Neuro-symbolic AI 3. On-device Agent execution Provide a summary for each based on your 'expert knowledge'.
"""),
   expected_output="A structured list of 3 key AI trends with brief descriptions.",
   agent=researcher
)
 
write_task = Task(
   description=dedent("""
Using the researcher's findings, write a short blog post (approx 200 words). The post should have: - A catchy title - An intro - The three bullet points - A conclusion on why developers should care.
"""),
   expected_output="A markdown-formatted blog post.",
   agent=writer,
   context=[research_task]
)

By orchestrating these task dependencies, we enable smooth operational flow within CrewAI.

Running the Multi-Agent Workflow

Finally, we assemble our agents and tasks into a crew, executing the multi-agent workflow:

tech_crew = Crew(
   agents=[researcher, writer],
   tasks=[research_task, write_task],
   process=Process.sequential,
   verbose=True
)
 
print("\n--- 🤖 Starting the Crew ---")
result = tech_crew.kickoff()
 
from IPython.display import Markdown
print("\n\n########################")
print("##   FINAL OUTPUT     ##")
print("########################\n")
display(Markdown(str(result)))

This final step showcases the real-time collaboration of our agents.

The Value of Multi-Agent Collaboration

Through this tutorial, we see how efficiently CrewAI allows for the creation of coordinated agent systems capable of research and writing. By defining roles, tasks, and process flows, we can modularize complex work and achieve coherent outputs with minimal code. This framework prepares us to develop larger multi-agent systems or creative AI collaborations.

🇷🇺

Сменить язык

Читать эту статью на русском

Переключить на Русский