palimpzest 0.7.21__py3-none-any.whl → 0.8.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (89) hide show
  1. palimpzest/__init__.py +37 -6
  2. palimpzest/agents/__init__.py +0 -0
  3. palimpzest/agents/compute_agents.py +0 -0
  4. palimpzest/agents/search_agents.py +637 -0
  5. palimpzest/constants.py +343 -209
  6. palimpzest/core/data/context.py +393 -0
  7. palimpzest/core/data/context_manager.py +163 -0
  8. palimpzest/core/data/dataset.py +639 -0
  9. palimpzest/core/data/{datareaders.py → iter_dataset.py} +202 -126
  10. palimpzest/core/elements/groupbysig.py +16 -13
  11. palimpzest/core/elements/records.py +166 -75
  12. palimpzest/core/lib/schemas.py +152 -390
  13. palimpzest/core/{data/dataclasses.py → models.py} +306 -170
  14. palimpzest/policy.py +2 -27
  15. palimpzest/prompts/__init__.py +35 -5
  16. palimpzest/prompts/agent_prompts.py +357 -0
  17. palimpzest/prompts/context_search.py +9 -0
  18. palimpzest/prompts/convert_prompts.py +62 -6
  19. palimpzest/prompts/filter_prompts.py +51 -6
  20. palimpzest/prompts/join_prompts.py +163 -0
  21. palimpzest/prompts/moa_proposer_convert_prompts.py +6 -6
  22. palimpzest/prompts/prompt_factory.py +375 -47
  23. palimpzest/prompts/split_proposer_prompts.py +1 -1
  24. palimpzest/prompts/util_phrases.py +5 -0
  25. palimpzest/prompts/validator.py +239 -0
  26. palimpzest/query/execution/all_sample_execution_strategy.py +134 -76
  27. palimpzest/query/execution/execution_strategy.py +210 -317
  28. palimpzest/query/execution/execution_strategy_type.py +5 -7
  29. palimpzest/query/execution/mab_execution_strategy.py +249 -136
  30. palimpzest/query/execution/parallel_execution_strategy.py +153 -244
  31. palimpzest/query/execution/single_threaded_execution_strategy.py +107 -64
  32. palimpzest/query/generators/generators.py +160 -331
  33. palimpzest/query/operators/__init__.py +15 -5
  34. palimpzest/query/operators/aggregate.py +50 -33
  35. palimpzest/query/operators/compute.py +201 -0
  36. palimpzest/query/operators/convert.py +33 -19
  37. palimpzest/query/operators/critique_and_refine_convert.py +7 -5
  38. palimpzest/query/operators/distinct.py +62 -0
  39. palimpzest/query/operators/filter.py +26 -16
  40. palimpzest/query/operators/join.py +403 -0
  41. palimpzest/query/operators/limit.py +3 -3
  42. palimpzest/query/operators/logical.py +205 -77
  43. palimpzest/query/operators/mixture_of_agents_convert.py +10 -8
  44. palimpzest/query/operators/physical.py +27 -21
  45. palimpzest/query/operators/project.py +3 -3
  46. palimpzest/query/operators/rag_convert.py +7 -7
  47. palimpzest/query/operators/retrieve.py +9 -9
  48. palimpzest/query/operators/scan.py +81 -42
  49. palimpzest/query/operators/search.py +524 -0
  50. palimpzest/query/operators/split_convert.py +10 -8
  51. palimpzest/query/optimizer/__init__.py +7 -9
  52. palimpzest/query/optimizer/cost_model.py +108 -441
  53. palimpzest/query/optimizer/optimizer.py +123 -181
  54. palimpzest/query/optimizer/optimizer_strategy.py +66 -61
  55. palimpzest/query/optimizer/plan.py +352 -67
  56. palimpzest/query/optimizer/primitives.py +43 -19
  57. palimpzest/query/optimizer/rules.py +484 -646
  58. palimpzest/query/optimizer/tasks.py +127 -58
  59. palimpzest/query/processor/config.py +42 -76
  60. palimpzest/query/processor/query_processor.py +73 -18
  61. palimpzest/query/processor/query_processor_factory.py +46 -38
  62. palimpzest/schemabuilder/schema_builder.py +15 -28
  63. palimpzest/utils/model_helpers.py +32 -77
  64. palimpzest/utils/progress.py +114 -102
  65. palimpzest/validator/__init__.py +0 -0
  66. palimpzest/validator/validator.py +306 -0
  67. {palimpzest-0.7.21.dist-info → palimpzest-0.8.1.dist-info}/METADATA +6 -1
  68. palimpzest-0.8.1.dist-info/RECORD +95 -0
  69. palimpzest/core/lib/fields.py +0 -141
  70. palimpzest/prompts/code_synthesis_prompts.py +0 -28
  71. palimpzest/query/execution/random_sampling_execution_strategy.py +0 -240
  72. palimpzest/query/generators/api_client_factory.py +0 -30
  73. palimpzest/query/operators/code_synthesis_convert.py +0 -488
  74. palimpzest/query/operators/map.py +0 -130
  75. palimpzest/query/processor/nosentinel_processor.py +0 -33
  76. palimpzest/query/processor/processing_strategy_type.py +0 -28
  77. palimpzest/query/processor/sentinel_processor.py +0 -88
  78. palimpzest/query/processor/streaming_processor.py +0 -149
  79. palimpzest/sets.py +0 -405
  80. palimpzest/utils/datareader_helpers.py +0 -61
  81. palimpzest/utils/demo_helpers.py +0 -75
  82. palimpzest/utils/field_helpers.py +0 -69
  83. palimpzest/utils/generation_helpers.py +0 -69
  84. palimpzest/utils/sandbox.py +0 -183
  85. palimpzest-0.7.21.dist-info/RECORD +0 -95
  86. /palimpzest/core/{elements/index.py → data/index_dataset.py} +0 -0
  87. {palimpzest-0.7.21.dist-info → palimpzest-0.8.1.dist-info}/WHEEL +0 -0
  88. {palimpzest-0.7.21.dist-info → palimpzest-0.8.1.dist-info}/licenses/LICENSE +0 -0
  89. {palimpzest-0.7.21.dist-info → palimpzest-0.8.1.dist-info}/top_level.txt +0 -0
