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.
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:
Manager Agent¶
- On the "Group Chat" tab, specify the Initial Agent and the Max Rounds fields.
- On the "Group Manager" tab, set the anager's name to "Manager" and select the model to use.
- On the "Speakers" tab, we can leave the selection method to "Auto", and the max retries to 10.
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:Link a model of your choice to the Engineer 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: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 use30
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.
- 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 the 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. Run the flow and review the logs and the generated blog post.
Files used in this example:
- Waldiez flow: Planning 1.waldiez
- Generated notebook: Planning 1.ipynb