Social Agents Example
This example demonstrates how to create a sophisticated social media content creation system with multiple specialized agents handling different aspects of content creation, from editing to platform-specific writing and review.
Overview
The Social Agents example shows how to: - Create a content editing and refinement pipeline - Generate platform-specific content (Twitter, LinkedIn) - Implement content review and feedback - Manage dynamic content workflows - Handle multi-platform content adaptation
Implementation
Here's the complete implementation:
from datetime import datetime
from yosrai import Agent, Action, ContextFunctions
import agents_social_prompts
# Greeting Agent - Introduces the content creation task
greeting_agent = Agent(
agent_code='greeting_agent',
agent_name='Greeting Agent',
agent_type='tool',
prompt_template=agents_social_prompts.GREETING_PROMPT,
outputs={'greeting': ContextFunctions.DEFAULT}
)
# Editor Agent - Refines and improves the initial content
editor_agent = Agent(
agent_code='editor_agent',
agent_name='Editor Agent',
prompt_template=agents_social_prompts.EDITOR_PROMPT,
outputs={'editor_text': ContextFunctions.DEFAULT, 'messages': ContextFunctions.REPLIES}
)
# Twitter Writer Agent - Creates Twitter-specific content
twitter_writer_agent = Agent(
agent_code='twitter_writer_agent',
agent_name='Twitter Writer Agent',
prompt_template=agents_social_prompts.TWITTER_WRITER_PROMPT,
outputs={'twitter_post_drafts': ContextFunctions.APPEND_OUTPUT_CONTENT, 'messages': ContextFunctions.REPLIES}
)
# LinkedIn Writer Agent - Creates LinkedIn-specific content
linkedin_writer_agent = Agent(
agent_code='linkedin_writer_agent',
agent_name='LinkedIn Writer Agent',
prompt_template=agents_social_prompts.LINKEDIN_WRITER_PROMPT,
outputs={'linkedin_post_drafts': ContextFunctions.APPEND_OUTPUT_CONTENT, 'messages': ContextFunctions.REPLIES}
)
# Review Agents - Evaluate and provide feedback on content
twitter_review_agent = Agent(
agent_code='twitter_review_agent',
agent_name='Twitter Review Agent',
prompt_template=agents_social_prompts.TWITTER_REVIEW_PROMPT,
outputs={'twitter_post_feedback': ContextFunctions.DEFAULT, 'messages': ContextFunctions.REPLIES}
)
linkedin_review_agent = Agent(
agent_code='linkedin_review_agent',
agent_name='LinkedIn Review Agent',
prompt_template=agents_social_prompts.LINKEDIN_REVIEW_PROMPT,
outputs={'linkedin_post_feedback': ContextFunctions.DEFAULT, 'messages': ContextFunctions.REPLIES}
)
# Decision Agents - Determine if content needs review
twitter_should_review_agent = Agent(
agent_code='twitter_should_review_agent',
agent_name='Twitter Should Review Agent',
prompt_template=agents_social_prompts.TWITTER_SHOULD_REVIEW_PROMPT,
outputs={'twitter_should_review_decision': ContextFunctions.DEFAULT}
)
linkedin_should_review_agent = Agent(
agent_code='linkedin_should_review_agent',
agent_name='LinkedIn Should Review Agent',
prompt_template=agents_social_prompts.LINKEDIN_SHOULD_REVIEW_PROMPT,
outputs={'linkedin_should_review_decision': ContextFunctions.DEFAULT}
)
# Set up the workflow
action = Action('Social Writing (Editor, Writer, Reviewer)')
action.Context(
user_text='Working from home is better than working from office',
target_audience='techies',
messages=[],
twitter_post_drafts=[],
twitter_post_feedback='',
linkedin_post_drafts=[],
linkedin_post_feedback='',
no_of_drafts=1,
date=datetime.now().strftime('%d-%m-%Y %H:%M:%S')
)
# Add agents to the action
action.add_agent(greeting_agent)
action.add_agent(editor_agent)
action.add_agent(twitter_writer_agent)
action.add_agent(linkedin_writer_agent)
action.add_agent(twitter_review_agent)
action.add_agent(linkedin_review_agent)
# Define the workflow
action.add_link(greeting_agent, editor_agent)
action.add_link(editor_agent, twitter_writer_agent)
action.add_link(editor_agent, linkedin_writer_agent)
action.add_link_dynamic(twitter_writer_agent, [twitter_review_agent, "END"], twitter_should_review_agent)
action.add_link_dynamic(linkedin_writer_agent, [linkedin_review_agent, "END"], linkedin_should_review_agent)
action.add_link(twitter_review_agent, twitter_writer_agent)
action.add_link(linkedin_review_agent, linkedin_writer_agent)
Workflow Visualization
The workflow shows the complex content creation and review process:
---
title: Social Media Post
---
graph LR
START((Start)) --> greeting_agent[Greeting Agent]
greeting_agent(Greeting Agent) --> editor_agent(Editor Agent)
editor_agent(Editor Agent) --> twitter_writer_agent(Twitter Writer Agent)
editor_agent(Editor Agent) --> linkedin_writer_agent(LinkedIn Writer Agent)
twitter_writer_agent(Twitter Writer Agent) --> twitter_review_agent(Twitter Review Agent)
twitter_writer_agent(Twitter Writer Agent) --> END((End))
linkedin_writer_agent(LinkedIn Writer Agent) --> linkedin_review_agent(LinkedIn Review Agent)
linkedin_writer_agent(LinkedIn Writer Agent) --> END((End))
twitter_review_agent(Twitter Review Agent) --> twitter_writer_agent(Twitter Writer Agent)
linkedin_review_agent(LinkedIn Review Agent) --> linkedin_writer_agent(LinkedIn Writer Agent)
Key Components
Greeting Agent
Initializes the content creation process:
greeting_agent = Agent(
agent_code='greeting_agent',
agent_name='Greeting Agent',
agent_type='tool',
prompt_template=agents_social_prompts.GREETING_PROMPT,
outputs={'greeting': ContextFunctions.DEFAULT}
)
Editor Agent
Refines and improves the initial content:
editor_agent = Agent(
agent_code='editor_agent',
agent_name='Editor Agent',
prompt_template=agents_social_prompts.EDITOR_PROMPT,
outputs={'editor_text': ContextFunctions.DEFAULT, 'messages': ContextFunctions.REPLIES}
)
Platform-Specific Writers
Create content tailored for each platform:
twitter_writer_agent = Agent(
agent_code='twitter_writer_agent',
agent_name='Twitter Writer Agent',
prompt_template=agents_social_prompts.TWITTER_WRITER_PROMPT,
outputs={'twitter_post_drafts': ContextFunctions.APPEND_OUTPUT_CONTENT, 'messages': ContextFunctions.REPLIES}
)
Review System
Evaluates content quality and provides feedback:
twitter_review_agent = Agent(
agent_code='twitter_review_agent',
agent_name='Twitter Review Agent',
prompt_template=agents_social_prompts.TWITTER_REVIEW_PROMPT,
outputs={'twitter_post_feedback': ContextFunctions.DEFAULT, 'messages': ContextFunctions.REPLIES}
)
Example Interaction
Here's a sample content creation flow:
Input: "Working from home is better than working from office"
Editor Agent: "Let's refine this for a tech audience: 'Remote work vs. office: Why WFH is the future of tech productivity'"
Twitter Writer: "#RemoteWork > Office Life 🏠💻 Data shows 42% higher productivity for tech teams WFH! No commute = More code time Better work-life balance = Better solutions
TechLife #FutureOfWork #DevLife"
LinkedIn Writer: "🚀 The Remote Revolution in Tech: A Data-Driven Perspective
As a tech professional, I've experienced firsthand how remote work transforms productivity. Here's why:
✨ Key Benefits: • 3+ hours saved daily on commute • 28% increase in deep work sessions • 65% better work-life balance
What's your remote work experience? Share below! 👇
TechIndustry #RemoteWork #ProductivityHacks"
Best Practices
When implementing the Social Agents pattern:
- Platform Awareness: Respect each platform's unique characteristics
- Content Consistency: Maintain message consistency across platforms
- Review Criteria: Define clear content review standards
- Audience Focus: Keep target audience in mind throughout
- Feedback Integration: Effectively incorporate review feedback
Use Cases
This pattern is ideal for: - Social media management - Content marketing - Brand communication - Multi-platform publishing - Content localization
Next Steps
After implementing the Social Agents pattern, you can: 1. Add more social platforms 2. Implement A/B testing 3. Add engagement analytics 4. Enhance content personalization 5. Add scheduling capabilities