✍️ Blog Writing Agent

This example shows how to create an OpenAGI agent with three workers (Research Analyst, Tech Content Strategist, Review and Editing Specialist) to autonomously research, write, and review a blog post.

Import the Required Modules

First, import the necessary modules for setting up the agent. These modules include tools for internet searches, content writing, and memory management. The specific tools and classes used are:

from openagi.actions.files import WriteFileAction
from openagi.actions.tools.ddg_search import DuckDuckGoNewsSearch
from openagi.actions.tools.webloader import WebBaseContextTool
from openagi.agent import Admin
from openagi.llms.azure import AzureChatOpenAIModel
from openagi.memory import Memory
from openagi.planner.task_decomposer import TaskPlanner
from openagi.worker import Worker
from rich.console import Console
from rich.markdown import Markdown

Set Up the LLM (Large Language Model)

To configure the AzureChatOpenAIModel, you need to load the configuration from environment variables. This step ensures that the model can access the necessary endpoints and API keys to function correctly.

os.environ["AZURE_BASE_URL"]="https://<replace-with-your-endpoint>.openai.azure.com/"
os.environ["AZURE_DEPLOYMENT_NAME"] = "<replace-with-your-deployment-name>"
os.environ["AZURE_MODEL_NAME"]="gpt4-32k"
os.environ["AZURE_OPENAI_API_VERSION"]="2023-05-15"
os.environ["AZURE_OPENAI_API_KEY"]=  "<replace-with-your-key>"

config = AzureChatOpenAIModel.load_from_env_config()
llm = AzureChatOpenAIModel(config=config)

Define the Team Members

In this step, create worker agents with specific roles and instructions. Each worker is equipped with tools to perform their designated tasks.

  • Research Analyst: The Research Analyst conducts research on the latest developments in AI.

  • Tech Content Strategist: The Tech Content Strategist writes the blog post based on the research.

  • Review and Editing Specialist: The Review and Editing Specialist reviews and edits the blog post, ensuring clarity and grammatical accuracy.

Set Up the Admin

Configure the Admin to manage and coordinate the tasks. The Admin assigns tasks to the workers and oversees the entire workflow.

Run the Task

The Admin executes the task by providing a query and description. The task involves researching, writing, and reviewing a blog post about the future of AI.

Print the Results

Finally, print the results from the OpenAGI, displaying the content generated by the agent.

Output

The agent will create a file with the following content:

Last updated