In this lesson, we’ll create a simple multi-agent system where several agents work together to accomplish a task. This approach allows you to divide complex problems into smaller, more manageable pieces.
# Research Agentresearch_agent = Agent( name="Researcher", instructions=""" You are a research specialist who excels at finding relevant information. Your job is to: 1. Thoroughly research the given topic 2. Identify key facts, statistics, and insights 3. Organize the information in a clear, structured format 4. Provide accurate information with no fabrications 5. Focus on the most relevant and current information """)# Writing Agentwriting_agent = Agent( name="Writer", instructions=""" You are a content writer who creates engaging, reader-friendly content. Your job is to: 1. Use the research provided to create well-structured content 2. Write in a clear, engaging style 3. Include an attention-grabbing introduction 4. Organize the content with appropriate headings 5. Conclude with a summary and call-to-action when appropriate """)# Editing Agentediting_agent = Agent( name="Editor", instructions=""" You are an editor who refines and improves content. Your job is to: 1. Correct any grammatical or spelling errors 2. Improve clarity and flow 3. Ensure consistency in tone and style 4. Check for logical structure and organization 5. Enhance readability for the target audience """)
Next, we need to define how our agents will work together:
# Define a topictopic = "The Benefits of Regular Exercise"# Start the multi-agent processresults = content_team.start( f""" Task: Create a comprehensive blog post about {topic} Process: 1. Researcher: Research {topic} and provide key information including: - Main benefits of exercise (physical and mental) - Recommended exercise guidelines - Scientific studies supporting the benefits - Common misconceptions 2. Writer: Use the research to create a 500-word blog post about {topic} with: - An engaging introduction - Clear sections with headings - Practical advice for readers - A compelling conclusion 3. Editor: Review and improve the blog post by: - Correcting any errors - Enhancing clarity and flow - Ensuring a consistent tone - Making the content more engaging """)# Print the final resultprint(results)
You can customize how agents interact by modifying the process instructions. For example, you could add feedback loops:
process_with_feedback = """Task: Create a comprehensive blog post about {topic}Process:1. Researcher: Research {topic} and provide key information2. Writer: Use the research to create a blog post3. Editor: Review the blog post and provide feedback4. Writer: Revise the blog post based on the editor's feedback5. Editor: Make final improvements to the revised blog post"""
parallel_process = """Task: Create a marketing campaign for a new productProcess:1. Market Researcher: Research the target market and competitors Content Researcher: Research the product features and benefits [These tasks happen in parallel]2. Strategy Agent: Use both research results to create a marketing strategy3. Content Creator: Create the marketing materials based on the strategy"""