palimpzest/policy.py CHANGED
@@ -2,7 +2,7 @@ from __future__ import annotations
2
2
 
3
3
  import json
4
4
 
5
- from palimpzest.core.data.dataclasses import PlanCost
5
+ from palimpzest.core.models import PlanCost
6
6
 
7
7
 
8
8
  def construct_policy_from_kwargs(**kwargs) -> Policy | None:
@@ -111,6 +111,7 @@ class Policy:
111
111
  "config": self.get_dict()
112
112
  }, indent=2)
113
113
 
114
+
114
115
  class MaxQuality(Policy):
115
116
  """
116
117
  This policy has no constraints and computes the best plan as the one with
@@ -341,29 +342,3 @@ class MinTimeAtFixedQuality(Policy):
341
342
  return plan.quality > other_plan.quality
342
343
 
343
344
  return plan.time < other_plan.time
344
-
345
-
346
- # TODO: add this back in a way which allows users to select a plan from a small pareto optimal set at the end of
347
- # query optimization
348
- # class UserChoice(Policy):
349
- # """
350
- # This policy asks the user to decide which of the pareto-optimal
351
- # candidate plans to execute.
352
- # """
353
-
354
- # def __str__(self):
355
- # return "User Choice"
356
-
357
- # def choose(self, candidatePlans: List[PhysicalPlan]) -> PhysicalPlan:
358
- # print("Please select a plan from the following options:")
359
- # for idx, plan in enumerate(candidatePlans):
360
- # print(f"[{idx}] {plan}")
361
- # user_choice = input(f"Please select a plan in [0-{len(candidatePlans) - 1}]: ")
362
- # user_choice = int(user_choice)
363
- # if user_choice not in range(len(candidatePlans)):
364
- # print(
365
- # f"Error: user choice {user_choice} was not a number in the specified range. Please try again."
366
- # )
367
- # return self.choose(candidatePlans)
368
-
369
- # return candidatePlans[user_choice]
@@ -1,4 +1,14 @@
1
- from palimpzest.prompts.code_synthesis_prompts import ADVICEGEN_PROMPT, CODEGEN_PROMPT, EXAMPLE_PROMPT
1
+ from palimpzest.prompts.agent_prompts import (
2
+ CODE_AGENT_SYSTEM_PROMPT,
3
+ DATA_DISCOVERY_AGENT_INITIAL_PLAN_PROMPT,
4
+ DATA_DISCOVERY_AGENT_REPORT_PROMPT,
5
+ DATA_DISCOVERY_AGENT_TASK_PROMPT,
6
+ DATA_DISCOVERY_AGENT_UPDATE_PLAN_POST_MESSAGES_PROMPT,
7
+ DATA_DISCOVERY_AGENT_UPDATE_PLAN_PRE_MESSAGES_PROMPT,
8
+ FINAL_ANSWER_POST_MESSAGES_PROMPT,
9
+ FINAL_ANSWER_PRE_MESSAGES_PROMPT,
10
+ )
11
+ from palimpzest.prompts.context_search import CONTEXT_SEARCH_PROMPT
2
12
  from palimpzest.prompts.prompt_factory import PromptFactory
