Skip to content

Reflection

Reflection and Blog post WritingΒΆ

Example 3 overview Example 3 overview

In this example, we will setup up a workflow for reviewing and improving blog posts using nested chats. The workflow includes roles for a writer, critic, and various reviewers (SEO, Legal, Ethics, and Meta).

Agent RolesΒΆ

  • Writer: Writes blog posts based on given topics.
  • Critic: Asks for reviews and provides feedback on the writer's work.
  • SEO Reviewer: Optimizes content for search engines.
  • Legal Reviewer: Ensures content is legally compliant.
  • Ethics Reviewer: Ensures content is ethically sound.
  • Meta Reviewer: Aggregates feedback from other reviewers.

Models UsedΒΆ

Feel free to use any models that suit your requirements. Here are the models used in this example:

  • SEO Reviewer: gpt-3.5-turbo
  • Legal Reviewer: gpt-3.5-turbo
  • Ethics Reviewer: gpt-3.5-turbo
  • Meta Reviewer: gpt-3.5-turbo
  • Writer: gpt-3.5-turbo
  • Critic: gpt-3.5-turbo

Setup the AgentsΒΆ

SEO ReviewerΒΆ

  1. Add an agent named SEO reviewer.
  2. In the System Message, set:

    You are an SEO reviewer, known for your ability to optimize content for search engines, ensuring that it ranks well and attracts organic traffic. Make sure your suggestion is concise (within 3 bullet points), concrete and to the point. Begin the review by stating your role.
    
  3. Link the agent to a model.

  1. Add an agent named Legal reviewer.
  2. In the System Message, set:

    You are a legal reviewer, known for your ability to ensure that content is legally compliant and free from any potential legal issues. Make sure your suggestion is concise (within 3 bullet points), concrete and to the point. Begin the review by stating your role.
    
  3. Link the agent to a model.

Ethics ReviewerΒΆ

  1. Add an agent named Ethics reviewer.
  2. In the System Message, set:

    You are an ethics reviewer, known for your ability to ensure that content is ethically sound and free from any potential ethical issues. Make sure your suggestion is concise (within 3 bullet points), concrete and to the point. Begin the review by stating your role.
    
  3. Link the agent to a model.

Meta ReviewerΒΆ

  1. Add an agent named Meta reviewer.
  2. In the System Message, set:

    You are a meta reviewer, you aggregate and review the work of other reviewers and give a final suggestion on the content.
    
  3. Link the agent to a model.


Writer AgentΒΆ

  1. Add a new agent named Writer.
  2. In the System Message, set:

    You are a writer. You write engaging and concise blog posts (with title) on given topics. You must polish your writing based on the feedback you receive and give a refined version. Only return your final work without additional comments.
    
  3. Link the agent to a model.

Critic AgentΒΆ

  1. Add a new agent named Critic.
  2. In the System Message, set:

    You are a critic. You review the work of the writer and provide constructive feedback to help improve the quality of the content.
    
  3. Link the agent to a model.

Note

We will come back to the Critic agent to configure nested chats after setting up the agent connections.


Agent ConnectionsΒΆ

Writer => CriticΒΆ

  1. Connect the Critic agent to the Writer agent.
  2. On the message tab, set the type to "Text" and the content to:
    Write a concise but engaging blog post about DeepLearning.AI. Make sure the blog post is within 100 words.
    

Nested chatsΒΆ

For the rest of the connections, we will set up nested chats to gather feedback from the SEO, Legal, Ethics, and Meta reviewers. Add a link from the Critic agent to each of the reviewers, and set the chat type to "Nested Chat". Set Max turns to 1 and Summary method to "Last Message". For the nested chat content, we will use a custom method to send the content to the SEO, Legal, and Ethics reviewers:

def nested_chat_message(recipient, messages, sender, config):
"""Ask for a review."""
return f"""Review the following content.
        \n\n {recipient.chat_messages_for_summary(sender)[-1]['content']}"""

Nested Chat message Nested Chat message

For the Meta reviewer, we use the "Text" type:

Aggregate feedback from all reviewers and give final suggestions on the writing.

Nested chat registrationΒΆ

  1. Go to the Critic agent’s settings and navigate to the Nested Chats tab.
  2. The nested chat is triggered when the writer replies to the critic's message with the content to be reviewed, so on the "Triggered by" select the Writer agent and check the "Agent's reply" box.
  3. Set up the messages to be sent when the chat is triggered:
    • Critic => SEO reviewer
    • Critic => Legal reviewer
    • Critic => Ethics reviewer
    • Critic => Meta reviewer

4. Workflow Flow OrderΒΆ

  1. Open the Edit Flow menu.
  2. Name the flow as Reflection or another suitable name.
  3. Set the initial flow order to start with Critic => Writer.

5. Run the flowΒΆ

We are ready to run the flow. Hit the play button to start the flow. The critic will ask the writer to write a blog post about DeepLearning.AI. The writer will then write the blog post and send it to the critic for review. The critic will then send the content to the SEO, Legal, Ethics, and Meta reviewers for feedback. You can check the logs to see the flow of the conversation.

Nested Chat message Nested Chat message

Files used in this example: