qtype 0.1.10__py3-none-any.whl → 0.1.12__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 (216) hide show
  1. docs/Concepts/mental-model-and-philosophy.md +363 -0
  2. docs/Contributing/index.md +276 -0
  3. docs/Contributing/roadmap.md +81 -0
  4. docs/Decisions/ADR-001-Chat-vs-Completion-Endpoint-Features.md +56 -0
  5. docs/Gallery/dataflow_pipelines.md +80 -0
  6. docs/Gallery/dataflow_pipelines.mermaid +45 -0
  7. docs/Gallery/research_assistant.md +98 -0
  8. docs/Gallery/research_assistant.mermaid +42 -0
  9. docs/Gallery/simple_chatbot.md +36 -0
  10. docs/Gallery/simple_chatbot.mermaid +35 -0
  11. docs/How To/Authentication/configure_aws_authentication.md +60 -0
  12. docs/How To/Authentication/use_api_key_authentication.md +40 -0
  13. docs/How To/Command Line Usage/load_multiple_inputs_from_files.md +62 -0
  14. docs/How To/Command Line Usage/pass_inputs_on_the_cli.md +52 -0
  15. docs/How To/Command Line Usage/serve_with_auto_reload.md +26 -0
  16. docs/How To/Data Processing/adjust_concurrency.md +41 -0
  17. docs/How To/Data Processing/cache_step_results.md +71 -0
  18. docs/How To/Data Processing/decode_json_xml.md +24 -0
  19. docs/How To/Data Processing/explode_collections.md +40 -0
  20. docs/How To/Data Processing/gather_results.md +68 -0
  21. docs/How To/Data Processing/read_data_from_files.md +35 -0
  22. docs/How To/Data Processing/read_sql_databases.md +47 -0
  23. docs/How To/Data Processing/write_data_to_file.md +40 -0
  24. docs/How To/Invoke Models/call_large_language_models.md +51 -0
  25. docs/How To/Invoke Models/create_embeddings.md +49 -0
  26. docs/How To/Invoke Models/reuse_prompts_with_templates.md +39 -0
  27. docs/How To/Language Features/include_qtype_yaml.md +45 -0
  28. docs/How To/Language Features/include_raw_text_from_other_files.md +47 -0
  29. docs/How To/Language Features/reference_entities_by_id.md +51 -0
  30. docs/How To/Language Features/use_environment_variables.md +47 -0
  31. docs/How To/Language Features/use_qtype_mcp.md +59 -0
  32. docs/How To/Observability & Debugging/trace_calls_with_open_telemetry.md +49 -0
  33. docs/How To/Observability & Debugging/validate_qtype_yaml.md +35 -0
  34. docs/How To/Observability & Debugging/visualize_application_architecture.md +61 -0
  35. docs/How To/Observability & Debugging/visualize_example.mermaid +35 -0
  36. docs/How To/Qtype Server/flow_as_ui.png +0 -0
  37. docs/How To/Qtype Server/serve_flows_as_apis.md +40 -0
  38. docs/How To/Qtype Server/serve_flows_as_ui.md +42 -0
  39. docs/How To/Qtype Server/use_conversational_interfaces.md +59 -0
  40. docs/How To/Qtype Server/use_variables_with_ui_hints.md +47 -0
  41. docs/How To/Tools & Integration/bind_tool_inputs_and_outputs.md +48 -0
  42. docs/How To/Tools & Integration/create_tools_from_openapi_specifications.md +89 -0
  43. docs/How To/Tools & Integration/create_tools_from_python_modules.md +90 -0
  44. docs/Reference/cli.md +338 -0
  45. docs/Reference/plugins.md +95 -0
  46. docs/Reference/semantic-validation-rules.md +179 -0
  47. docs/Tutorials/01-first-qtype-application.md +248 -0
  48. docs/Tutorials/02-conversational-chatbot.md +327 -0
  49. docs/Tutorials/03-structured-data.md +481 -0
  50. docs/Tutorials/04-tools-and-function-calling.md +483 -0
  51. docs/Tutorials/example_chat.png +0 -0
  52. docs/Tutorials/index.md +92 -0
  53. docs/components/APIKeyAuthProvider.md +7 -0
  54. docs/components/APITool.md +10 -0
  55. docs/components/AWSAuthProvider.md +13 -0
  56. docs/components/AWSSecretManager.md +5 -0
  57. docs/components/Agent.md +6 -0
  58. docs/components/Aggregate.md +8 -0
  59. docs/components/AggregateStats.md +7 -0
  60. docs/components/Application.md +22 -0
  61. docs/components/AuthorizationProvider.md +6 -0
  62. docs/components/AuthorizationProviderList.md +5 -0
  63. docs/components/BearerTokenAuthProvider.md +6 -0
  64. docs/components/BedrockReranker.md +8 -0
  65. docs/components/ChatContent.md +7 -0
  66. docs/components/ChatMessage.md +6 -0
  67. docs/components/ConstantPath.md +5 -0
  68. docs/components/CustomType.md +7 -0
  69. docs/components/Decoder.md +8 -0
  70. docs/components/DecoderFormat.md +8 -0
  71. docs/components/DocToTextConverter.md +7 -0
  72. docs/components/Document.md +7 -0
  73. docs/components/DocumentEmbedder.md +7 -0
  74. docs/components/DocumentIndex.md +7 -0
  75. docs/components/DocumentSearch.md +7 -0
  76. docs/components/DocumentSource.md +12 -0
  77. docs/components/DocumentSplitter.md +10 -0
  78. docs/components/Echo.md +8 -0
  79. docs/components/Embedding.md +7 -0
  80. docs/components/EmbeddingModel.md +6 -0
  81. docs/components/FieldExtractor.md +20 -0
  82. docs/components/FileSource.md +6 -0
  83. docs/components/FileWriter.md +7 -0
  84. docs/components/Flow.md +14 -0
  85. docs/components/FlowInterface.md +7 -0
  86. docs/components/Index.md +8 -0
  87. docs/components/IndexUpsert.md +6 -0
  88. docs/components/InvokeEmbedding.md +7 -0
  89. docs/components/InvokeFlow.md +8 -0
  90. docs/components/InvokeTool.md +8 -0
  91. docs/components/LLMInference.md +9 -0
  92. docs/components/ListType.md +5 -0
  93. docs/components/Memory.md +8 -0
  94. docs/components/MessageRole.md +14 -0
  95. docs/components/Model.md +10 -0
  96. docs/components/ModelList.md +5 -0
  97. docs/components/OAuth2AuthProvider.md +9 -0
  98. docs/components/PrimitiveTypeEnum.md +21 -0
  99. docs/components/PromptTemplate.md +7 -0
  100. docs/components/PythonFunctionTool.md +7 -0
  101. docs/components/RAGChunk.md +7 -0
  102. docs/components/RAGDocument.md +10 -0
  103. docs/components/RAGSearchResult.md +8 -0
  104. docs/components/Reranker.md +5 -0
  105. docs/components/SQLSource.md +8 -0
  106. docs/components/Search.md +7 -0
  107. docs/components/SearchResult.md +7 -0
  108. docs/components/SecretManager.md +7 -0
  109. docs/components/SecretReference.md +7 -0
  110. docs/components/Source.md +6 -0
  111. docs/components/Step.md +9 -0
  112. docs/components/TelemetrySink.md +9 -0
  113. docs/components/Tool.md +9 -0
  114. docs/components/ToolList.md +5 -0
  115. docs/components/ToolParameter.md +6 -0
  116. docs/components/TypeList.md +5 -0
  117. docs/components/Variable.md +6 -0
  118. docs/components/VariableList.md +5 -0
  119. docs/components/VectorIndex.md +7 -0
  120. docs/components/VectorSearch.md +6 -0
  121. docs/components/VertexAuthProvider.md +9 -0
  122. docs/components/Writer.md +5 -0
  123. docs/example_ui.png +0 -0
  124. docs/index.md +81 -0
  125. docs/legacy_how_tos/Configuration/modular-yaml.md +366 -0
  126. docs/legacy_how_tos/Configuration/phoenix_projects.png +0 -0
  127. docs/legacy_how_tos/Configuration/phoenix_traces.png +0 -0
  128. docs/legacy_how_tos/Configuration/reference-by-id.md +251 -0
  129. docs/legacy_how_tos/Configuration/telemetry-setup.md +259 -0
  130. docs/legacy_how_tos/Data Types/custom-types.md +52 -0
  131. docs/legacy_how_tos/Data Types/domain-types.md +113 -0
  132. docs/legacy_how_tos/Debugging/visualize-apps.md +147 -0
  133. docs/legacy_how_tos/Tools/api-tools.md +29 -0
  134. docs/legacy_how_tos/Tools/python-tools.md +299 -0
  135. examples/authentication/aws_authentication.qtype.yaml +63 -0
  136. examples/conversational_ai/hello_world_chat.qtype.yaml +43 -0
  137. examples/conversational_ai/simple_chatbot.qtype.yaml +40 -0
  138. examples/data_processing/batch_processing.qtype.yaml +54 -0
  139. examples/data_processing/cache_step_results.qtype.yaml +78 -0
  140. examples/data_processing/collect_results.qtype.yaml +55 -0
  141. examples/data_processing/dataflow_pipelines.qtype.yaml +108 -0
  142. examples/data_processing/decode_json.qtype.yaml +23 -0
  143. examples/data_processing/explode_items.qtype.yaml +25 -0
  144. examples/data_processing/read_file.qtype.yaml +60 -0
  145. examples/invoke_models/create_embeddings.qtype.yaml +28 -0
  146. examples/invoke_models/simple_llm_call.qtype.yaml +32 -0
  147. examples/language_features/include_raw.qtype.yaml +27 -0
  148. examples/language_features/ui_hints.qtype.yaml +52 -0
  149. examples/legacy/bedrock/data_analysis_with_telemetry.qtype.yaml +169 -0
  150. examples/legacy/bedrock/hello_world.qtype.yaml +39 -0
  151. examples/legacy/bedrock/hello_world_chat.qtype.yaml +37 -0
  152. examples/legacy/bedrock/hello_world_chat_with_telemetry.qtype.yaml +40 -0
  153. examples/legacy/bedrock/hello_world_chat_with_thinking.qtype.yaml +40 -0
  154. examples/legacy/bedrock/hello_world_completion.qtype.yaml +41 -0
  155. examples/legacy/bedrock/hello_world_completion_with_auth.qtype.yaml +44 -0
  156. examples/legacy/bedrock/simple_agent_chat.qtype.yaml +46 -0
  157. examples/legacy/chat_with_langfuse.qtype.yaml +50 -0
  158. examples/legacy/data_processor.qtype.yaml +48 -0
  159. examples/legacy/echo/debug_example.qtype.yaml +59 -0
  160. examples/legacy/echo/prompt.qtype.yaml +22 -0
  161. examples/legacy/echo/test.qtype.yaml +26 -0
  162. examples/legacy/echo/video.qtype.yaml +20 -0
  163. examples/legacy/field_extractor_example.qtype.yaml +137 -0
  164. examples/legacy/multi_flow_example.qtype.yaml +125 -0
  165. examples/legacy/openai/hello_world_chat.qtype.yaml +43 -0
  166. examples/legacy/openai/hello_world_chat_with_telemetry.qtype.yaml +46 -0
  167. examples/legacy/rag.qtype.yaml +207 -0
  168. examples/legacy/time_utilities.qtype.yaml +64 -0
  169. examples/legacy/vertex/hello_world_chat.qtype.yaml +36 -0
  170. examples/legacy/vertex/hello_world_completion.qtype.yaml +40 -0
  171. examples/legacy/vertex/hello_world_completion_with_auth.qtype.yaml +45 -0
  172. examples/observability_debugging/trace_with_opentelemetry.qtype.yaml +40 -0
  173. examples/research_assistant/research_assistant.qtype.yaml +94 -0
  174. examples/research_assistant/tavily.oas.yaml +722 -0
  175. examples/research_assistant/tavily.qtype.yaml +289 -0
  176. examples/tutorials/01_hello_world.qtype.yaml +48 -0
  177. examples/tutorials/02_conversational_chat.qtype.yaml +37 -0
  178. examples/tutorials/03_structured_data.qtype.yaml +130 -0
  179. examples/tutorials/04_tools_and_function_calling.qtype.yaml +89 -0
  180. qtype/application/converters/tools_from_api.py +39 -35
  181. qtype/base/types.py +6 -1
  182. qtype/commands/convert.py +3 -6
  183. qtype/commands/generate.py +7 -3
  184. qtype/commands/mcp.py +68 -0
  185. qtype/commands/validate.py +4 -4
  186. qtype/dsl/custom_types.py +2 -1
  187. qtype/dsl/linker.py +15 -7
  188. qtype/dsl/loader.py +3 -3
  189. qtype/dsl/model.py +24 -3
  190. qtype/interpreter/api.py +4 -1
  191. qtype/interpreter/base/base_step_executor.py +3 -1
  192. qtype/interpreter/conversions.py +7 -3
  193. qtype/interpreter/executors/construct_executor.py +1 -1
  194. qtype/interpreter/executors/document_splitter_executor.py +4 -1
  195. qtype/interpreter/executors/file_source_executor.py +3 -3
  196. qtype/interpreter/executors/file_writer_executor.py +4 -4
  197. qtype/interpreter/executors/index_upsert_executor.py +1 -1
  198. qtype/interpreter/executors/sql_source_executor.py +1 -1
  199. qtype/interpreter/resource_cache.py +3 -1
  200. qtype/interpreter/rich_progress.py +6 -3
  201. qtype/interpreter/stream/chat/converter.py +25 -17
  202. qtype/interpreter/stream/chat/ui_request_to_domain_type.py +2 -2
  203. qtype/interpreter/typing.py +5 -7
  204. qtype/mcp/__init__.py +0 -0
  205. qtype/mcp/server.py +467 -0
  206. qtype/semantic/checker.py +1 -1
  207. qtype/semantic/generate.py +3 -3
  208. qtype/semantic/visualize.py +38 -51
  209. {qtype-0.1.10.dist-info → qtype-0.1.12.dist-info}/METADATA +21 -1
  210. qtype-0.1.12.dist-info/RECORD +325 -0
  211. {qtype-0.1.10.dist-info → qtype-0.1.12.dist-info}/WHEEL +1 -1
  212. schema/qtype.schema.json +4018 -0
  213. qtype-0.1.10.dist-info/RECORD +0 -142
  214. {qtype-0.1.10.dist-info → qtype-0.1.12.dist-info}/entry_points.txt +0 -0
  215. {qtype-0.1.10.dist-info → qtype-0.1.12.dist-info}/licenses/LICENSE +0 -0
  216. {qtype-0.1.10.dist-info → qtype-0.1.12.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,483 @@
1
+ # Adding Tools to Your Application
2
+
3
+ **Time:** 20 minutes
4
+ **Prerequisites:** [Tutorial 3: Working with Types and Structured Data](03-structured-data.md)
5
+ **Example:** [`04_tools_and_function_calling.qtype.yaml`](https://github.com/bazaarvoice/qtype/blob/main/examples/tutorials/04_tools_and_function_calling.qtype.yaml)
6
+
7
+ **What you'll learn:**
8
+
9
+ * Import pre-built tools from the commons library
10
+ * Use InvokeTool to call Python functions
11
+ * Chain multiple tools with input/output bindings
12
+ * Understand tool references and automatic generation
13
+
14
+ **What you'll build:** A deadline calculator that uses tools to get the current time, add days, and format the result.
15
+
16
+ ---
17
+
18
+ ## Background: What Are Tools?
19
+
20
+ Tools extend your QType applications with custom steps.
21
+ Tools are how you plug QType into other existing systems that may not be supported in the shipped interpreter.
22
+
23
+ **A tool is simply a reference to:**
24
+ - **A Python function** - Call any Python function with typed parameters
25
+ - **An API endpoint** - Make HTTP requests to external services
26
+
27
+ Tools define their **inputs** (parameters) and **outputs** (return values) with explicit types.
28
+
29
+ ### The Commons Library
30
+
31
+ QType provides a [commons library](https://github.com/bazaarvoice/qtype/blob/main/common/tools.qtype.yaml) published on GitHub with pre-built tools for common operations:
32
+
33
+ - **Time utilities** - Get current time, add/subtract durations, format timestamps
34
+ - **String operations** - Base64 encoding/decoding, text transformations
35
+ - **Data processing** - JSON parsing, field extraction, type conversions
36
+
37
+ ### Automatic Tool Generation
38
+
39
+ You don't need to write tool YAML files manually! QType can generate them automatically using `qtype convert`:
40
+
41
+ **From Python modules:**
42
+ ```bash
43
+ qtype convert python --module myapp.utils --output tools.qtype.yaml
44
+ ```
45
+
46
+ **From OpenAPI specifications:**
47
+ ```bash
48
+ qtype convert openapi --spec api_spec.yaml --output api_tools.qtype.yaml
49
+ ```
50
+
51
+ The converter analyzes function signatures or API schemas and creates properly typed tool definitions.
52
+
53
+ ---
54
+
55
+ ## Part 1: Import and Use Your First Tool (7 minutes)
56
+
57
+ ### Create Your Application File
58
+
59
+ Create `04_tools_and_function_calling.qtype.yaml`:
60
+
61
+ ```yaml
62
+ id: deadline_calculator
63
+ description: |
64
+ Calculates a deadline by adding days to the current timestamp.
65
+ Demonstrates tool imports, InvokeTool step, and tool chaining.
66
+ ```
67
+
68
+ ---
69
+
70
+ ### Import the Commons Library
71
+
72
+ Add a `references:` section before `flows:`:
73
+
74
+ ```yaml
75
+ # Import pre-built tools from the commons library
76
+ references:
77
+ - !include https://raw.githubusercontent.com/bazaarvoice/qtype/refs/tags/v0.1.11/common/tools.qtype.yaml
78
+ ```
79
+
80
+ **What this means:**
81
+
82
+ **`!include`** - YAML directive to load another file's content. `!include` brings in yaml files inside the header.
83
+ - Can use local paths: `!include ../../common/tools.qtype.yaml`
84
+ - Or remote URLs: `!include https://...` (shown here)
85
+ - Imports all tools, types, and definitions from that file
86
+
87
+ **`references:` section** - Where you import external components. References can be other applications or lists of models, tools, authorization providers, variables, or custom types.
88
+
89
+ You can now reference any tool by its `id` (like `qtype.application.commons.tools.get_current_timestamp`).
90
+
91
+ **Check your work:**
92
+
93
+ ```bash
94
+ qtype validate 04_tools_and_function_calling.qtype.yaml
95
+ ```
96
+
97
+ Should pass ✅ (even with no flows yet - imports are valid)
98
+
99
+ ---
100
+
101
+ ### Define Your Flow Variables
102
+
103
+ Add the flow structure:
104
+
105
+ ```yaml
106
+ flows:
107
+ - id: calculate_deadline
108
+ description: Calculate a formatted deadline from current time plus days
109
+ inputs:
110
+ - days_until_due
111
+ outputs:
112
+ - deadline_formatted
113
+
114
+ variables:
115
+ # Input
116
+ - id: days_until_due
117
+ type: int
118
+
119
+ # Tool outputs
120
+ - id: current_time
121
+ type: datetime
122
+ - id: deadline_time
123
+ type: datetime
124
+ - id: format_string
125
+ type: text
126
+ - id: deadline_formatted
127
+ type: text
128
+ ```
129
+
130
+ **New types:**
131
+
132
+ **`datetime` type** - Built-in QType type for timestamps:
133
+ - Represents a point in time (date + time)
134
+ - Stored internally as ISO 8601 strings
135
+ - Automatically converted to/from Python `datetime` objects
136
+ - Tools can accept and return `datetime` values
137
+
138
+ **Why all these variables?** Each tool transforms data:
139
+ - `current_time` ← output from get_current_timestamp
140
+ - `deadline_time` ← output from timedelta (current_time + days)
141
+ - `deadline_formatted` ← output from format_datetime (pretty string)
142
+
143
+ Explicit variables make the data flow visible and debuggable.
144
+
145
+ ---
146
+
147
+ ### Add Your First Tool Call
148
+
149
+ Add this under `steps:`:
150
+
151
+ ```yaml
152
+ steps:
153
+ # Step 1: Get current timestamp using a tool
154
+ # This tool takes no inputs and returns the current UTC time
155
+ - id: get_current_time
156
+ type: InvokeTool
157
+ tool: qtype.application.commons.tools.get_current_timestamp
158
+ input_bindings: {}
159
+ output_bindings:
160
+ result: current_time
161
+ outputs:
162
+ - current_time
163
+ ```
164
+
165
+ **New step type: InvokeTool**
166
+
167
+ This is your primary way to call tools in QType flows.
168
+
169
+ **`tool:`** - Full ID of the tool to invoke:
170
+ - Format: `<module_id>.<function_name>`
171
+ - Must match a tool defined in your imports or application
172
+ - Example: `qtype.application.commons.tools.get_current_timestamp`
173
+
174
+ **`input_bindings:`** - Maps flow variables to tool parameters:
175
+ - Empty `{}` means no inputs needed
176
+ - This tool has no parameters - it just returns the current time
177
+
178
+ **`output_bindings:`** - Maps tool outputs to flow variables:
179
+ - `result: current_time` means "take the tool's `result` output and store it in the `current_time` variable"
180
+ - Tool outputs are defined in the tool's YAML definition
181
+
182
+ **`outputs:`** - Flow-level outputs this step produces:
183
+ - Lists which flow variables this step creates or modifies
184
+ - Used by QType to validate data flow through the pipeline
185
+
186
+ **Check your work:**
187
+
188
+ ```bash
189
+ qtype validate 04_tools_and_function_calling.qtype.yaml
190
+ ```
191
+
192
+ Should pass ✅
193
+
194
+ ---
195
+
196
+ ## Part 2: Chain Tools with Bindings (8 minutes)
197
+
198
+ ### Add a Constant Variable
199
+
200
+ Before we can format our datetime, we need to define the format string:
201
+
202
+ ```yaml
203
+ # Step 2: Create a format string constant
204
+ - id: create_format_string
205
+ type: PromptTemplate
206
+ template: "%B %d, %Y at %I:%M %p UTC"
207
+ inputs: []
208
+ outputs:
209
+ - format_string
210
+ ```
211
+
212
+ **Pattern: Constants in flows**
213
+
214
+ Since tool `input_bindings` only accept variable names (not literal values), we use PromptTemplate to create constants:
215
+ - Template with no placeholders → constant string
216
+ - `inputs: []` → no dependencies
217
+ - Produces `format_string` variable for later use
218
+
219
+ **Format string syntax:** Uses Python's `strftime` format codes:
220
+ - `%B` - Full month name (January)
221
+ - `%d` - Day of month (14)
222
+ - `%Y` - 4-digit year (2026)
223
+ - `%I:%M %p` - Time in 12-hour format (03:30 PM)
224
+
225
+ ---
226
+
227
+ ### Add Days with Input Bindings
228
+
229
+ Now let's use a tool with multiple inputs:
230
+
231
+ ```yaml
232
+ # Step 3: Calculate deadline by adding days to current time
233
+ # input_bindings maps flow variables to tool parameters
234
+ - id: add_days
235
+ type: InvokeTool
236
+ tool: qtype.application.commons.tools.timedelta
237
+ input_bindings:
238
+ timestamp: current_time
239
+ days: days_until_due
240
+ output_bindings:
241
+ result: deadline_time
242
+ outputs:
243
+ - deadline_time
244
+ ```
245
+
246
+ **Understanding bindings:**
247
+
248
+ **Input bindings structure:**
249
+ ```yaml
250
+ input_bindings:
251
+ <tool_parameter_name>: <flow_variable_name>
252
+ ```
253
+
254
+ In this case:
255
+ - Tool parameter `timestamp` ← gets value from flow variable `current_time`
256
+ - Tool parameter `days` ← gets value from flow variable `days_until_due`
257
+
258
+ The `timedelta` tool definition (from commons library) looks like:
259
+ ```yaml
260
+ inputs:
261
+ timestamp:
262
+ type: datetime
263
+ days:
264
+ type: int
265
+ hours:
266
+ type: int
267
+ optional: true
268
+ # ... more optional parameters
269
+ ```
270
+
271
+ **Optional parameters:** You only need to bind the required parameters. `timedelta` has many optional parameters (hours, minutes, seconds, weeks), but we only use `days`.
272
+
273
+ ---
274
+
275
+ ### Chain Tools Together
276
+
277
+ Finally, format the deadline using the output from the previous step:
278
+
279
+ ```yaml
280
+ # Step 4: Format deadline for human readability
281
+ # Shows chaining: output from previous tool becomes input to this one
282
+ - id: format_deadline
283
+ type: InvokeTool
284
+ tool: qtype.application.commons.tools.format_datetime
285
+ input_bindings:
286
+ timestamp: deadline_time
287
+ format_string: format_string
288
+ output_bindings:
289
+ result: deadline_formatted
290
+ outputs:
291
+ - deadline_formatted
292
+ ```
293
+
294
+ **Check your work:**
295
+
296
+ ```bash
297
+ qtype validate 04_tools_and_function_calling.qtype.yaml
298
+ ```
299
+
300
+ Should pass ✅
301
+
302
+ ---
303
+
304
+ ## Part 3: Test Your Tools (5 minutes)
305
+
306
+ ### Run the Application
307
+
308
+ ```bash
309
+ qtype run -i '{"days_until_due": 3}' 04_tools_and_function_calling.qtype.yaml
310
+ ```
311
+
312
+ **Expected output:**
313
+
314
+ ```json
315
+ {
316
+ "deadline_formatted": "January 17, 2026 at 03:39 PM UTC"
317
+ }
318
+ ```
319
+
320
+ The exact time will match when you run it, but the date should be 3 days from now.
321
+
322
+ ---
323
+
324
+ ### Try Different Durations
325
+
326
+ ```bash
327
+ # One week deadline
328
+ qtype run -i '{"days_until_due": 7}' 04_tools_and_function_calling.qtype.yaml
329
+
330
+ # Two weeks
331
+ qtype run -i '{"days_until_due": 14}' 04_tools_and_function_calling.qtype.yaml
332
+
333
+ # Same day (0 days)
334
+ qtype run -i '{"days_until_due": 0}' 04_tools_and_function_calling.qtype.yaml
335
+ ```
336
+
337
+ ---
338
+
339
+ ### Add the `--progress` Flag
340
+
341
+ For more visibility into tool execution:
342
+
343
+ ```bash
344
+ qtype run -i '{"days_until_due": 3}' 04_tools_and_function_calling.qtype.yaml --progress
345
+ ```
346
+
347
+ You'll see each step execute in real-time:
348
+
349
+ ```
350
+ Step get_current_time ✔ 1 succeeded
351
+ Step create_format_string ✔ 1 succeeded
352
+ Step add_days ✔ 1 succeeded
353
+ Step format_deadline ✔ 1 succeeded
354
+ ```
355
+
356
+ ---
357
+
358
+ ## Part 4: Understanding Tools Deeply (Bonus)
359
+
360
+ ### Tool Types and Custom Types
361
+
362
+ Remember from Tutorial 3 where `calculate_time_difference` returns `TimeDifferenceResultType`? That's a custom type defined in the commons library:
363
+
364
+ ```yaml
365
+ types:
366
+ - id: TimeDifferenceResultType
367
+ properties:
368
+ days: int
369
+ seconds: int
370
+ microseconds: int
371
+ total_hours: float
372
+ total_minutes: float
373
+ total_seconds: float
374
+ total_days: float
375
+ ```
376
+
377
+ If you use `calculate_time_difference`, you can extract fields from its result:
378
+
379
+ ```yaml
380
+ - id: calc_difference
381
+ type: InvokeTool
382
+ tool: qtype.application.commons.tools.calculate_time_difference
383
+ input_bindings:
384
+ start_time: start
385
+ end_time: end
386
+ output_bindings:
387
+ result: time_diff # time_diff is now TimeDifferenceResultType
388
+
389
+ # Later, access fields using FieldExtractor or Construct
390
+ ```
391
+
392
+ ---
393
+
394
+ ### Generating Your Own Tools
395
+
396
+ When you're ready to create custom tools, use `qtype convert`:
397
+
398
+ **From a Python module:**
399
+
400
+ ```bash
401
+ # Generate tools from all functions in myapp.utils
402
+ qtype convert python --module myapp.utils --output my_tools.qtype.yaml
403
+ ```
404
+
405
+ QType will:
406
+ - Scan all public functions in the module
407
+ - Extract type hints from function signatures
408
+ - Generate tool definitions with proper input/output types
409
+ - Include docstrings as descriptions
410
+
411
+ **From an OpenAPI spec:**
412
+
413
+ ```bash
414
+ # Generate tools from a REST API
415
+ qtype convert openapi --spec weather_api.yaml --output weather_tools.qtype.yaml
416
+ ```
417
+
418
+ QType will:
419
+ - Parse endpoint definitions
420
+ - Create a tool for each operation
421
+ - Map request parameters to tool inputs
422
+ - Map response schemas to tool outputs
423
+ - Handle authentication configurations
424
+
425
+ <!-- **Learn more:** See the [How-To Guide: Generate Tools](../How-To%20Guides/Tools/generate-tools.md) for detailed examples. -->
426
+
427
+ ---
428
+
429
+ ## What You've Learned
430
+
431
+ Congratulations! You've mastered:
432
+
433
+ ✅ **Tool concepts** - References to Python functions or API calls
434
+ ✅ **Importing tools** - Using `!include` with local or remote files
435
+ ✅ **InvokeTool step** - Calling tools with input/output bindings
436
+ ✅ **Input bindings** - Mapping flow variables to tool parameters
437
+ ✅ **Output bindings** - Mapping tool results to flow variables
438
+ ✅ **Tool chaining** - Connecting outputs to inputs across steps
439
+ ✅ **Commons library** - Pre-built tools for common operations
440
+ ✅ **Tool generation** - Using `qtype convert` to create tool definitions
441
+
442
+ ---
443
+
444
+ ## Next Steps
445
+
446
+ **Reference the complete example:**
447
+
448
+ - [`04_tools_and_function_calling.qtype.yaml`](https://github.com/bazaarvoice/qtype/blob/main/examples/tutorials/04_tools_and_function_calling.qtype.yaml) - Full working example
449
+ - [Commons Library](https://github.com/bazaarvoice/qtype/blob/main/common/tools.qtype.yaml) - Browse all available tools
450
+ - [Commons Library Source](https://github.com/bazaarvoice/qtype/blob/v0.1.11/qtype/application/commons/tools.py) - Browse the source of tools.
451
+ <!--
452
+ **Learn more:**
453
+
454
+ - [PythonFunctionTool Reference](../components/PythonFunctionTool.md) - Complete specification
455
+ - [APITool Reference](../components/APITool.md) - External service integration
456
+ - [InvokeTool Step](../components/InvokeTool.md) - Advanced binding patterns
457
+ - [Generate Tools](../How-To%20Guides/Tools/generate-tools.md) - Create your own tools -->
458
+
459
+ <!-- **Next tutorial:**
460
+
461
+ - Tutorial 5: Building an AI Agent - Use tools with autonomous LLM decision-making -->
462
+
463
+ ---
464
+
465
+ ## Common Questions
466
+
467
+ **Q: Can I call multiple tools in parallel?**
468
+ A: Not directly in a single step. However, if tools don't depend on each other's outputs, QType's execution engine may parallelize them automatically based on dependency analysis.
469
+
470
+ **Q: What happens if a tool raises an error?**
471
+ A: The flow stops and returns an error.
472
+
473
+ **Q: Can I pass literal values instead of variables to tools?**
474
+ A: No - `input_bindings` only accepts variable names. Use PromptTemplate to create constant variables, or define them in your flow's input data.
475
+
476
+ **Q: How do I know what parameters a tool accepts?**
477
+ A: Check the tool's YAML definition (in the commons library or your generated file). It lists all `inputs` with their types and whether they're optional.
478
+
479
+ **Q: Can tools modify variables or have side effects?**
480
+ A: Tools are functional - they take inputs and return outputs without modifying flow state. Side effects (like writing files or calling APIs) happen inside the tool implementation, but they don't affect other flow variables.
481
+
482
+ **Q: What's the difference between InvokeTool and Agent?**
483
+ A: **InvokeTool** explicitly calls a specific tool with defined bindings. **Agent** gives an LLM access to multiple tools and lets it decide which to use and when. Use InvokeTool for deterministic workflows, Agent for autonomous decision-making.
Binary file
@@ -0,0 +1,92 @@
1
+ # Installation
2
+
3
+ QType can be installed in two different ways depending on your needs:
4
+
5
+ ## Interpreter Package Installation (Recommended)
6
+
7
+ For full functionality including the ability to execute QType flows, serve them as APIs, and launch user experiences, install with the interpreter extra:
8
+
9
+ === "uv"
10
+ ```sh
11
+ uv add qtype[interpreter]
12
+ ```
13
+
14
+ === "pip"
15
+ ```bash
16
+ pip install qtype[interpreter]
17
+ ```
18
+
19
+
20
+ ## Base Package Installation
21
+
22
+ The base QType package provides core functionality for defining, validating, and generating schemas for QType specifications:
23
+
24
+ === "uv"
25
+ ```sh
26
+ uv add qtype
27
+ ```
28
+
29
+ === "uvx"
30
+ ```sh
31
+ uvx qtype
32
+ ```
33
+
34
+ === "pip"
35
+ ```sh
36
+ pip install qtype
37
+ ```
38
+
39
+ ### What's included in the base package:
40
+
41
+ - **Schema validation**: Validate your QType YAML files against the specification
42
+ - **File conversion**: Convert between different QType formats
43
+ - **Core DSL components**: Define models, prompts, tools, and flows
44
+ - **Basic CLI commands**: `validate`, `generate`, `convert`
45
+
46
+
47
+ ### Additional capabilities with the interpreter package:
48
+
49
+ - **Flow execution**: Run QType flows locally with the `run` command
50
+ - **UI and API serving**: Serve QType flows as web UI and APIs with the `serve` command
51
+ - **Multiple model Providers**: Support for AWS Bedrock, OpenAI, and other LLM providers
52
+ - **Embeddings and Detrieval**: Built-in support for vector embeddings and retrieval
53
+ - **Observability**: Integrated telemetry and tracing with OpenTelemetry
54
+
55
+ ### Additional dependencies:
56
+
57
+ (These are installed by default with the `interpreter` package)
58
+
59
+ - `boto3` - AWS SDK for Bedrock and other AWS services
60
+ - `fastapi` - Web framework for serving APIs
61
+ - `uvicorn` - ASGI server for FastAPI
62
+ - `llama-index` - LLM application framework with embeddings support
63
+ - `arize-phoenix-otel` - OpenTelemetry instrumentation
64
+
65
+ ## Requirements
66
+
67
+ - **Python 3.10 or higher**
68
+ - Operating systems: macOS, Linux, Windows
69
+
70
+ ## Verification
71
+
72
+ After installation, verify that QType is working correctly:
73
+
74
+ ```bash
75
+ # Check installation
76
+ qtype --help
77
+
78
+ # Validate a sample spec (base package)
79
+ qtype validate examples/hello_world.qtype.yaml
80
+ ```
81
+
82
+ Then, edit `.env` and put in your `OPENAI_KEY`:
83
+ ```
84
+ OPENAI_KEY=sk-proj....
85
+ ```
86
+
87
+ and run the example flow:
88
+ ```
89
+ # Run a flow (interpreter package only)
90
+ qtype run -i '{"question":"What is your quest?"}' examples/hello_world.qtype.yaml
91
+ ```
92
+
@@ -0,0 +1,7 @@
1
+ ### APIKeyAuthProvider
2
+
3
+ API key-based authentication provider.
4
+
5
+ - **type** (`Literal`): (No documentation available.)
6
+ - **api_key** (`str | SecretReference`): API key for authentication.
7
+ - **host** (`str | None`): Base URL or domain of the provider.
@@ -0,0 +1,10 @@
1
+ ### APITool
2
+
3
+ Tool that invokes an API endpoint.
4
+
5
+ - **type** (`Literal`): (No documentation available.)
6
+ - **endpoint** (`str`): API endpoint URL to call.
7
+ - **method** (`str`): HTTP method to use (GET, POST, PUT, DELETE, etc.).
8
+ - **auth** (`Reference[AuthProviderType] | str | None`): Optional AuthorizationProvider for API authentication.
9
+ - **headers** (`dict[str, str]`): Optional HTTP headers to include in the request.
10
+ - **parameters** (`dict[str, ToolParameter]`): Output parameters produced by this tool.
@@ -0,0 +1,13 @@
1
+ ### AWSAuthProvider
2
+
3
+ AWS authentication provider supporting multiple credential methods.
4
+
5
+ - **type** (`Literal`): (No documentation available.)
6
+ - **access_key_id** (`str | SecretReference | None`): AWS access key ID.
7
+ - **secret_access_key** (`str | SecretReference | None`): AWS secret access key.
8
+ - **session_token** (`str | SecretReference | None`): AWS session token for temporary credentials.
9
+ - **profile_name** (`str | None`): AWS profile name from credentials file.
10
+ - **role_arn** (`str | None`): ARN of the role to assume.
11
+ - **role_session_name** (`str | None`): Session name for role assumption.
12
+ - **external_id** (`str | None`): External ID for role assumption.
13
+ - **region** (`str | None`): AWS region.
@@ -0,0 +1,5 @@
1
+ ### AWSSecretManager
2
+
3
+ Configuration for AWS Secrets Manager.
4
+
5
+ - **type** (`Literal`): (No documentation available.)
@@ -0,0 +1,6 @@
1
+ ### Agent
2
+
3
+ Defines an agent that can perform tasks and make decisions based on user input and context.
4
+
5
+ - **type** (`Literal`): (No documentation available.)
6
+ - **tools** (`list[Reference[ToolType] | str]`): List of tools available to the agent.
@@ -0,0 +1,8 @@
1
+ ### Aggregate
2
+
3
+ A terminal step that consumes an entire input stream and produces a single
4
+ summary message with success/error counts.
5
+
6
+ - **type** (`Literal`): (No documentation available.)
7
+ - **cardinality** (`Literal`): (No documentation available.)
8
+ - **outputs** (`list[Reference[Variable] | str]`): References to the variables for the output. There should be one and only one output with type AggregateStats
@@ -0,0 +1,7 @@
1
+ ### AggregateStats
2
+
3
+ A standard, built-in representation of aggregate statistics.
4
+
5
+ - **num_successful** (`int`): The count of successful messages processed.
6
+ - **num_failed** (`int`): The count of failed messages processed.
7
+ - **num_total** (`int`): The total count of messages processed.
@@ -0,0 +1,22 @@
1
+ ### Application
2
+
3
+ Defines a complete QType application specification.
4
+ An Application is the top-level container of the entire
5
+ program in a QType YAML file. It serves as the blueprint for your
6
+ AI-powered application, containing all the models, flows, tools, data sources,
7
+ and configuration needed to run your program. Think of it as the main entry
8
+ point that ties together all components into a cohesive,
9
+ executable system.
10
+
11
+ - **id** (`str`): Unique ID of the application.
12
+ - **description** (`str | None`): Optional description of the application.
13
+ - **memories** (`list[Memory]`): List of memory definitions used in this application.
14
+ - **models** (`list[ModelType]`): List of models used in this application.
15
+ - **types** (`list[CustomType]`): List of custom types defined in this application.
16
+ - **flows** (`list[Flow]`): List of flows defined in this application.
17
+ - **auths** (`list[AuthProviderType]`): List of authorization providers used for API access.
18
+ - **tools** (`list[ToolType]`): List of tools available in this application.
19
+ - **indexes** (`list[IndexType]`): List of indexes available for search operations.
20
+ - **secret_manager** (`SecretManagerType | None`): Optional secret manager configuration for the application.
21
+ - **telemetry** (`TelemetrySink | None`): Optional telemetry sink for observability.
22
+ - **references** (`list[Document]`): List of other q-type documents you may use. This allows modular composition and reuse of components across applications.
@@ -0,0 +1,6 @@
1
+ ### AuthorizationProvider
2
+
3
+ Base class for authentication providers.
4
+
5
+ - **id** (`str`): Unique ID of the authorization configuration.
6
+ - **type** (`str`): Authorization method type.
@@ -0,0 +1,5 @@
1
+ ### AuthorizationProviderList
2
+
3
+ Schema for a standalone list of authorization providers.
4
+
5
+ - **root** (`list[APIKeyAuthProvider | BearerTokenAuthProvider | AWSAuthProvider | OAuth2AuthProvider | VertexAuthProvider]`): (No documentation available.)
@@ -0,0 +1,6 @@
1
+ ### BearerTokenAuthProvider
2
+
3
+ Bearer token authentication provider.
4
+
5
+ - **type** (`Literal`): (No documentation available.)
6
+ - **token** (`str | SecretReference`): Bearer token for authentication.
@@ -0,0 +1,8 @@
1
+ ### BedrockReranker
2
+
3
+ Reranks documents using an AWS Bedrock model.
4
+
5
+ - **type** (`Literal`): (No documentation available.)
6
+ - **auth** (`Reference[AWSAuthProvider] | str | None`): AWS authorization provider for Bedrock access.
7
+ - **model_id** (`str`): Bedrock model ID to use for reranking. See https://docs.aws.amazon.com/bedrock/latest/userguide/rerank-supported.html
8
+ - **num_results** (`int | None`): Return this many results.