
How I Automated My Social Media Workflow with LangGraph
Why an automation?
I recently started blogging, more specifically technical blogging. I enjoy going through papers, articles and GitHub repos which spark my interest. This led me to the idea of posting about them. But I realized that technical blogging can be more than just a medium to share my interests, it can be a powerful way to build up my personal brand.
Speaking of creating a personal brand, a lot goes into it, but in my simple view it only requires two things:
- High value and high impact content
- A great distribution strategy
Social media is the “great distribution strategy”.
But writing content optimized for social media, more specifically LinkedIn and X was not an area I wanted to spend a lot of time on, and also, being an engineer, I was attracted to automating it away.
How it works?
Central Idea
At the heart of this project is a LangGraph workflow that automates my content pipeline, which means, right from the idea stage to the draft and publish stage of my social media posts (not my blogs), the workflow takes care of the entire generation.
- What kind of posts I want?
- What type of post I need depending on day of the week?
- Is the content of the post legitimate and factual?
- Does the post make any claims with no basis?
- Does the post state any statements without proper citations?
Why LangGraph?
After using multiple tools for creating agents like LCEL, CrewAI and DSPy, I felt LangGraph was extremely easy to follow in terms of the workflow, as it maps very well to flowcharts and UML diagrams we encounter on a daily basis. Also, I am familiar with LangGraph since I used it extensively at my internship to build agentic systems.
Flowchart
Here’s a breakdown of the process:
-
Capture & Research
- The workflow starts by capturing a raw idea (
capture_idea). - It then pulls in notes and references from Obsidian (
obsidian_research), ensuring the idea is grounded in prior research.
- The workflow starts by capturing a raw idea (
-
Planning & Teaser Generation
- The
planner_agentstructures the idea into a roadmap. - Depending on the phase, the system may generate an early teaser post (
teaser_generator) to share on Monday as a preview.
- The
-
Drafting the Blog
- If we’re in the drafting phase, the
blog_draftercreates a long-form draft. - Once the final blog URL is available, the system scrapes the published content (
scraper) and builds a concise summary (summarizer).
- If we’re in the drafting phase, the
-
Social Media Post Creation
- Using the blog summary, the workflow generates tailored LinkedIn posts (
final_post_generator) and X/Twitter posts (x_generator).
- Using the blog summary, the workflow generates tailored LinkedIn posts (
-
Validation & Review
- Posts are validated for structure, tone, and platform-fit (
validator). - If issues are found, they are sent for peer review (
peer_reviewer) and, if necessary, refined by thecontent_improver. - The workflow limits improvements to 3 iterations to avoid endless loops.
- Posts are validated for structure, tone, and platform-fit (
-
Self-Evaluation & Recovery
- Before finalizing, posts undergo a self-check (
self_evaluator). - If errors occur (e.g., missing blog URL, broken logic), a
recovery_agentsteps in to fix or gracefully exit.
- Before finalizing, posts undergo a self-check (
-
Completion
- Once validated, the system outputs ready-to-publish posts for LinkedIn and X.
- If human oversight is required (e.g., controversial phrasing or ambiguous context), the workflow pauses and flags it for manual review.
The workflow code snippet:
def create_workflow():
workflow = StateGraph(AutomationState)
workflow.add_node("capture_idea", capture_idea)
workflow.add_node("obsidian_research", process_obsidian_content)
workflow.add_node("planner_agent", planner_agent)
workflow.add_node("teaser_generator", teaser_generator)
workflow.add_node("blog_drafter", blog_drafter)
workflow.add_node("scraper", scrape_blog_content)
workflow.add_node("summarizer", generate_blog_summary)
workflow.add_node("final_post_generator", generate_linkedin_posts)
workflow.add_node("x_generator", generate_x_posts)
workflow.add_node("validator", validate_posts)
workflow.add_node("peer_reviewer", peer_review_agent)
workflow.add_node("content_improver", content_improver_agent)
workflow.add_node("self_evaluator", self_evaluator)
workflow.add_node("recovery_agent", recovery_agent)
workflow.set_entry_point("capture_idea")
workflow.add_edge("capture_idea", "obsidian_research")
workflow.add_edge("obsidian_research", "planner_agent")
workflow.add_conditional_edges(
"planner_agent",
should_generate_teaser,
{
"teaser_generator": "teaser_generator",
"planner_agent": "planner_agent",
"scraper": "scraper",
},
)
workflow.add_conditional_edges(
"teaser_generator",
should_generate_blog_draft,
{
"blog_drafter": "blog_drafter",
"planner_agent": "planner_agent",
"scraper": "scraper",
},
)
workflow.add_conditional_edges(
"blog_drafter", should_scrape_blog, {"scraper": "scraper", "END": END}
)
workflow.add_edge("scraper", "summarizer")
workflow.add_edge("summarizer", "final_post_generator")
workflow.add_edge("final_post_generator", "x_generator")
workflow.add_conditional_edges(
"x_generator",
should_validate_or_end,
{"validator": "validator", "recovery_agent": "recovery_agent", "END": END},
)
workflow.add_conditional_edges(
"validator",
should_improve_or_evaluate,
{
"peer_reviewer": "peer_reviewer",
"self_evaluator": "self_evaluator",
"recovery_agent": "recovery_agent",
},
)
workflow.add_conditional_edges(
"peer_reviewer",
should_improve_or_end,
{
"content_improver": "content_improver",
"self_evaluator": "self_evaluator",
"recovery_agent": "recovery_agent",
},
)
workflow.add_edge("content_improver", "validator")
workflow.add_conditional_edges(
"self_evaluator",
should_loop_or_end,
{"validator": "validator", "recovery_agent": "recovery_agent", "END": END},
)
workflow.add_edge("recovery_agent", END)
return workflow.compile()
Entire code for my automation: GitHub
Closing Thoughts
It was very fun building out this automation. Obviously it can’t be deemed a boon for my productivity in such a short period of time, but I will be keeping a close eye on gains (or losses) as a result of this automation, which I certainly will be posting about.
Share This Post
Sources
-by Mariya Mansurova
Documentation
Deep dive into LangGraph