The TAO of Prompt Engineering (Part-2): writing an email assistant

Michael Humor
3 min readMar 21, 2024

--

In the last article, we have introduced TAO (Thought-Action-Observation), a method for LLM prompt engineering. In this article, we focus on writing an email assistant in Python based on TAO.

1. TAO prompt template

First, we define our TAO prompt template as follows:

The TAO prompt template (inspired by ReAct)

The TAO template consists of three parts:

  1. define the tools — FindEmail, ReadCalendar, SendEmail, and WebSearch
  2. define the format — TAO state machine (Thought-Action-Observation can repeat N times)
  3. define the task — provided by user input

Define the tools

Each tool corresponds to a mapping from Action to a Python function:

A sample find_email implementation:

A sample send_email implementation:

A sample read_calendar implementation:

And a sample web_search implementation:

2. Define the LLM and stop criteria

Importantly, the stop parameter is defined as ['Observation:', 'Observation '], so that the LLM generation stops at the Observation token and that we can extract Action from the LLM response:

And we append the tool output to the prompt, to be used in the next TAO iteration:

3. Get task from user and limit TAO iterations

Finally, we get task from user, invoke llm_do_task, and limit the number of tool iterations:

Here is a full demo:

--

--