# Build a social media agent with Managed Deep Agents

## Executive summary

This tutorial demonstrates building an autonomous social media agent using LangChain's Managed Deep Agents (MDA). The resulting agent monitors Hacker News and X (Twitter) to generate daily drafts of post ideas, which are then delivered directly to the user via Slack. The process covers setting up the project structure, defining custom tools, implementing specialized skills, configuring persistent memory across sessions, scheduling autonomous execution, and deploying the system to a production channel.

## Key takeaways

- Agent Initialization and Setup: The process begins by installing dependencies using `UV tool install managed deep agents` and initializing the project with `MDA init social post assistant`. The agent's entry point (`agent.py`) is configured, specifying model properties (e.g., changing to `GPT-5.6 Luna` for cost efficiency) and defining access tools.
- Tooling and Data Integration: Custom tools are built to interact with external APIs: a tool to search Hacker News (using Algolia API) and two tools for X/Twitter (`get X user timeline` and `search X posts`). Authentication requires defining bearer tokens in the `.env` file.
- Advanced Agent Configuration: The agent's behavior is governed by a core instruction file (`instructions.md`) and specialized, modular knowledge packages called 'Skills.' A skill (e.g., `draft posts`) provides dynamic instructions for specific tasks like drafting or revising content.
- Persistence and Automation: To maintain context across different runs, a memory file (`memory.py`) is set with the scope to 'agent.' The agent's autonomy is established by creating a schedule (e.g., `morning drafts.py`) using cron expressions to run daily at 9:00 a.m. Pacific time.
- Deployment and Connectivity: The agent is tested locally via `MDA dev` (which opens the agent in LangSmith Studio) before deployment using `MDA deploy`. Slack integration requires running `mda channel add slack`, generating a manifest, and setting up necessary environment variables (Slack signing secret and bot token).

## Technical details

- Project Setup & Dependencies: Managed Deep Agents requires specific commands: `UV tool install managed deep agents` and project initialization via `MDA init <agent-name>`. The LangSmith API key must be set in the `.env` file.
- Agent Core Definition: The agent's properties are defined in `agent.py`, allowing customization of the model (e.g., `GPT-5.6 Luna`) and defining access to tools, sub-agents, and middleware.
- Tool Implementation: Tools are implemented as Python functions decorated with the LangChain tool decorator. The function's docstring serves as the agent's description, while arguments define visible input parameters.
- Memory and State Management: To ensure memory persists across multiple conversation threads, a `memory.py` file must be created in the project root and set with the scope to 'agent.'
- Scheduling and Execution: Autonomous execution is configured using a schedule directory, defining a cron tab expression (e.g., running every weekday at 9:00 a.m.) and setting `auto_post = true` for unattended posting.
- Deployment Workflow: The deployment process involves running `MDA deploy`, followed by manually linking the channel using `mda channel add slack`. The final step requires setting Slack credentials and redeploying to activate the connection.

## Practical implications

- The architecture can be generalized for any recurring, multi-step task (e.g., engineering update summaries, customer research, incident reports) by simply changing the tools and skills.
- By separating instructions into 'Skills,' complex domain knowledge or specialized workflows can be loaded dynamically only when required, keeping the core agent logic clean.
- The combination of scheduled execution and persistent memory allows for truly autonomous agents that operate without continuous human intervention.

## Topics

Managed Deep Agents, LangChain, Autonomous AI, Agent Orchestration, Scheduled Tasks, API Integration (Hacker News, X/Twitter), Slack Automation, Managed Deep Agents Docs, Example Code Repository

Source: https://www.youtube.com/watch?v=OpFXXSsEIBo
