An AI agent built with LangChain and Google Gemini that generates professional, engaging LinkedIn posts from a topic and a language.
The agent uses an LLM chain (prompt | llm | output_parser) to produce a
structured 2–4 paragraph post with a strong hook, a clear takeaway, a call to
action, and relevant hashtags — all written in the language you choose
(English, Bengali, Spanish, and more).
- Topic-driven — give it any subject (e.g., "AI in Healthcare").
- Multilingual — writes the entire post in your selected language, including non-Latin scripts like Bengali or Arabic.
- Structured output — hook, 2–4 paragraphs, call to action, and hashtags.
- Configurable — optional tone and target audience; swap models or temperature via flags or environment variables.
- Usable two ways — interactive CLI prompts or one-shot command-line flags.
linkedin-post-generator-agent/
├── linkedin_agent/
│ ├── __init__.py # exports LinkedInPostAgent, PostRequest
│ ├── agent.py # the LangChain LCEL chain + agent class
│ └── prompts.py # chat prompt templates
├── app.py # modern Streamlit web UI
├── main.py # CLI entry point
├── demo.sh # guided demo for recording a walkthrough
├── Dockerfile
├── docker-compose.yml
├── requirements.txt
├── .env.example
└── README.md
-
Create and activate a virtual environment
python3 -m venv .venv source .venv/bin/activate # Windows: .venv\Scripts\activate
-
Install dependencies
pip install -r requirements.txt
-
Configure your API key
cp .env.example .env # then edit .env and set GOOGLE_API_KEY.envvariables:Variable Required Default Description GOOGLE_API_KEYyes — Your Google Gemini API key GEMINI_MODELno gemini-2.5-flashChat model to use LLM_TEMPERATUREno 0.7Sampling temperature (0.0–1.0)
A modern, interactive Streamlit interface:
streamlit run app.pyThen open the URL it prints (default: http://localhost:8501). You get a topic
box, a language picker, optional tone/audience fields, a model selector, and a
creativity slider in the sidebar — plus copy and download buttons for the
generated post. You can paste an API key directly in the sidebar if you haven't
set GOOGLE_API_KEY in .env.
python main.pyYou'll be prompted for the topic and language.
python main.py --topic "AI in Healthcare" --language English
python main.py -t "Remote Work Productivity" -l Bengali --tone inspirational
python main.py -t "Cloud Cost Optimization" -l Spanish --audience "startup founders"| Flag | Description |
|---|---|
-t, --topic |
Topic of the post |
-l, --language |
Language of the post (default: English) |
--tone |
Optional tone (e.g., inspirational, technical) |
--audience |
Optional target audience |
--model |
Override the LLM model |
--temperature |
Override the sampling temperature |
Make sure your GOOGLE_API_KEY is set in a .env file (see Setup). The .env
file is not baked into the image — it is passed in at runtime.
docker build -t linkedin-post-generator .# One-shot with flags
docker run --rm --env-file .env linkedin-post-generator -t "AI in Healthcare" -l English
# Interactive prompts (note the -it flags)
docker run --rm -it --env-file .env linkedin-post-generator# One-shot with flags
docker compose run --rm linkedin-agent -t "Remote Work Productivity" -l Bengali
# Interactive prompts
docker compose run --rm linkedin-agent# Starts the Streamlit UI on http://localhost:8501
docker compose up uiThe container runs as a non-root user and reads configuration from environment variables, so the same
.envyou use locally works inside Docker.
from dotenv import load_dotenv
from linkedin_agent import LinkedInPostAgent
load_dotenv()
agent = LinkedInPostAgent()
post = agent.generate_post(
topic="AI in Healthcare",
language="English",
tone="inspirational",
)
print(post)linkedin_agent/agent.py builds a LangChain Expression Language (LCEL) chain:
ChatPromptTemplate → ChatGoogleGenerativeAI (Gemini) → StrOutputParser
The system prompt instructs the model to act as a LinkedIn content strategist and to write the full post in the requested language, while the human prompt injects the topic, language, and optional tone/audience. The parsed string is returned as the final post.
- A Google Gemini API key is required; calls to the API may incur usage costs. Get one at https://aistudio.google.com/app/apikey.
- To use a different LLM provider, swap
ChatGoogleGenerativeAIinagent.pyfor another LangChain chat model (e.g.,langchain-openai,langchain-anthropic). - Note: some models (e.g.,
gemini-2.0-flash) may have zero free-tier quota on a given key;gemini-2.5-flashis used by default. Override viaGEMINI_MODELor--model.