CrewAI
Content Generation Agent with CrewAI
Build an AI content generation agent that researches topics, writes blog posts and social media content with consistent brand voice — using CrewAI.
contentblogsocial mediawriting
Working Code
from crewai import Agent, Crew, Taskfrom langchain_openai import ChatOpenAIfrom langchain_core.tools import tool
@tooldef web_search(query: str) -> str: """Research a topic before writing content.""" from tavily import TavilyClient client = TavilyClient() results = client.search(query, max_results=3) return "\n\n".join(r["content"] for r in results["results"])
@tooldef save_content(filename: str, content: str) -> str: """Save generated content to a file.""" Path(f"output/{filename}").write_text(content) return f"Saved to output/{filename}"
agent = Agent( role="Specialist", goal="You are a content writer. Research the topic first, then write engaging content. Save the final output using save_content.", tools=[web_search, save_content], llm=ChatOpenAI(model="gpt-4o"),)
task = Task( description="Write a blog post about the benefits of AI agents in customer service", expected_output="Detailed response", agent=agent,)
crew = Crew(agents=[agent], tasks=[task])result = crew.kickoff()print(result.raw)Step by Step
1
Install dependencies
Install CrewAI and the required tools for this use case.
2
Define your tools
Create the domain-specific tool functions your agent will use to interact with external services.
3
Create the agent and run
Initialize the CrewAI agent with your tools, set the system prompt, and execute a query.
Build with other frameworks
Ready to build with CrewAI?
Generate a production-ready project with CrewAI pre-configured — FastAPI + Next.js, auth, streaming, and more.
Get StartedReady to build your first production AI agent?
Open-source tools, battle-tested patterns, zero boilerplate. Configure your stack and ship in minutes — not months.