Skip to content

Commit 51ef4aa

Browse files
committed
add prompt caching
1 parent 007c171 commit 51ef4aa

2 files changed

Lines changed: 79 additions & 21 deletions

File tree

src/agent/components/chains.py

Lines changed: 38 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
# Prompt
1515
opey_system_prompt_template = """You are a friendly, helpful assistant for the Open Bank Project API called Opey. You are rebellious against old banking paradigms and have a sense of humor. Always give the user accurate and helpful information.
1616
17-
Ensure Comprehensive Endpoint Awareness: Always use the endpoint retrieval tool to stay aware of and provide details on all available API capabilities before attempting to answer the user's question.
17+
Ensure Endpoint Awareness: Always use the endpoint retrieval tool to stay aware of and provide details on available API capabilities before attempting to answer the user's question.
18+
Assume that the endpoint retrieval tool has access to all the latest API endpoint information. And that you do not need to use the tool multiple times.
1819
1920
Efficiency priority: If there is a tool that can help answer the user's question, use it immediately without needing to be prompted. Try to avoid answering questions without using the tools.
2021
@@ -156,7 +157,16 @@ class QueryFormulatorOutput(BaseModel):
156157

157158
query_formulator_prompt_template = ChatPromptTemplate.from_messages(
158159
[
159-
SystemMessage(content=query_formulator_system_prompt),
160+
{
161+
"role": "system",
162+
"content": [
163+
{
164+
"type": "text",
165+
"text": query_formulator_system_prompt,
166+
"cache_control": {"type": "ephemeral"},
167+
}
168+
]
169+
},
160170
MessagesPlaceholder("messages"),
161171
]
162172
)
@@ -169,18 +179,32 @@ class QueryFormulatorOutput(BaseModel):
169179

170180

171181

172-
conversation_summarizer_system_prompt_template = PromptTemplate.from_template(
173-
"""
174-
You are a conversation summarizer that takes a list of messages and tries to summarize the conversation so far.\n
175-
The messages will consist of messages from the user, responses from the chatbot, and tool calls with responses.\n
176-
Try to summarize the conversation so far in a way that is concise and informative.\n
177-
If there is important information in the tools or the messages,\n
178-
such as a relevant bank ID user ID, or some other peice of data that is important to the users last message, include it in the summary message.
179-
180-
{existing_summary_message}
181-
182-
List of messages: {messages}
183-
"""
182+
conversation_summarizer_system_prompt_template = ChatPromptTemplate.from_messages(
183+
[
184+
{
185+
"role": "system",
186+
"content": [
187+
{
188+
"type": "text",
189+
"text": """You are a conversation summarizer that takes a list of messages and tries to summarize the conversation so far.\n
190+
The messages will consist of messages from the user, responses from the chatbot, and tool calls with responses.\n
191+
Try to summarize the conversation so far in a way that is concise and informative.\n
192+
If there is important information in the tools or the messages,\n
193+
such as a relevant bank ID user ID, or some other peice of data that is important to the users last message, include it in the summary message.""",
194+
"cache_control": {"type": "ephemeral"},
195+
}
196+
]
197+
},
198+
{
199+
"role": "user",
200+
"content": [
201+
{
202+
"type": "text",
203+
"text": "{existing_summary_message}\n\nList of messages: {messages}",
204+
}
205+
]
206+
}
207+
]
184208
)
185209

186210
conversation_summarizer_llm = get_model(model_name='medium', temperature=0)

src/agent/components/retrieval/endpoint_retrieval/components/chains.py

Lines changed: 41 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,31 @@ class GradeDocuments(BaseModel):
3030

3131
grader_prompt_template = ChatPromptTemplate.from_messages(
3232
[
33-
("system", grader_system_prompt),
34-
("human", "Retrieved document: \n\n {document} \n\n User question: {question}")
33+
# ("system", grader_system_prompt),
34+
# ("human", "Retrieved document: \n\n {document} \n\n User question: {question}")
35+
{
36+
"role": "system",
37+
"content": [
38+
{
39+
"type": "text",
40+
"text": grader_system_prompt,
41+
"cache_control": {"type": "ephemeral"},
42+
}
43+
]
44+
},
45+
{
46+
"role": "user",
47+
"content": [
48+
{
49+
"type": "text",
50+
"text": "Retrieved document: \n\n {document} \n\n User question: {question}",
51+
}
52+
]
53+
}
3554
]
3655
)
3756

57+
3858
retrieval_grader = grader_prompt_template | llm_grader
3959

4060

@@ -155,11 +175,25 @@ class GradeDocuments(BaseModel):
155175
"""
156176
re_write_prompt = ChatPromptTemplate.from_messages(
157177
[
158-
("system", system),
159-
(
160-
"human",
161-
"Here is the initial question: \n\n {question} \n Formulate an improved question.",
162-
),
178+
{
179+
"role": "system",
180+
"content": [
181+
{
182+
"type": "text",
183+
"text": system,
184+
"cache_control": {"type": "ephemeral"},
185+
}
186+
]
187+
},
188+
{
189+
"role": "user",
190+
"content": [
191+
{
192+
"type": "text",
193+
"text": "Here is the initial question: \n\n {question} \n Formulate an improved question.",
194+
}
195+
]
196+
}
163197
]
164198
)
165199

0 commit comments

Comments
 (0)