qtype 0.1.11__py3-none-any.whl → 0.1.13__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 (263) hide show
  1. qtype/` +0 -0
  2. qtype/application/__init__.py +0 -2
  3. qtype/application/converters/tools_from_api.py +67 -57
  4. qtype/application/converters/tools_from_module.py +66 -32
  5. qtype/base/types.py +6 -1
  6. qtype/commands/convert.py +3 -6
  7. qtype/commands/generate.py +97 -10
  8. qtype/commands/mcp.py +68 -0
  9. qtype/commands/run.py +116 -44
  10. qtype/commands/validate.py +4 -4
  11. qtype/docs/.pages +8 -0
  12. qtype/docs/Concepts/mental-model-and-philosophy.md +363 -0
  13. qtype/docs/Contributing/.pages +4 -0
  14. qtype/docs/Contributing/index.md +283 -0
  15. qtype/docs/Contributing/roadmap.md +81 -0
  16. qtype/docs/Decisions/ADR-001-Chat-vs-Completion-Endpoint-Features.md +56 -0
  17. qtype/docs/Gallery/dataflow_pipelines.md +81 -0
  18. qtype/docs/Gallery/dataflow_pipelines.mermaid +45 -0
  19. qtype/docs/Gallery/research_assistant.md +97 -0
  20. qtype/docs/Gallery/research_assistant.mermaid +42 -0
  21. qtype/docs/Gallery/simple_chatbot.md +38 -0
  22. qtype/docs/Gallery/simple_chatbot.mermaid +35 -0
  23. qtype/docs/How To/Authentication/configure_aws_authentication.md +60 -0
  24. qtype/docs/How To/Authentication/use_api_key_authentication.md +40 -0
  25. qtype/docs/How To/Command Line Usage/load_multiple_inputs_from_files.md +77 -0
  26. qtype/docs/How To/Command Line Usage/pass_inputs_on_the_cli.md +52 -0
  27. qtype/docs/How To/Command Line Usage/serve_with_auto_reload.md +27 -0
  28. qtype/docs/How To/Data Processing/adjust_concurrency.md +40 -0
  29. qtype/docs/How To/Data Processing/cache_step_results.md +71 -0
  30. qtype/docs/How To/Data Processing/decode_json_xml.md +24 -0
  31. qtype/docs/How To/Data Processing/explode_collections.md +40 -0
  32. qtype/docs/How To/Data Processing/gather_results.md +68 -0
  33. qtype/docs/How To/Data Processing/invoke_other_flows.md +71 -0
  34. qtype/docs/How To/Data Processing/load_data_from_athena.md +49 -0
  35. qtype/docs/How To/Data Processing/read_data_from_files.md +61 -0
  36. qtype/docs/How To/Data Processing/read_sql_databases.md +46 -0
  37. qtype/docs/How To/Data Processing/write_data_to_file.md +39 -0
  38. qtype/docs/How To/Invoke Models/call_large_language_models.md +51 -0
  39. qtype/docs/How To/Invoke Models/create_embeddings.md +49 -0
  40. qtype/docs/How To/Invoke Models/reuse_prompts_with_templates.md +38 -0
  41. qtype/docs/How To/Language Features/include_qtype_yaml.md +45 -0
  42. qtype/docs/How To/Language Features/include_raw_text_from_other_files.md +48 -0
  43. qtype/docs/How To/Language Features/reference_entities_by_id.md +51 -0
  44. qtype/docs/How To/Language Features/use_agent_skills.md +29 -0
  45. qtype/docs/How To/Language Features/use_environment_variables.md +48 -0
  46. qtype/docs/How To/Language Features/use_optional_variables.md +42 -0
  47. qtype/docs/How To/Language Features/use_qtype_mcp.md +59 -0
  48. qtype/docs/How To/Observability & Debugging/trace_calls_with_open_telemetry.md +49 -0
  49. qtype/docs/How To/Observability & Debugging/validate_qtype_yaml.md +36 -0
  50. qtype/docs/How To/Observability & Debugging/visualize_application_architecture.md +61 -0
  51. qtype/docs/How To/Observability & Debugging/visualize_example.mermaid +35 -0
  52. qtype/docs/How To/Qtype Server/flow_as_ui.png +0 -0
  53. qtype/docs/How To/Qtype Server/serve_flows_as_apis.md +40 -0
  54. qtype/docs/How To/Qtype Server/serve_flows_as_ui.md +41 -0
  55. qtype/docs/How To/Qtype Server/use_conversational_interfaces.md +56 -0
  56. qtype/docs/How To/Qtype Server/use_variables_with_ui_hints.md +48 -0
  57. qtype/docs/How To/Tools & Integration/bind_tool_inputs_and_outputs.md +47 -0
  58. qtype/docs/How To/Tools & Integration/create_tools_from_openapi_specifications.md +85 -0
  59. qtype/docs/How To/Tools & Integration/create_tools_from_python_modules.md +87 -0
  60. qtype/docs/Reference/cli.md +336 -0
  61. qtype/docs/Reference/plugins.md +99 -0
  62. qtype/docs/Reference/semantic-validation-rules.md +184 -0
  63. qtype/docs/Tutorials/.pages +1 -0
  64. qtype/docs/Tutorials/01-first-qtype-application.md +249 -0
  65. qtype/docs/Tutorials/02-conversational-chatbot.md +327 -0
  66. qtype/docs/Tutorials/03-structured-data.md +480 -0
  67. qtype/docs/Tutorials/04-tools-and-function-calling.md +476 -0
  68. qtype/docs/Tutorials/example_chat.png +0 -0
  69. qtype/docs/Tutorials/index.md +92 -0
  70. qtype/docs/components/APIKeyAuthProvider.md +7 -0
  71. qtype/docs/components/APITool.md +10 -0
  72. qtype/docs/components/AWSAuthProvider.md +13 -0
  73. qtype/docs/components/AWSSecretManager.md +5 -0
  74. qtype/docs/components/Agent.md +6 -0
  75. qtype/docs/components/Aggregate.md +7 -0
  76. qtype/docs/components/AggregateStats.md +7 -0
  77. qtype/docs/components/Application.md +22 -0
  78. qtype/docs/components/AuthorizationProvider.md +6 -0
  79. qtype/docs/components/AuthorizationProviderList.md +5 -0
  80. qtype/docs/components/BearerTokenAuthProvider.md +6 -0
  81. qtype/docs/components/BedrockReranker.md +8 -0
  82. qtype/docs/components/ChatContent.md +7 -0
  83. qtype/docs/components/ChatMessage.md +6 -0
  84. qtype/docs/components/Collect.md +6 -0
  85. qtype/docs/components/ConstantPath.md +5 -0
  86. qtype/docs/components/Construct.md +6 -0
  87. qtype/docs/components/CustomType.md +7 -0
  88. qtype/docs/components/Decoder.md +8 -0
  89. qtype/docs/components/DecoderFormat.md +8 -0
  90. qtype/docs/components/DocToTextConverter.md +7 -0
  91. qtype/docs/components/Document.md +7 -0
  92. qtype/docs/components/DocumentEmbedder.md +6 -0
  93. qtype/docs/components/DocumentIndex.md +7 -0
  94. qtype/docs/components/DocumentSearch.md +7 -0
  95. qtype/docs/components/DocumentSource.md +12 -0
  96. qtype/docs/components/DocumentSplitter.md +9 -0
  97. qtype/docs/components/Echo.md +8 -0
  98. qtype/docs/components/Embedding.md +7 -0
  99. qtype/docs/components/EmbeddingModel.md +6 -0
  100. qtype/docs/components/Explode.md +5 -0
  101. qtype/docs/components/FieldExtractor.md +21 -0
  102. qtype/docs/components/FileSource.md +6 -0
  103. qtype/docs/components/FileWriter.md +7 -0
  104. qtype/docs/components/Flow.md +14 -0
  105. qtype/docs/components/FlowInterface.md +7 -0
  106. qtype/docs/components/Index.md +8 -0
  107. qtype/docs/components/IndexUpsert.md +6 -0
  108. qtype/docs/components/InvokeEmbedding.md +7 -0
  109. qtype/docs/components/InvokeFlow.md +8 -0
  110. qtype/docs/components/InvokeTool.md +8 -0
  111. qtype/docs/components/LLMInference.md +9 -0
  112. qtype/docs/components/ListType.md +5 -0
  113. qtype/docs/components/Memory.md +8 -0
  114. qtype/docs/components/MessageRole.md +14 -0
  115. qtype/docs/components/Model.md +10 -0
  116. qtype/docs/components/ModelList.md +5 -0
  117. qtype/docs/components/OAuth2AuthProvider.md +9 -0
  118. qtype/docs/components/PrimitiveTypeEnum.md +20 -0
  119. qtype/docs/components/PromptTemplate.md +7 -0
  120. qtype/docs/components/PythonFunctionTool.md +7 -0
  121. qtype/docs/components/RAGChunk.md +7 -0
  122. qtype/docs/components/RAGDocument.md +10 -0
  123. qtype/docs/components/RAGSearchResult.md +8 -0
  124. qtype/docs/components/Reranker.md +5 -0
  125. qtype/docs/components/SQLSource.md +8 -0
  126. qtype/docs/components/Search.md +7 -0
  127. qtype/docs/components/SearchResult.md +7 -0
  128. qtype/docs/components/SecretManager.md +7 -0
  129. qtype/docs/components/SecretReference.md +7 -0
  130. qtype/docs/components/Source.md +5 -0
  131. qtype/docs/components/Step.md +8 -0
  132. qtype/docs/components/TelemetrySink.md +9 -0
  133. qtype/docs/components/Tool.md +9 -0
  134. qtype/docs/components/ToolList.md +5 -0
  135. qtype/docs/components/TypeList.md +5 -0
  136. qtype/docs/components/Variable.md +8 -0
  137. qtype/docs/components/VariableList.md +5 -0
  138. qtype/docs/components/VectorIndex.md +7 -0
  139. qtype/docs/components/VectorSearch.md +6 -0
  140. qtype/docs/components/VertexAuthProvider.md +9 -0
  141. qtype/docs/components/Writer.md +5 -0
  142. qtype/docs/example_ui.png +0 -0
  143. qtype/docs/index.md +81 -0
  144. qtype/docs/legacy_how_tos/.pages +6 -0
  145. qtype/docs/legacy_how_tos/Configuration/modular-yaml.md +366 -0
  146. qtype/docs/legacy_how_tos/Configuration/phoenix_projects.png +0 -0
  147. qtype/docs/legacy_how_tos/Configuration/phoenix_traces.png +0 -0
  148. qtype/docs/legacy_how_tos/Configuration/reference-by-id.md +251 -0
  149. qtype/docs/legacy_how_tos/Configuration/telemetry-setup.md +259 -0
  150. qtype/docs/legacy_how_tos/Data Types/custom-types.md +52 -0
  151. qtype/docs/legacy_how_tos/Data Types/domain-types.md +113 -0
  152. qtype/docs/legacy_how_tos/Debugging/visualize-apps.md +147 -0
  153. qtype/docs/legacy_how_tos/Tools/api-tools.md +29 -0
  154. qtype/docs/legacy_how_tos/Tools/python-tools.md +299 -0
  155. qtype/docs/skills/architect/SKILL.md +188 -0
  156. qtype/docs/skills/architect/references/cheatsheet.md +198 -0
  157. qtype/docs/skills/architect/references/patterns.md +29 -0
  158. qtype/docs/stylesheets/extra.css +27 -0
  159. qtype/dsl/custom_types.py +2 -1
  160. qtype/dsl/linker.py +23 -7
  161. qtype/dsl/loader.py +3 -3
  162. qtype/dsl/model.py +181 -67
  163. qtype/examples/authentication/aws_authentication.qtype.yaml +63 -0
  164. qtype/examples/conversational_ai/hello_world_chat.qtype.yaml +43 -0
  165. qtype/examples/conversational_ai/simple_chatbot.qtype.yaml +40 -0
  166. qtype/examples/data_processing/athena_query.qtype.yaml +56 -0
  167. qtype/examples/data_processing/batch_inputs.csv +5 -0
  168. qtype/examples/data_processing/batch_processing.qtype.yaml +54 -0
  169. qtype/examples/data_processing/cache_step_results.qtype.yaml +78 -0
  170. qtype/examples/data_processing/collect_results.qtype.yaml +55 -0
  171. qtype/examples/data_processing/create_sample_db.py +129 -0
  172. qtype/examples/data_processing/dataflow_pipelines.qtype.yaml +108 -0
  173. qtype/examples/data_processing/decode_json.qtype.yaml +23 -0
  174. qtype/examples/data_processing/explode_items.qtype.yaml +25 -0
  175. qtype/examples/data_processing/invoke_other_flows.qtype.yaml +98 -0
  176. qtype/examples/data_processing/read_file.qtype.yaml +60 -0
  177. qtype/examples/data_processing/reviews.db +0 -0
  178. qtype/examples/data_processing/sample_article.txt +1 -0
  179. qtype/examples/data_processing/sample_documents.jsonl +5 -0
  180. qtype/examples/invoke_models/create_embeddings.qtype.yaml +28 -0
  181. qtype/examples/invoke_models/simple_llm_call.qtype.yaml +32 -0
  182. qtype/examples/language_features/include_raw.qtype.yaml +27 -0
  183. qtype/examples/language_features/optional_variables.qtype.yaml +32 -0
  184. qtype/examples/language_features/story_prompt.txt +6 -0
  185. qtype/examples/language_features/ui_hints.qtype.yaml +52 -0
  186. qtype/examples/legacy/bedrock/data_analysis_with_telemetry.qtype.yaml +169 -0
  187. qtype/examples/legacy/bedrock/hello_world.qtype.yaml +39 -0
  188. qtype/examples/legacy/bedrock/hello_world_chat.qtype.yaml +37 -0
  189. qtype/examples/legacy/bedrock/hello_world_chat_with_telemetry.qtype.yaml +40 -0
  190. qtype/examples/legacy/bedrock/hello_world_chat_with_thinking.qtype.yaml +40 -0
  191. qtype/examples/legacy/bedrock/hello_world_completion.qtype.yaml +41 -0
  192. qtype/examples/legacy/bedrock/hello_world_completion_with_auth.qtype.yaml +44 -0
  193. qtype/examples/legacy/bedrock/simple_agent_chat.qtype.yaml +46 -0
  194. qtype/examples/legacy/chat_with_langfuse.qtype.yaml +50 -0
  195. qtype/examples/legacy/data/customers.csv +6 -0
  196. qtype/examples/legacy/data_processor.qtype.yaml +48 -0
  197. qtype/examples/legacy/echo/debug_example.qtype.yaml +59 -0
  198. qtype/examples/legacy/echo/prompt.qtype.yaml +22 -0
  199. qtype/examples/legacy/echo/readme.md +29 -0
  200. qtype/examples/legacy/echo/test.qtype.yaml +26 -0
  201. qtype/examples/legacy/echo/video.qtype.yaml +20 -0
  202. qtype/examples/legacy/field_extractor_example.qtype.yaml +137 -0
  203. qtype/examples/legacy/multi_flow_example.qtype.yaml +125 -0
  204. qtype/examples/legacy/openai/hello_world_chat.qtype.yaml +43 -0
  205. qtype/examples/legacy/openai/hello_world_chat_with_telemetry.qtype.yaml +46 -0
  206. qtype/examples/legacy/qtype_plugin_example.py +51 -0
  207. qtype/examples/legacy/rag.qtype.yaml +207 -0
  208. qtype/examples/legacy/sample_data.txt +43 -0
  209. qtype/examples/legacy/time_utilities.qtype.yaml +64 -0
  210. qtype/examples/legacy/vertex/README.md +11 -0
  211. qtype/examples/legacy/vertex/hello_world_chat.qtype.yaml +36 -0
  212. qtype/examples/legacy/vertex/hello_world_completion.qtype.yaml +40 -0
  213. qtype/examples/legacy/vertex/hello_world_completion_with_auth.qtype.yaml +45 -0
  214. qtype/examples/observability_debugging/trace_with_opentelemetry.qtype.yaml +40 -0
  215. qtype/examples/research_assistant/research_assistant.qtype.yaml +94 -0
  216. qtype/examples/research_assistant/tavily.oas.yaml +722 -0
  217. qtype/examples/research_assistant/tavily.qtype.yaml +216 -0
  218. qtype/examples/tutorials/01_hello_world.qtype.yaml +48 -0
  219. qtype/examples/tutorials/02_conversational_chat.qtype.yaml +37 -0
  220. qtype/examples/tutorials/03_structured_data.qtype.yaml +130 -0
  221. qtype/examples/tutorials/04_tools_and_function_calling.qtype.yaml +89 -0
  222. qtype/interpreter/api.py +4 -1
  223. qtype/interpreter/base/base_step_executor.py +3 -1
  224. qtype/interpreter/base/stream_emitter.py +19 -13
  225. qtype/interpreter/conversions.py +7 -3
  226. qtype/interpreter/converters.py +142 -26
  227. qtype/interpreter/executors/agent_executor.py +2 -3
  228. qtype/interpreter/executors/aggregate_executor.py +3 -4
  229. qtype/interpreter/executors/construct_executor.py +15 -15
  230. qtype/interpreter/executors/doc_to_text_executor.py +1 -3
  231. qtype/interpreter/executors/field_extractor_executor.py +13 -12
  232. qtype/interpreter/executors/file_source_executor.py +21 -34
  233. qtype/interpreter/executors/file_writer_executor.py +4 -4
  234. qtype/interpreter/executors/index_upsert_executor.py +1 -1
  235. qtype/interpreter/executors/invoke_embedding_executor.py +1 -4
  236. qtype/interpreter/executors/invoke_flow_executor.py +2 -2
  237. qtype/interpreter/executors/invoke_tool_executor.py +19 -18
  238. qtype/interpreter/executors/llm_inference_executor.py +16 -18
  239. qtype/interpreter/executors/prompt_template_executor.py +1 -3
  240. qtype/interpreter/executors/sql_source_executor.py +1 -1
  241. qtype/interpreter/resource_cache.py +3 -1
  242. qtype/interpreter/rich_progress.py +6 -3
  243. qtype/interpreter/stream/chat/converter.py +25 -17
  244. qtype/interpreter/stream/chat/ui_request_to_domain_type.py +2 -2
  245. qtype/interpreter/tools/function_tool_helper.py +11 -10
  246. qtype/interpreter/types.py +89 -4
  247. qtype/interpreter/typing.py +35 -38
  248. qtype/mcp/__init__.py +0 -0
  249. qtype/mcp/server.py +722 -0
  250. qtype/schema/qtype.schema.json +4016 -0
  251. qtype/semantic/checker.py +20 -1
  252. qtype/semantic/generate.py +6 -9
  253. qtype/semantic/model.py +26 -33
  254. qtype/semantic/resolver.py +7 -0
  255. qtype/semantic/visualize.py +45 -53
  256. {qtype-0.1.11.dist-info → qtype-0.1.13.dist-info}/METADATA +65 -44
  257. qtype-0.1.13.dist-info/RECORD +352 -0
  258. {qtype-0.1.11.dist-info → qtype-0.1.13.dist-info}/WHEEL +1 -2
  259. qtype/application/facade.py +0 -177
  260. qtype-0.1.11.dist-info/RECORD +0 -142
  261. qtype-0.1.11.dist-info/top_level.txt +0 -1
  262. {qtype-0.1.11.dist-info → qtype-0.1.13.dist-info}/entry_points.txt +0 -0
  263. {qtype-0.1.11.dist-info → qtype-0.1.13.dist-info}/licenses/LICENSE +0 -0
@@ -0,0 +1,476 @@
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 ../../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
+ - id: timestamp
262
+ type: datetime
263
+ - id: days
264
+ type: int?
265
+ - id: hours
266
+ type: int?
267
+ # ... more optional parameters
268
+ ```
269
+
270
+ **Optional parameters:** You only need to bind the required parameters. `timedelta` has many optional parameters (hours, minutes, seconds, weeks), but we only use `days`.
271
+
272
+ ---
273
+
274
+ ### Chain Tools Together
275
+
276
+ Finally, format the deadline using the output from the previous step:
277
+
278
+ ```yaml
279
+ # Step 4: Format deadline for human readability
280
+ # Shows chaining: output from previous tool becomes input to this one
281
+ - id: format_deadline
282
+ type: InvokeTool
283
+ tool: qtype.application.commons.tools.format_datetime
284
+ input_bindings:
285
+ timestamp: deadline_time
286
+ format_string: format_string
287
+ output_bindings:
288
+ result: deadline_formatted
289
+ outputs:
290
+ - deadline_formatted
291
+ ```
292
+
293
+ **Check your work:**
294
+
295
+ ```bash
296
+ qtype validate 04_tools_and_function_calling.qtype.yaml
297
+ ```
298
+
299
+ Should pass ✅
300
+
301
+ ---
302
+
303
+ ## Part 3: Test Your Tools (5 minutes)
304
+
305
+ ### Run the Application
306
+
307
+ ```bash
308
+ qtype run -i '{"days_until_due": 3}' 04_tools_and_function_calling.qtype.yaml
309
+ ```
310
+
311
+ **Expected output:**
312
+
313
+ ```json
314
+ {
315
+ "deadline_formatted": "January 17, 2026 at 03:39 PM UTC"
316
+ }
317
+ ```
318
+
319
+ The exact time will match when you run it, but the date should be 3 days from now.
320
+
321
+ ---
322
+
323
+ ### Try Different Durations
324
+
325
+ ```bash
326
+ # One week deadline
327
+ qtype run -i '{"days_until_due": 7}' 04_tools_and_function_calling.qtype.yaml
328
+
329
+ # Two weeks
330
+ qtype run -i '{"days_until_due": 14}' 04_tools_and_function_calling.qtype.yaml
331
+
332
+ # Same day (0 days)
333
+ qtype run -i '{"days_until_due": 0}' 04_tools_and_function_calling.qtype.yaml
334
+ ```
335
+
336
+ ---
337
+
338
+ ### Add the `--progress` Flag
339
+
340
+ For more visibility into tool execution:
341
+
342
+ ```bash
343
+ qtype run -i '{"days_until_due": 3}' 04_tools_and_function_calling.qtype.yaml --progress
344
+ ```
345
+
346
+ You'll see each step execute in real-time:
347
+
348
+ ```
349
+ Step get_current_time ✔ 1 succeeded
350
+ Step create_format_string ✔ 1 succeeded
351
+ Step add_days ✔ 1 succeeded
352
+ Step format_deadline ✔ 1 succeeded
353
+ ```
354
+
355
+ ---
356
+
357
+ ## Part 4: Understanding Tools Deeply (Bonus)
358
+
359
+ ### Tool Types and Custom Types
360
+
361
+ Remember from Tutorial 3 where `calculate_time_difference` returns `TimeDifferenceResultType`? That's a custom type defined in the commons library:
362
+
363
+ ```yaml
364
+ types:
365
+ - id: TimeDifferenceResultType
366
+ properties:
367
+ days: int
368
+ seconds: int
369
+ microseconds: int
370
+ total_hours: float
371
+ total_minutes: float
372
+ total_seconds: float
373
+ total_days: float
374
+ ```
375
+
376
+ If you use `calculate_time_difference`, you can extract fields from its result:
377
+
378
+ ```yaml
379
+ - id: calc_difference
380
+ type: InvokeTool
381
+ tool: qtype.application.commons.tools.calculate_time_difference
382
+ input_bindings:
383
+ start_time: start
384
+ end_time: end
385
+ output_bindings:
386
+ result: time_diff # time_diff is now TimeDifferenceResultType
387
+
388
+ # Later, access fields using FieldExtractor or Construct
389
+ ```
390
+
391
+ ---
392
+
393
+ ### Generating Your Own Tools
394
+
395
+ When you're ready to create custom tools, use `qtype convert`:
396
+
397
+ **From a Python module:**
398
+
399
+ ```bash
400
+ # Generate tools from all functions in myapp.utils
401
+ qtype convert python --module myapp.utils --output my_tools.qtype.yaml
402
+ ```
403
+
404
+ QType will:
405
+ - Scan all public functions in the module
406
+ - Extract type hints from function signatures
407
+ - Generate tool definitions with proper input/output types
408
+ - Include docstrings as descriptions
409
+
410
+ **From an OpenAPI spec:**
411
+
412
+ ```bash
413
+ # Generate tools from a REST API
414
+ qtype convert openapi --spec weather_api.yaml --output weather_tools.qtype.yaml
415
+ ```
416
+
417
+ QType will:
418
+ - Parse endpoint definitions
419
+ - Create a tool for each operation
420
+ - Map request parameters to tool inputs
421
+ - Map response schemas to tool outputs
422
+ - Handle authentication configurations
423
+
424
+ <!-- **Learn more:** See the [How-To Guide: Generate Tools](../How-To%20Guides/Tools/generate-tools.md) for detailed examples. -->
425
+
426
+ ---
427
+
428
+ ## What You've Learned
429
+
430
+ Congratulations! You've mastered:
431
+
432
+ ✅ **Tool concepts** - References to Python functions or API calls
433
+ ✅ **Importing tools** - Using `!include` with local or remote files
434
+ ✅ **InvokeTool step** - Calling tools with input/output bindings
435
+ ✅ **Input bindings** - Mapping flow variables to tool parameters
436
+ ✅ **Output bindings** - Mapping tool results to flow variables
437
+ ✅ **Tool chaining** - Connecting outputs to inputs across steps
438
+ ✅ **Commons library** - Pre-built tools for common operations
439
+ ✅ **Tool generation** - Using `qtype convert` to create tool definitions
440
+
441
+ ---
442
+
443
+ ## Next Steps
444
+
445
+ **Reference the complete example:**
446
+
447
+ - [`04_tools_and_function_calling.qtype.yaml`](https://github.com/bazaarvoice/qtype/blob/main/examples/tutorials/04_tools_and_function_calling.qtype.yaml)
448
+ - [Commons Library Tools](https://github.com/bazaarvoice/qtype/blob/main/common/tools.qtype.yaml)
449
+
450
+ **Learn more:**
451
+
452
+ - [Create Tools from Python Modules](../How%20To/Tools%20%26%20Integration/create_tools_from_python_modules.md)
453
+ - [Create Tools from OpenAPI Specifications](../How%20To/Tools%20%26%20Integration/create_tools_from_openapi_specifications.md)
454
+ - [Bind Tool Inputs and Outputs](../How%20To/Tools%20%26%20Integration/bind_tool_inputs_and_outputs.md)
455
+
456
+ ---
457
+
458
+ ## Common Questions
459
+
460
+ **Q: Can I call multiple tools in parallel?**
461
+ 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.
462
+
463
+ **Q: What happens if a tool raises an error?**
464
+ A: The flow stops and returns an error.
465
+
466
+ **Q: Can I pass literal values instead of variables to tools?**
467
+ A: No - `input_bindings` only accepts variable names. Use PromptTemplate to create constant variables, or define them in your flow's input data.
468
+
469
+ **Q: How do I know what parameters a tool accepts?**
470
+ 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.
471
+
472
+ **Q: Can tools modify variables or have side effects?**
473
+ 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.
474
+
475
+ **Q: What's the difference between InvokeTool and Agent?**
476
+ 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** (`list[Variable]`): Path and query parameters for the API call.
@@ -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,7 @@
1
+ ### Aggregate
2
+
3
+ A step that, after all messages have been processed,
4
+ returns a single message containing the counts of successful and failed
5
+ messages. Other messages are passed through unchanged.
6
+
7
+ - **type** (`Literal`): (No documentation available.)
@@ -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.