Back to prompt library
CrewAI Agent and Task Definition
Linked challenge: Collaborative Technical Research Crew
Prompt source
planning63 lines13 sectionsNo variables1 code block
Define three distinct agents using `CrewAI`: a `Researcher` (expert in web searching and information gathering), an `Analyst` (expert in synthesizing and structuring information), and a `Technical Writer` (expert in clear, concise technical communication). Each agent should have specific tools available. The `Researcher` should have a `WebSearchTool` (e.g., using `DuckDuckGoSearchRun` from Langchain). The `Analyst` and `Technical Writer` should have access to `ChromaDB` (via a custom tool) for storing and retrieving research fragments. All agents should use `Gemini 2.5 Pro` via Vertex AI for their LLM backend.
```python
import os
from crewai import Agent, Task, Crew
from crewai_tools import DuckDuckGoSearchRun # Example search tool
from langchain_google_vertexai import VertexAI
from chromadb import Client, Settings
# --- Assume Google Cloud Project and API setup for Vertex AI ---
# Make sure GOOGLE_APPLICATION_CREDENTIALS environment variable is set
# Initialize Vertex AI LLM (Gemini 2.5 Pro)
gemini_llm = VertexAI(model_name="gemini-2.5-pro-preview-0403", temperature=0.7)
# Initialize ChromaDB client (running in-memory for this example)
chroma_client = Client(Settings(allow_reset=True))
chroma_collection = chroma_client.get_or_create_collection(name="tech_research_kb")
# Custom ChromaDB Tool for agents
class ChromaDBTool:
@classmethod
def store_research(cls, topic: str, content: str) -> str:
# In a real scenario, embed content before storing
chroma_collection.add(documents=[content], metadatas=[{"topic": topic}], ids=[f"doc-{len(chroma_collection.get()['ids']) + 1}"])
return f"Stored research for '{topic}'."
@classmethod
def retrieve_research(cls, query: str) -> str:
# In a real scenario, embed query before searching
results = chroma_collection.query(query_texts=[query], n_results=5)
return "\n".join([doc for doc in results['documents'][0]]) if results['documents'] else "No relevant research found."
# Tools available to agents
web_search_tool = DuckDuckGoSearchRun()
chroma_tool = ChromaDBTool()
# Define Agents
researcher = Agent(
role='Senior Research Analyst',
goal='Conduct in-depth research on complex technical topics and gather relevant information.',
backstory='An expert in identifying credible sources and extracting key insights from vast amounts of data.',
llm=gemini_llm,
tools=[web_search_tool, chroma_tool.store_research],
verbose=True
)
analyst = Agent(
role='Technical Data Analyst',
goal='Synthesize research findings, identify patterns, and structure information for clear understanding.',
backstory='A meticulous analyst capable of breaking down complex concepts into digestible components.',
llm=gemini_llm,
tools=[chroma_tool.retrieve_research, chroma_tool.store_research],
verbose=True
)
writer = Agent(
role='Expert Technical Writer',
goal='Translate complex technical information into well-structured, clear, and engaging reports.',
backstory='A gifted communicator who transforms raw data and analysis into compelling narratives.',
llm=gemini_llm,
tools=[chroma_tool.retrieve_research],
verbose=True
)
# Define Tasks (initial tasks, more will be added later)
# Note: Tasks are defined in the next prompt
# Initialize the Crew (will be done in a later prompt once tasks are defined)
# tech_research_crew = Crew(
# agents=[researcher, analyst, writer],
# tasks=[...],
# verbose=2
# )
```