Skip to content
LangGraph

Content Generation Agent with LangGraph

Build an AI content generation agent that researches topics, writes blog posts and social media content with consistent brand voice — using LangGraph.

contentblogsocial mediawriting

Working Code

LangGraph
from langchain_openai import ChatOpenAI
from langchain_core.tools import tool
from langgraph.prebuilt import create_react_agent
@tool
def 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"])
@tool
def 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 = create_react_agent(
ChatOpenAI(model="gpt-4o"),
tools=[web_search, save_content],
prompt="You are a content writer. Research the topic first, then write engaging content. Save the final output using save_content.",
)
result = await agent.ainvoke({
"messages": [("user", "Write a blog post about the benefits of AI agents in customer service")]
})
print(result["messages"][-1].content)

Step by Step

1

Install dependencies

Install LangGraph 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 LangGraph agent with your tools, set the system prompt, and execute a query.

Ready to build with LangGraph?

Generate a production-ready project with LangGraph pre-configured — FastAPI + Next.js, auth, streaming, and more.

Get Started

Ready to build your first production AI agent?

Open-source tools, battle-tested patterns, zero boilerplate. Configure your stack and ship in minutes — not months.