An agent for sourcing, curating, and scheduling social media posts with human-in-the-loop.
An agent for sourcing, curating, and scheduling social media posts with human-in-the-loop.
This repository contains an 'agent' which can take in a URL, and generate a Twitter & LinkedIn post based on the content of the URL. It uses a human-in-the-loop (HITL) flow to handle authentication with different social media platforms, and to allow the user to make changes, or accept/reject the generated post.
[!TIP] For a visual guide, check out our step-by-step video tutorial that walks you through the account setup process and project configuration.
This quickstart covers how to setup the Social Media Agent in a basic setup mode. This is the quickest way to get up and running, however it will lack some of the features of the full setup mode. See here for the full setup guide.
Running in basic setup mode will lack the following features:To get started, you'll need the following API keys/software:
git clone https://github.com/langchain-ai/social-media-agent.gitcd social-media-agentyarn installCopy the values of the quickstart .env.quickstart.example to .env, then add the values:
cp .env.quickstart.example .envOnce done, ensure you have the following environment variables set:
# For LangSmith tracing (optional)
LANGSMITH_API_KEY=
LANGSMITH_TRACING_V2=true
# For LLM generations
ANTHROPIC_API_KEY=
# For web scraping
FIRECRAWL_API_KEY=
# Arcade API key - used for fetching Tweets, and scheduling LinkedIn/Twitter posts
ARCADE_API_KEY=If you plan to post to LinkedIn as an organization (rather than as yourself), you'll also need to set:
# Get the organization ID from the URL of the company page when you're logged in as an admin.
# For example, if the URL is `https://www.linkedin.com/company/12345678/admin/dashboard/`, the organization ID would be `12345678`.
POST_TO_LINKEDIN_ORGANIZATION=true
LINKEDIN_ORGANIZATION_ID=pip install langgraph-cliThen run the following command to check the CLI is installed:
langgraph --versionClick here to read the full download instructions for the LangGraph CLI.
To start the LangGraph server, run this script:
yarn langgraph:in_mem:upUnder the hood, this will execute the following command:
npx @langchain/langgraph-cli dev --port 54367[!NOTE] The first time running this command (or if a new version of
@langchain/langgraph-clihas been released), it will ask you to accept an install for the CLI. Enteryto accept.
Once the server is ready, you can execute the following command to generate a post:
yarn generate_postYou may also modify this script to pass different URLs to generate posts for other content.
This will kick off a new run to generate a post on a LangChain blog post.
To view the output, either inspect it in LangSmith, or use Agent Inbox.
[!TIP] Follow these steps to setup & configure the Agent Inbox: Setup Agent Inbox Guide
To use all of the features of the Social Media Agent, you'll need the following:
git clone https://github.com/langchain-ai/social-media-agent.gitcd social-media-agentyarn installCopy the values of the full env example file .env.full.example to .env, then update the values as needed.
cp .env.full.example .envThe agent needs your authorization to read and write to social media platforms. There are two ways to authorize the agent:
You can use either method, but not both.
Create an Arcade account here. After you register, get an Arcade API key. Set this value as ARCADE_API_KEY in your .env file.
Then, you will need to set these environment variables in your .env file:
TWITTER_USER_ID - The ID/email of the Twitter account you want to use to post to Twitter.LINKEDIN_USER_ID - The ID/email of the LinkedIn account you want to use to post to LinkedIn.Make sure you have the USE_ARCADE_AUTH environment variable set to true to have the graph use Arcade authentication.
If you plan to post to LinkedIn as an organization (rather than as yourself), you'll also need to set:
# Get the organization ID from the URL of the company page when you're logged in as an admin.
# For example, if the URL is `https://www.linkedin.com/company/12345678/admin/dashboard/`, the organization ID would be `12345678`.
LINKEDIN_ORGANIZATION_ID=
POST_TO_LINKEDIN_ORGANIZATION=true[!NOTE] If you want to upload media to Twitter, you will still need to set up your own Twitter developer account (below) in addition to using Arcade.
If you are only planning to read/write text posts on Twitter, you can use Arcade without any additional setup.
You'll need to follow these instructions if you plan on uploading media to Twitter, and/or you are not using Arcade for authorization.
API Key, API Key Secret and Bearer Token and set them as TWITTER_API_KEY, TWITTER_API_KEY_SECRET, and TWITTER_BEARER_TOKEN in your .env file.User authentication settings section, and click the Set up button. This is how you will authorize users to use the Twitter API on their behalf.App permissions: Read and writeType of App: Web App, Automated App or BotApp info:Callback URI/Redirect URL: http://localhost:3000/auth/twitter/callbackWebsite URL: Your website URLClient ID and Client Secret. Set these as TWITTER_CLIENT_ID and TWITTER_CLIENT_SECRET in your .env file.Once done, run the yarn start:auth command to run the Twitter OAuth server. Open http://localhost:3000 in your browser, and click Login with Twitter.
After authorizing your account with the app, navigate to your terminal where you'll see a JSON object logged. Copy the token and tokenSecret values and set them as TWITTER_USER_TOKEN and TWITTER_USER_TOKEN_SECRET in your .env file.
You'll need to follow these instructions if you plan on posting to LinkedIn and are not using Arcade for authorization.
Auth tab, and add a new authorized redirect URL for OAuth 2.0. Set it to http://localhost:3000/auth/linkedin/callbackProducts tab and enable the Share on LinkedIn and Sign In with LinkedIn using OpenID Connect products.Advertising API product. Furthermore, ensure your personal account has at least one one of the following roles with the company page:ADMINISTRATORDIRECT_SPONSORED_CONTENT_POSTERRECRUITING_POSTERSettings tab of your app, then click the Verify button on the company page card.w_organization_social scope is enabled inside the scopes string in the /auth/linkedin route. Once done, the scopes string should look like this: openid profile email w_member_social w_organization_socialLINKEDIN_ORGANIZATION_ID environment variable. For example, if the URL is https://www.linkedin.com/company/12345678/admin/dashboard/, the organization ID would be 12345678.[!NOTE] If you plan on only posting from the company account, you can set the
POST_TO_LINKEDIN_ORGANIZATIONto"true"in your.envfile. If you want to choose dynamically, you can set this totrue/falsein the configurable fields (postToLinkedInOrganization) when invoking thegenerate_postgraph.This value will take precedence over the
POST_TO_LINKEDIN_ORGANIZATIONenvironment variable.
.env file:LINKEDIN_CLIENT_IDLINKEDIN_CLIENT_SECRETyarn start:auth command to run the LinkedIn OAuth server. Open http://localhost:3000 in your browser, and click Login with LinkedIn.access_token and sub values from the objects logged to the terminal. Set these values as LINKEDIN_ACCESS_TOKEN (access_token) and LINKEDIN_PERSON_URN (sub) in your .env file.Supabase is required for storing images found/generated by the agent.
No open issues yet, or sync has not completed.