Skip to content

Planning

Planning and Stock Report Generation

In this example, we create a workflow to analyze stock price performance using multiple agents with specific roles. The task is to analyze Nvidia’s stock performance over the past month, retrieve relevant data, and generate a report.

Example 6 overview Example 6 overview

Overview

The workflow includes:

  • Admin Agent: Manages task delegation and provides instructions.
  • (Group) Manager Agent: Oversees execution by coordinating with specialized agents.
  • Planner Agent: Plans the sequence of steps to complete the analysis.
  • Engineer Agent: Writes code based on the plan provided by the planner.
  • Executor Agent: Executes the code written by the engineer and reports the result.
  • Writer Agent: Compiles the analysis into a blog post.

Agents setup

Admin Agent

Create a new user proxy agent named Admin and system message:

Give the task, and send instructions to writer to refine the blog post.

Manager Agent

  • Create a new group agent named Manager
  • On the "Group Chat" tab, specify the Admin Name and the Max Rounds fields. You can leave the speakers configuration as default (allow speakers repetition, and auto speaker selection method). We'll configure the speaker transitions in a next case. Group Manager Group Manager

Note

The Max Rounds field specifies the maximum number of rounds the group agent will run. The group agent will stop after reaching this limit. You might want to set this field to a high number to avoid stopping the group agent prematurely.

Group members

  • Drag and drop assistant agents to the manager agent:

    • Planner Agent: Create a new assistant agent named Planner and add the following system message:

      Given a task, please determine what information is needed to complete the task. Please note that the information will all be retrieved using Python code. Please only suggest information that can be retrieved using Python code. After each step is done by others, check the progress and instruct the remaining steps. If a step fails, try to workaround.
      

      Link a model of your choice to the Planner Agent. In our example, we use the gpt-4-turbo model.

  • Engineer Agent: Create a new assistant agent named Engineer. No need to add any system message, you can add a description if you want, something like:
    An engineer that writes code based on the plan provided by the planner.
    

    Link a model of your choice to the Planner Agent. In our example, we use the gpt-4-turbo model.

  • Executor Agent: Create a new assistant agent named Executor, with the following system message:
    Execute the code written by the engineer and report the result.
    

    On the Code Execution tab, enable the Use Code Execution option, set the Working Directory to coding, and set a default timeout for the code execution to wait. We use 30 seconds in this example, but you can increase it if needed.

    Do not link any model to the Executor Agent, this agent will not generate text, only execute code.

    Executor Executor

  • Writer Agent: Create a new assistant agent named Writer, with the following system message:
    Writer. Please write blogs in markdown format (with relevant titles) and put the content in pseudo ```md``` code block. You take feedback from the admin and refine your blog.
    

    Link a model of your choice to the Writer Agent. In our example, we use the gpt-4-turbo model.

Add agent connections and run the flow

1. Add a connection from the Admin agent to the Manager agent, to start the flow. For hte message we use a custom method:

def callable_message(sender, recipient, context):
"""Return the task."""
import datetime  # pylint: disable=import-outside-toplevel

today = datetime.datetime.now().date()
message = (
    "Write a blogpost about the stock price performance of "
    f"Nvidia in the past month. Today's date is {today}"
)
return message

2. Edit Flow: Set up the flow order to start with the "Admin => Manager" connection. 3. Run the flow and review the logs and the generated blog post. Logs Logs

Using custom transitions

Since the agents in the group do not need to interact with all the other agents, we can use custom transitions to manage the flow more effectively. In this example, we will set up custom transitions to limit what agents can speak to each other.

On the manger agent, Group Chat tab, Speakers section, we can set up the transitions between the agents. The Admin can speak to all the agents (well it's an admin, right?), the Engineer can speak to the Admin amd the Executor agent, the Executor can speak to the Admin the Engineer and the Planner, the Planner to Admin, Engineer and the Writer and the Writer to the Admin and the Planner.

Logs Logs


Files used in this example: