Agent Prompter
The Prompter
is a key component of the UFO framework, responsible for constructing prompts for the LLM to generate responses. The Prompter
is implemented in the ufo/prompts
folder. Each agent has its own Prompter
class that defines the structure of the prompt and the information to be fed to the LLM.
Components
A prompt fed to the LLM usually a list of dictionaries, where each dictionary contains the following keys:
Key | Description |
---|---|
role |
The role of the text in the prompt, can be system , user , or assistant . |
content |
The content of the text for the specific role. |
Tip
You may find the official documentation helpful for constructing the prompt.
In the __init__
method of the Prompter
class, you can define the template of the prompt for each component, and the final prompt message is constructed by combining the templates of each component using the prompt_construction
method.
System Prompt
The system prompt use the template configured in the config_dev.yaml
file for each agent. It usually contains the instructions for the agent's role, action, tips, reponse format, etc.
You need use the system_prompt_construction
method to construct the system prompt.
Prompts on the API instructions, and demonstration examples are also included in the system prompt, which are constructed by the api_prompt_helper
and examples_prompt_helper
methods respectively. Below is the sub-components of the system prompt:
Component | Description | Method |
---|---|---|
apis |
The API instructions for the agent. | api_prompt_helper |
examples |
The demonstration examples for the agent. | examples_prompt_helper |
User Prompt
The user prompt is constructed based on the information from the agent's observation, external knowledge, and Blackboard
. You can use the user_prompt_construction
method to construct the user prompt. Below is the sub-components of the user prompt:
Component | Description | Method |
---|---|---|
observation |
The observation of the agent. | user_content_construction |
retrieved_docs |
The knowledge retrieved from the external knowledge base. | retrived_documents_prompt_helper |
blackboard |
The information stored in the Blackboard . |
blackboard_to_prompt |
Reference
You can find the implementation of the Prompter
in the ufo/prompts
folder. Below is the basic structure of the Prompter
class:
Bases: ABC
The BasicPrompter class is the abstract class for the prompter.
Initialize the BasicPrompter.
Parameters: |
|
---|
Source code in prompter/basic.py
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
|
api_prompt_helper()
A helper function to construct the API list and descriptions for the prompt.
Source code in prompter/basic.py
139 140 141 142 143 144 |
|
examples_prompt_helper()
A helper function to construct the examples prompt for in-context learning.
Source code in prompter/basic.py
132 133 134 135 136 137 |
|
load_prompt_template(template_path, is_visual=None)
staticmethod
Load the prompt template.
Returns: |
|
---|
Source code in prompter/basic.py
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
|
prompt_construction(system_prompt, user_content)
staticmethod
Construct the prompt for summarizing the experience into an example.
Parameters: |
|
---|
Source code in prompter/basic.py
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
|
retrived_documents_prompt_helper(header, separator, documents)
staticmethod
Construct the prompt for retrieved documents.
Parameters: |
|
---|
Source code in prompter/basic.py
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
|
system_prompt_construction()
abstractmethod
Construct the system prompt for LLM.
Source code in prompter/basic.py
108 109 110 111 112 113 114 |
|
user_content_construction()
abstractmethod
Construct the full user content for LLM, including the user prompt and images.
Source code in prompter/basic.py
124 125 126 127 128 129 130 |
|
user_prompt_construction()
abstractmethod
Construct the textual user prompt for LLM based on the user
field in the prompt template.
Source code in prompter/basic.py
116 117 118 119 120 121 122 |
|
Tip
You can customize the Prompter
class to tailor the prompt to your requirements.