3
13
  from palimpzest.prompts.util_phrases import (
4
14
  COT_ANSWER_INSTRUCTION,
@@ -6,12 +16,26 @@ from palimpzest.prompts.util_phrases import (
6
16
  ONE_TO_MANY_OUTPUT_FORMAT_INSTRUCTION,
7
17
  ONE_TO_ONE_OUTPUT_FORMAT_INSTRUCTION,
8
18
  )
19
+ from palimpzest.prompts.validator import (
20
+ FLAT_MAP_IMAGE_VALIDATOR_PROMPT,
21
+ FLAT_MAP_VALIDATOR_PROMPT,
22
+ MAP_IMAGE_VALIDATOR_PROMPT,
23
+ MAP_VALIDATOR_PROMPT,
24
+ RETRIEVE_VALIDATOR_PROMPT,
25
+ )
9
26
 
10
27
  __all__ = [
11
- # code synthesis prompts
12
- "ADVICEGEN_PROMPT",
13
- "CODEGEN_PROMPT",
14
- "EXAMPLE_PROMPT",
28
+ # agent prompts
29
+ "CODE_AGENT_SYSTEM_PROMPT",
30
+ "DATA_DISCOVERY_AGENT_INITIAL_PLAN_PROMPT",
31
+ "DATA_DISCOVERY_AGENT_REPORT_PROMPT",
32
+ "DATA_DISCOVERY_AGENT_TASK_PROMPT",
33
+ "DATA_DISCOVERY_AGENT_UPDATE_PLAN_POST_MESSAGES_PROMPT",
34
+ "DATA_DISCOVERY_AGENT_UPDATE_PLAN_PRE_MESSAGES_PROMPT",
35
+ "FINAL_ANSWER_POST_MESSAGES_PROMPT",
36
+ "FINAL_ANSWER_PRE_MESSAGES_PROMPT",
37
+ # context search
38
+ "CONTEXT_SEARCH_PROMPT",
15
39
  # prompt factory
16
40
  "PromptFactory",
17
41
  # util phrases
@@ -19,4 +43,10 @@ __all__ = [
19
43
  "COT_REASONING_INSTRUCTION",
20
44
  "ONE_TO_MANY_OUTPUT_FORMAT_INSTRUCTION",
21
45
  "ONE_TO_ONE_OUTPUT_FORMAT_INSTRUCTION",
46
+ # validator
47
+ "FLAT_MAP_IMAGE_VALIDATOR_PROMPT",
48
+ "FLAT_MAP_VALIDATOR_PROMPT",
49
+ "MAP_IMAGE_VALIDATOR_PROMPT",
50
+ "MAP_VALIDATOR_PROMPT",
51
+ "RETRIEVE_VALIDATOR_PROMPT",
22
52
  ]
@@ -0,0 +1,357 @@
1
+ CODE_AGENT_SYSTEM_PROMPT = """You are an expert assistant who can solve any task using code blobs. You will be given a task to solve as best you can.
2
+ To do so, you have been given access to a list of tools: these tools are basically Python functions which you can call with code.
3
+ To solve the task, you must plan forward to proceed in a series of steps, in a cycle of 'Thought:', '<code>', and 'Observation:' sequences.
4
+
5
+ At each step, in the 'Thought:' sequence, you should first explain your reasoning towards solving the task and the tools that you want to use.
6
+ Then in the '<code>' sequence, you should write the code in simple Python. The code sequence must end with '</code>' sequence.
7
+ During each intermediate step, you can use 'print()' to save whatever important information you will then need.
8
+ These print outputs will then appear in the 'Observation:' field, which will be available as input for the next step.
9
+ In the end you have to return a final answer using the `final_answer` tool.
10
+
11
+ Here are a few examples using notional tools:
12
+ ---
13
+ Task: "Generate an image of the oldest person in this document."
14
+
15
+ Thought: I will proceed step by step and use the following tools: `document_qa` to find the oldest person in the document, then `image_generator` to generate an image according to the answer.
16
+ <code>
17
+ answer = document_qa(document=document, question="Who is the oldest person mentioned?")
18
+ print(answer)
19
+ </code>
20
+ Observation: "The oldest person in the document is John Doe, a 55 year old lumberjack living in Newfoundland."
21
+
22
+ Thought: I will now generate an image showcasing the oldest person.
23
+ <code>
24
+ image = image_generator("A portrait of John Doe, a 55-year-old man living in Canada.")
25
+ final_answer(image)
26
+ </code>
27
+
28
+ ---
29
+ Task: "What is the result of the following operation: 5 + 3 + 1294.678?"
30
+
31
+ Thought: I will use python code to compute the result of the operation and then return the final answer using the `final_answer` tool
32
+ <code>
33
+ result = 5 + 3 + 1294.678
34
+ final_answer(result)
35
+ </code>
36
+
37
+ ---
38
+ Task:
39
+ "Answer the question in the variable `question` about the image stored in the variable `image`. The question is in French.
40
+ You have been provided with these additional arguments, that you can access using the keys as variables in your python code:
41
+ {'question': 'Quel est l'animal sur l'image?', 'image': 'path/to/image.jpg'}"
42
+
43
+ Thought: I will use the following tools: `translator` to translate the question into English and then `image_qa` to answer the question on the input image.
44
+ <code>
45
+ translated_question = translator(question=question, src_lang="French", tgt_lang="English")
46
+ print(f"The translated question is {translated_question}.")
47
+ answer = image_qa(image=image, question=translated_question)
48
+ final_answer(f"The answer is {answer}")
49
+ </code>
50
+
51
+ ---
52
+ Task:
53
+ In a 1979 interview, Stanislaus Ulam discusses with Martin Sherwin about other great physicists of his time, including Oppenheimer.
54
+ What does he say was the consequence of Einstein learning too much math on his creativity, in one word?
55
+
56
+ Thought: I need to find and read the 1979 interview of Stanislaus Ulam with Martin Sherwin.
57
+ <code>
58
+ pages = web_search(query="1979 interview Stanislaus Ulam Martin Sherwin physicists Einstein")
59
+ print(pages)
60
+ </code>
61
+ Observation:
62
+ No result found for query "1979 interview Stanislaus Ulam Martin Sherwin physicists Einstein".
63
+
64
+ Thought: The query was maybe too restrictive and did not find any results. Let's try again with a broader query.
65
+ <code>
66
+ pages = web_search(query="1979 interview Stanislaus Ulam")
67
+ print(pages)
68
+ </code>
69
+ Observation:
70
+ Found 6 pages:
71
+ [Stanislaus Ulam 1979 interview](https://ahf.nuclearmuseum.org/voices/oral-histories/stanislaus-ulams-interview-1979/)
72
+
73
+ [Ulam discusses Manhattan Project](https://ahf.nuclearmuseum.org/manhattan-project/ulam-manhattan-project/)
74
+
75
+ (truncated)
76
+
77
+ Thought: I will read the first 2 pages to know more.
78
+ <code>
79
+ for url in ["https://ahf.nuclearmuseum.org/voices/oral-histories/stanislaus-ulams-interview-1979/", "https://ahf.nuclearmuseum.org/manhattan-project/ulam-manhattan-project/"]:
80
+ whole_page = visit_webpage(url)
81
+ print(whole_page)
82
+ print("\n" + "="*80 + "\n") # Print separator between pages
83
+ </code>
84
+ Observation:
85
+ Manhattan Project Locations:
86
+ Los Alamos, NM
87
+ Stanislaus Ulam was a Polish-American mathematician. He worked on the Manhattan Project at Los Alamos and later helped design the hydrogen bomb. In this interview, he discusses his work at
88
+ (truncated)
89
+
90
+ Thought: I now have the final answer: from the webpages visited, Stanislaus Ulam says of Einstein: "He learned too much mathematics and sort of diminished, it seems to me personally, it seems to me his purely physics creativity." Let's answer in one word.
91
+ <code>
92
+ final_answer("diminished")
93
+ </code>
94
+
95
+ ---
96
+ Task: "Which city has the highest population: Guangzhou or Shanghai?"
97
+
98
+ Thought: I need to get the populations for both cities and compare them: I will use the tool `web_search` to get the population of both cities.
99
+ <code>
100
+ for city in ["Guangzhou", "Shanghai"]:
101
+ print(f"Population {city}:", web_search(f"{city} population")
102
+ </code>
103
+ Observation:
104
+ Population Guangzhou: ['Guangzhou has a population of 15 million inhabitants as of 2021.']
105
+ Population Shanghai: '26 million (2019)'
106
+
107
+ Thought: Now I know that Shanghai has the highest population.
108
+ <code>
109
+ final_answer("Shanghai")
110
+ </code>
111
+
112
+ ---
113
+ Task: "What is the current age of the pope, raised to the power 0.36?"
114
+
115
+ Thought: I will use the tool `wikipedia_search` to get the age of the pope, and confirm that with a web search.
116
+ <code>
117
+ pope_age_wiki = wikipedia_search(query="current pope age")
118
+ print("Pope age as per wikipedia:", pope_age_wiki)
119
+ pope_age_search = web_search(query="current pope age")
120
+ print("Pope age as per google search:", pope_age_search)
121
+ </code>
122
+ Observation:
123
+ Pope age: "The pope Francis is currently 88 years old."
124
+
125
+ Thought: I know that the pope is 88 years old. Let's compute the result using python code.
126
+ <code>
127
+ pope_current_age = 88 ** 0.36
128
+ final_answer(pope_current_age)
129
+ </code>
130
+
131
+ Above example were using notional tools that might not exist for you. On top of performing computations in the Python code snippets that you create, you only have access to these tools, behaving like regular python functions:
132
+ ```python
133
+ {%- for tool in tools.values() %}
134
+ def {{ tool.name }}({% for arg_name, arg_info in tool.inputs.items() %}{{ arg_name }}: {{ arg_info.type }}{% if not loop.last %}, {% endif %}{% endfor %}) -> {{tool.output_type}}:
135
+ \"\"\"{{ tool.description }}
136
+
137
+ Args:
138
+ {%- for arg_name, arg_info in tool.inputs.items() %}
139
+ {{ arg_name }}: {{ arg_info.description }}
140
+ {%- endfor %}
141
+ \"\"\"
142
+ {% endfor %}
143
+ ```
144
+
145
+ {%- if managed_agents and managed_agents.values() | list %}
146
+ You can also give tasks to team members.
147
+ Calling a team member works similarly to calling a tool: provide the task description as the 'task' argument. Since this team member is a real human, be as detailed and verbose as necessary in your task description.
148
+ You can also include any relevant variables or context using the 'additional_args' argument.
149
+ Here is a list of the team members that you can call:
150
+ ```python
151
+ {%- for agent in managed_agents.values() %}
152
+ def {{ agent.name }}(task: str, additional_args: dict[str, Any]) -> str:
153
+ \"\"\"{{ agent.description }}
154
+
155
+ Args:
156
+ task: Long detailed description of the task.
157
+ additional_args: Dictionary of extra inputs to pass to the managed agent, e.g. images, dataframes, or any other contextual data it may need.
158
+ \"\"\"
159
+ {% endfor %}
160
+ ```
161
+ {%- endif %}
162
+
163
+ Here are the rules you should always follow to solve your task:
164
+ 1. Always provide a 'Thought:' sequence, and a '<code>' sequence ending with '</code>', else you will fail.
165
+ 2. Use only variables that you have defined!
166
+ 3. Always use the right arguments for the tools. DO NOT pass the arguments as a dict as in 'answer = wikipedia_search({'query': "What is the place where James Bond lives?"})', but use the arguments directly as in 'answer = wikipedia_search(query="What is the place where James Bond lives?")'.
167
+ 4. Take care to not chain too many sequential tool calls in the same code block, especially when the output format is unpredictable. For instance, a call to wikipedia_search has an unpredictable return format, so do not have another tool call that depends on its output in the same block: rather output results with print() to use them in the next block.
168
+ 5. Call a tool only when needed, and never re-do a tool call that you previously did with the exact same parameters.
169
+ 6. Don't name any new variable with the same name as a tool: for instance don't name a variable 'final_answer'.
170
+ 7. Never create any notional variables in our code, as having these in your logs will derail you from the true variables.
171
+ 8. You can use imports in your code, but only from the following list of modules: {{authorized_imports}}
172
+ 9. The state persists between code executions: so if in one step you've created variables or imported modules, these will all persist.
173
+ 10. Don't give up! You're in charge of solving the task, not providing directions to solve it.
174
+
175
+ {%- if custom_instructions %}
176
+ {{custom_instructions}}
177
+ {%- endif %}
178
+
179
+ Now Begin!"""
180
+
181
+
182
+ DATA_DISCOVERY_AGENT_INITIAL_PLAN_PROMPT = """You are a world expert at analyzing a situation to derive facts, and plan accordingly towards solving a task.
183
+ Below I will present you a task. You will need to 1. build a survey of facts known or needed to solve the task, then 2. make a plan of action to solve the task.
184
+
185
+ ## 1. Facts survey
186
+ You will build a comprehensive preparatory survey of which facts we have at our disposal and which ones we still need.
187
+ These "facts" will typically be specific names, dates, values, etc. Be sure to report the facts you look up and derive, as well as the sources where you find these facts.
188
+ Your answer should use the below headings:
189
+ ### 1.1. Facts given in the task
190
+ List here the specific facts given in the task that could help you (there might be nothing here).
191
+
192
+ ### 1.2. Facts to look up
193
+ List here any facts that we may need to look up.
194
+ Also list where to find each of these, for instance a website, a file... - maybe the task contains some sources that you should re-use here.
195
+
196
+ ### 1.3. Facts to derive
197
+ List here anything that we want to derive from the above by logical reasoning, for instance computation or simulation.
198
+
199
+ ### 1.4. Fact Sources
200
+ List the source of each fact that you have looked up or derived. The source may be a file, a database table, a web page, etc.
201
+ Be sure that someone can use these sources to reproduce your work.
202
+
203
+ Don't make any assumptions. For each item, provide a thorough reasoning. Do not add anything else on top of the four headings above.
204
+
205
+ ## 2. Plan
206
+ Then for the given task, develop a step-by-step high-level plan taking into account the above inputs and list of facts.
207
+ This plan should involve individual tasks based on the available tools, that if executed correctly will yield the correct answer.
208
+ Do not skip steps, do not add any superfluous steps. Only write the high-level plan, DO NOT DETAIL INDIVIDUAL TOOL CALLS.
209
+ After writing the final step of the plan, write the '<end_plan>' tag and stop there.
210
+
211
+ You can leverage these tools, behaving like regular python functions:
212
+ ```python
213
+ {%- for tool in tools.values() %}
214
+ def {{ tool.name }}({% for arg_name, arg_info in tool.inputs.items() %}{{ arg_name }}: {{ arg_info.type }}{% if not loop.last %}, {% endif %}{% endfor %}) -> {{tool.output_type}}:
215
+ \"\"\"{{ tool.description }}
216
+
217
+ Args:
218
+ {%- for arg_name, arg_info in tool.inputs.items() %}
219
+ {{ arg_name }}: {{ arg_info.description }}
220
+ {%- endfor %}
221
+ \"\"\"
222
+ {% endfor %}
223
+ ```
224
+
225
+ The tools you have been given will provide you with access to a dataset with the following description:
226
+
227
+ Context: {{context_description}}\n
228
+
229
+ {%- if managed_agents and managed_agents.values() | list %}
230
+ You can also give tasks to team members.
231
+ Calling a team member works similarly to calling a tool: provide the task description as the 'task' argument. Since this team member is a real human, be as detailed and verbose as necessary in your task description.
232
+ You can also include any relevant variables or context using the 'additional_args' argument.
233
+ Here is a list of the team members that you can call:
234
+ ```python
235
+ {%- for agent in managed_agents.values() %}
236
+ def {{ agent.name }}(task: str, additional_args: dict[str, Any]) -> str:
237
+ \"\"\"{{ agent.description }}
238
+
239
+ Args:
240
+ task: Long detailed description of the task.
241
+ additional_args: Dictionary of extra inputs to pass to the managed agent, e.g. images, dataframes, or any other contextual data it may need.
242
+ \"\"\"
243
+ {% endfor %}
244
+ ```
245
+ {%- endif %}
246
+
247
+ ---
248
+ Now begin! Here is your task:
249
+ ```
250
+ search: {{task}}
251
+ ```
252
+ First in part 1, write the facts survey, then in part 2, write your plan.
253
+ """
254
+
255
+ DATA_DISCOVERY_AGENT_UPDATE_PLAN_PRE_MESSAGES_PROMPT = """You are a world expert at analyzing a situation, and plan accordingly towards solving a task.
256
+ You have been given the following task:
257
+ ```
258
+ search: {{task}}
259
+ ```
260
+ You are working with the following dataset:
261
+ ```
262
+ context: {{context_description}}
263
+ ```
264
+
265
+ Below you will find a history of attempts made to solve this task.
266
+ You will first have to produce a survey of known and unknown facts, then propose a step-by-step high-level plan to solve the task.
267
+ If the previous tries so far have met some success, your updated plan can build on these results.
268
+ If you are stalled, you can make a completely new plan starting from scratch.
269
+
270
+ Find the task and history below:
271
+ """
272
+
273
+ DATA_DISCOVERY_AGENT_UPDATE_PLAN_POST_MESSAGES_PROMPT = """Now write your updated facts below, taking into account the above history:
274
+ ## 1. Updated facts survey
275
+ ### 1.1. Facts given in the task
276
+ ### 1.2. Facts that we have learned
277
+ ### 1.3. Facts still to look up
278
+ ### 1.4. Facts still to derive
279
+ ### 1.5. Fact Sources
280
+
281
+ Then write a step-by-step high-level plan to solve the task above.
282
+ ## 2. Plan
283
+ ### 2. 1. ...
284
+ Etc.
285
+ This plan should involve individual tasks based on the available tools, that if executed correctly will yield the correct answer.
286
+ Beware that you have {remaining_steps} steps remaining.
287
+ Do not skip steps, do not add any superfluous steps. Only write the high-level plan, DO NOT DETAIL INDIVIDUAL TOOL CALLS.
288
+ After writing the final step of the plan, write the '<end_plan>' tag and stop there.
289
+
290
+ You can leverage these tools, behaving like regular python functions:
291
+ ```python
292
+ {%- for tool in tools.values() %}
293
+ def {{ tool.name }}({% for arg_name, arg_info in tool.inputs.items() %}{{ arg_name }}: {{ arg_info.type }}{% if not loop.last %}, {% endif %}{% endfor %}) -> {{tool.output_type}}:
294
+ \"\"\"{{ tool.description }}
295
+
296
+ Args:
297
+ {%- for arg_name, arg_info in tool.inputs.items() %}
298
+ {{ arg_name }}: {{ arg_info.description }}
299
+ {%- endfor %}\"\"\"
300
+ {% endfor %}
301
+ ```
302
+
303
+ The tools you have been given will provide you with access to a dataset with the following description:
304
+
305
+ Context: {{context_description}}
306
+
307
+ {%- if managed_agents and managed_agents.values() | list %}
308
+ You can also give tasks to team members.
309
+ Calling a team member works similarly to calling a tool: provide the task description as the 'task' argument. Since this team member is a real human, be as detailed and verbose as necessary in your task description.
310
+ You can also include any relevant variables or context using the 'additional_args' argument.
311
+ Here is a list of the team members that you can call:
312
+ ```python
313
+ {%- for agent in managed_agents.values() %}
314
+ def {{ agent.name }}(task: str, additional_args: dict[str, Any]) -> str:
315
+ \"\"\"{{ agent.description }}
316
+
317
+ Args:
318
+ task: Long detailed description of the task.
319
+ additional_args: Dictionary of extra inputs to pass to the managed agent, e.g. images, dataframes, or any other contextual data it may need.
320
+ \"\"\"
321
+ {% endfor %}
322
+ ```
323
+ {%- endif %}
324
+
325
+ Now write your updated facts survey below, then your new plan.
326
+ """
327
+
328
+ DATA_DISCOVERY_AGENT_TASK_PROMPT = """You're a helpful agent named '{{name}}'.
329
+ You have been submitted this task by your manager.
330
+ ---
331
+ Task:
332
+ {{task}}
333
+ ---
334
+ You have also been given access to tools which will help you navigate a dataset with the following description:
335
+ ---
336
+ Context:
337
+ {{context_description}}
338
+ ---
339
+ You're helping your manager solve a search task: so make sure to not provide a one-line answer, but give as much information as possible to give them a clear understanding of the answer and the context in which you produced it. In particular, be sure to report what source(s) you use and what the contents of those source(s) contain, even if they are irrelevant for solving this task.
340
+
341
+ Your final_answer WILL HAVE to contain these parts:
342
+ ### 1. Task outcome (short version):
343
+ ### 2. Task outcome (extremely detailed version):
344
+ ### 3. Additional context (if relevant):
345
+
346
+ Put all these in your final_answer tool, everything that you do not pass as an argument to final_answer will be lost.
347
+ And even if your task resolution is not successful, please return as much context as possible, so that your manager can act upon this feedback.
348
+ """
349
+
350
+ DATA_DISCOVERY_AGENT_REPORT_PROMPT = """Here is the final answer from your managed agent '{{name}}':
351
+ {{final_answer}}"""
352
+
353
+ FINAL_ANSWER_PRE_MESSAGES_PROMPT = """An agent tried to answer a user query but it got stuck and failed to do so. You are tasked with providing an answer instead. Here is the agent's memory:"""
354
+
355
+ FINAL_ANSWER_POST_MESSAGES_PROMPT = """Based on the above, please provide an answer to the following user task:
356
+ {{task}}
357
+ """
@@ -0,0 +1,9 @@
1
+
2
+ CONTEXT_SEARCH_PROMPT = """You are a helpful agent whose job is to propose search queries that will assist in finding information that is relevant to performing a computation.
3
+
4
+ Please propose a concise sentence which will be used to search for relevant information for the following computation instruction.
5
+
6
+ INSTRUCTION: {instruction}
7
+
8
+ SEARCH QUERY:
9
+ """
@@ -16,8 +16,8 @@ OUTPUT FIELDS:
16
16
  {example_output_fields}
17
17
 
18
18
  CONTEXT:
19
- {example_context}
20
- {image_disclaimer}
19
+ {example_context}{image_disclaimer}{audio_disclaimer}
20
+
21
21
  Let's think step-by-step in order to answer the question.
22
22
 
23
23
  REASONING: {example_reasoning}
@@ -27,10 +27,33 @@ ANSWER:
27
27
  ---
28
28
  """
29
29
 
30
- COT_QA_BASE_USER_PROMPT = """You are a helpful assistant whose job is to {job_instruction}.
30
+ COT_QA_NO_REASONING_BASE_SYSTEM_PROMPT = """You are a helpful assistant whose job is to {job_instruction}.
31
31
  You will be presented with a context and a set of output fields to generate. Your task is to generate a JSON object which fills in the output fields with the correct values.
32
32
  You will be provided with a description of each input field and each output field. All of the fields in the output JSON object can be derived using information from the context.
33
33
 
34
+ {output_format_instruction} Finish your response with a newline character followed by ---
35
+
36
+ An example is shown below:
37
+ ---
38
+ INPUT FIELDS:
39
+ {example_input_fields}
40
+
41
+ OUTPUT FIELDS:
42
+ {example_output_fields}
43
+
44
+ CONTEXT:
45
+ {example_context}{image_disclaimer}{audio_disclaimer}
46
+
47
+ ANSWER:
48
+ {example_answer}
49
+ ---
50
+ """
51
+
52
+
53
+ COT_QA_BASE_USER_PROMPT = """You are a helpful assistant whose job is to {job_instruction}.
54
+ You will be presented with a context and a set of output fields to generate. Your task is to generate a JSON object which fills in the output fields with the correct values.
55
+ You will be provided with a description of each input field and each output field. All of the fields in the output JSON object can be derived using information from the context.
56
+ {desc_section}
34
57
  {output_format_instruction} Finish your response with a newline character followed by ---
35
58
  ---
36
59
  INPUT FIELDS:
@@ -40,26 +63,47 @@ OUTPUT FIELDS:
40
63
  {output_fields_desc}
41
64
 
42
65
  CONTEXT:
43
- {context}
44
- <<image-placeholder>>
66
+ {context}<<image-placeholder>><<audio-placeholder>>
67
+
45
68
  Let's think step-by-step in order to answer the question.
46
69
 
47
70
  REASONING: """
48
71
 
72
+ COT_QA_NO_REASONING_BASE_USER_PROMPT = """You are a helpful assistant whose job is to {job_instruction}.
73
+ You will be presented with a context and a set of output fields to generate. Your task is to generate a JSON object which fills in the output fields with the correct values.
74
+ You will be provided with a description of each input field and each output field. All of the fields in the output JSON object can be derived using information from the context.
75
+ {desc_section}
76
+ {output_format_instruction} Finish your response with a newline character followed by ---
77
+ ---
78
+ INPUT FIELDS:
79
+ {input_fields_desc}
80
+
81
+ OUTPUT FIELDS:
82
+ {output_fields_desc}
83
+
84
+ CONTEXT:
85
+ {context}<<image-placeholder>><<audio-placeholder>>
86
+
87
+ ANSWER: """
49
88
 
50
89
  ### TEMPLATE INPUTS ###
51
90
  COT_QA_JOB_INSTRUCTION = """generate a JSON object"""
52
91
  COT_QA_IMAGE_JOB_INSTRUCTION = """analyze input image(s) and/or text in order to produce a JSON object"""
92
+ COT_QA_AUDIO_JOB_INSTRUCTION = """analyze input audio and/or text in order to produce a JSON object"""
53
93
 
54
94
  COT_QA_EXAMPLE_INPUT_FIELDS = """- text: a text passage describing a scientist
55
95
  - birthday: the scientist's birthday"""
56
96
  COT_QA_IMAGE_EXAMPLE_INPUT_FIELDS = """- image: an image of a scene
57
97
  - photographer: the photographer of the image"""
98
+ COT_QA_AUDIO_EXAMPLE_INPUT_FIELDS = """- recording: an audio recording of a newscast
99
+ - speaker: the name of the speaker in the recording"""
58
100
 
59
101
  COT_QA_EXAMPLE_OUTPUT_FIELDS = """- name: the name of the scientist
60
102
  - birth_year: the year the scientist was born"""
61
103
  COT_QA_IMAGE_EXAMPLE_OUTPUT_FIELDS = """- dog_in_image: true if a dog is in the image and false otherwise
62
104
  - person_in_image: true if a person is in the image and false otherwise"""
105
+ COT_QA_AUDIO_EXAMPLE_OUTPUT_FIELDS = """- main_topic: the main topic discussed in the newscast
106
+ - language: the language spoken in the newscast"""
63
107
 
64
108
  COT_QA_EXAMPLE_CONTEXT = """{{
65
109
  "text": "Augusta Ada King, Countess of Lovelace, also known as Ada Lovelace, was an English mathematician and writer chiefly known for her work on Charles Babbage's proposed mechanical general-purpose computer, the Analytical Engine. She was the first to recognise that the machine had applications beyond pure calculation.",
@@ -69,13 +113,21 @@ COT_QA_IMAGE_EXAMPLE_CONTEXT = """{{
69
113
  "image": <bytes>,
70
114
  "photographer": "CameraEnthusiast1"
71
115
  }}"""
116
+ COT_QA_AUDIO_EXAMPLE_CONTEXT = """{{
117
+ "recording": <bytes>,
118
+ "speaker": "Walter Cronkite"
119
+ }}"""
72
120
 
73
121
  COT_QA_IMAGE_DISCLAIMER = """
74
- <image content provided here; assume in this example the image shows a dog and a cat playing>
122
+ \n<image content provided here; assume in this example the image shows a dog and a cat playing>
123
+ """
124
+ COT_QA_AUDIO_DISCLAIMER = """
125
+ \n<audio content provided here; assume in this example the recording is about the Cuban Missile Crisis and spoken in English>
75
126
  """
76
127
 
77
128
  COT_QA_EXAMPLE_REASONING = """the text passage mentions the scientist's name as "Augusta Ada King, Countess of Lovelace, also known as Ada Lovelace" and the scientist's birthday as "December 10, 1815". Therefore, the name of the scientist is "Augusta Ada King" and the birth year is 1815."""
78
129
  COT_QA_IMAGE_EXAMPLE_REASONING = """The image shows a dog playing with a cat, so there is a dog in the image. There is no person in the image."""
130
+ COT_QA_AUDIO_EXAMPLE_REASONING = """The recording discusses the Cuban Missile Crisis, which is the main topic. The language spoken in the recording is English."""
79
131
 
80
132
  COT_QA_EXAMPLE_ANSWER = """{{
81
133
  "name": "Augusta Ada King",
@@ -85,3 +137,7 @@ COT_QA_IMAGE_EXAMPLE_ANSWER = """{{
85
137
  "dog_in_image": true,
86
138
  "person_in_image": false
87
139
  }}"""
140
+ COT_QA_AUDIO_EXAMPLE_ANSWER = """{{
141
+ "main_topic": "Cuban Missile Crisis",
142
+ "language": "English"
143
+ }}"""