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,299 @@
1
+ # Create Tools from Python Modules
2
+
3
+ QType allows you to automatically convert Python functions into QType tools. This tutorial will walk you through creating a Python module with functions and converting them into a QType specification that can be used in your applications.
4
+
5
+ ## Prerequisites
6
+
7
+ Before following this tutorial, make sure you understand:
8
+
9
+ - [Variables and types](../../Concepts/Core/variable.md) in QType
10
+ - [Primitive types](../../components/PrimitiveTypeEnum.md)
11
+ - [Domain types](../Data%20Types/domain-types.md)
12
+ - [Custom types](../Data%20Types/custom-types.md)
13
+
14
+ ## Overview
15
+
16
+ The `qtype convert module` command analyzes Python functions in a module and automatically generates QType tool definitions. This saves you from manually writing tool specifications and ensures consistency between your Python code and QType definitions.
17
+
18
+ ## Supported Types
19
+
20
+ For functions to be converted successfully, all arguments and return types must use supported type annotations:
21
+
22
+ ### Primitive Types
23
+ - `str` → `text`
24
+ - `int` → `int`
25
+ - `float` → `float`
26
+ - `bool` → `boolean`
27
+ - `bytes` → `file`
28
+ - `datetime.datetime` → `datetime`
29
+ - `datetime.date` → `date`
30
+ - `datetime.time` → `time`
31
+
32
+ ### Domain Types
33
+ - `ChatMessage` from `qtype.dsl.domain_types`
34
+ - `ChatContent` from `qtype.dsl.domain_types`
35
+ - `Embedding` from `qtype.dsl.domain_types`
36
+
37
+ ### Custom Types
38
+ You can use your own classes **only if** they inherit from `pydantic.BaseModel`. These will be automatically converted to QType custom types.
39
+
40
+ ## Creating a Sample Module
41
+
42
+ Let's create a sample Python module with utility functions. Create a new file called `my_utilities.py`:
43
+
44
+ ```python
45
+ from datetime import datetime, timedelta
46
+ from pydantic import BaseModel
47
+
48
+
49
+ class ProcessingResult(BaseModel):
50
+ """Result of a text processing operation."""
51
+ processed_text: str
52
+ word_count: int
53
+ processing_time: float
54
+
55
+
56
+ def count_words(text: str) -> int:
57
+ """
58
+ Count the number of words in a text string.
59
+
60
+ Args:
61
+ text: The input text to count words in.
62
+
63
+ Returns:
64
+ Number of words in the text.
65
+ """
66
+ return len(text.split())
67
+
68
+
69
+ def format_timestamp(timestamp: datetime, format_str: str = "%Y-%m-%d %H:%M:%S") -> str:
70
+ """
71
+ Format a datetime object as a string.
72
+
73
+ Args:
74
+ timestamp: The datetime to format.
75
+ format_str: The format string to use.
76
+
77
+ Returns:
78
+ Formatted datetime string.
79
+ """
80
+ return timestamp.strftime(format_str)
81
+
82
+
83
+ def calculate_future_date(start_date: datetime, days_ahead: int) -> datetime:
84
+ """
85
+ Calculate a future date by adding days to a start date.
86
+
87
+ Args:
88
+ start_date: The starting date.
89
+ days_ahead: Number of days to add.
90
+
91
+ Returns:
92
+ The calculated future date.
93
+ """
94
+ return start_date + timedelta(days=days_ahead)
95
+
96
+
97
+ def process_text_advanced(text: str, uppercase: bool = False) -> ProcessingResult:
98
+ """
99
+ Process text and return detailed results.
100
+
101
+ Args:
102
+ text: The text to process.
103
+ uppercase: Whether to convert to uppercase.
104
+
105
+ Returns:
106
+ Processing results including word count and timing.
107
+ """
108
+ import time
109
+ start_time = time.time()
110
+
111
+ processed = text.upper() if uppercase else text.lower()
112
+ word_count = len(text.split())
113
+ processing_time = time.time() - start_time
114
+
115
+ return ProcessingResult(
116
+ processed_text=processed,
117
+ word_count=word_count,
118
+ processing_time=processing_time
119
+ )
120
+ ```
121
+
122
+ ## Converting the Module to QType Tools
123
+
124
+ Now convert your Python module to QType tools using the CLI:
125
+
126
+ ```bash
127
+ qtype convert module my_utilities -o my_utilities.qtype.yml
128
+ ```
129
+
130
+ This will generate a QType specification file with all your functions converted to tools.
131
+
132
+ ## Understanding the Generated Output
133
+
134
+ The generated `my_utilities.qtype.yml` file will contain:
135
+
136
+ ```yaml
137
+ description: Tools created from Python module my_utilities
138
+ id: my_utilities
139
+ tools:
140
+ - description: Count the number of words in a text string.
141
+ function_name: count_words
142
+ id: my_utilities.count_words
143
+ inputs:
144
+ - id: count_words.text
145
+ type: text
146
+ module_path: my_utilities
147
+ name: count_words
148
+ outputs:
149
+ - id: my_utilities.count_words.result
150
+ type: int
151
+
152
+ - description: Format a datetime object as a string.
153
+ function_name: format_timestamp
154
+ id: my_utilities.format_timestamp
155
+ inputs:
156
+ - id: format_timestamp.timestamp
157
+ type: datetime
158
+ - id: format_timestamp.format_str
159
+ type: text
160
+ module_path: my_utilities
161
+ name: format_timestamp
162
+ outputs:
163
+ - id: my_utilities.format_timestamp.result
164
+ type: text
165
+
166
+ - description: Calculate a future date by adding days to a start date.
167
+ function_name: calculate_future_date
168
+ id: my_utilities.calculate_future_date
169
+ inputs:
170
+ - id: calculate_future_date.start_date
171
+ type: datetime
172
+ - id: calculate_future_date.days_ahead
173
+ type: int
174
+ module_path: my_utilities
175
+ name: calculate_future_date
176
+ outputs:
177
+ - id: my_utilities.calculate_future_date.result
178
+ type: datetime
179
+
180
+ - description: Process text and return detailed results.
181
+ function_name: process_text_advanced
182
+ id: my_utilities.process_text_advanced
183
+ inputs:
184
+ - id: process_text_advanced.text
185
+ type: text
186
+ - id: process_text_advanced.uppercase
187
+ type: boolean
188
+ module_path: my_utilities
189
+ name: process_text_advanced
190
+ outputs:
191
+ - id: my_utilities.process_text_advanced.result
192
+ type: ProcessingResult
193
+
194
+ types:
195
+ - description: Result of a text processing operation.
196
+ id: ProcessingResult
197
+ properties:
198
+ processed_text: str
199
+ word_count: int
200
+ processing_time: float
201
+ ```
202
+
203
+ ## Key Features of the Conversion
204
+
205
+ ### Automatic Type Mapping
206
+ - Python types are automatically mapped to QType types
207
+ - Type hints are required for all function parameters and return values
208
+ - Docstrings are extracted and used as tool descriptions
209
+
210
+ ### Custom Type Generation
211
+ - Pydantic models are automatically converted to QType custom types
212
+ - The `ProcessingResult` class becomes a custom type definition
213
+ - All fields in the Pydantic model are preserved with their types
214
+
215
+ ### Tool Naming
216
+ - Tool IDs follow the pattern: `{module_path}.{function_name}`
217
+ - Input variable IDs follow: `{function_name}.{parameter_name}`
218
+ - Output variable IDs follow: `{module_path}.{function_name}.result`
219
+
220
+ ## Requirements and Limitations
221
+
222
+ ### Function Requirements
223
+ 1. **Type Annotations**: All functions must have complete type annotations for parameters and return values
224
+ 2. **Public Functions**: Only public functions (not starting with `_`) are converted
225
+ 3. **Module Definition**: Functions must be defined in the target module (not imported from elsewhere)
226
+ 4. **Supported Types**: All types must be mappable to QType types
227
+
228
+ ### Unsupported Features
229
+ - Functions with `*args` or `**kwargs` parameters
230
+ - Functions without return type annotations
231
+ - Complex generic types (e.g., `Dict[str, List[int]]`)
232
+ - Circular type references
233
+
234
+ ## Using Generated Tools
235
+
236
+ Once you have your `.qtype.yml` file, you can use these tools in QType applications:
237
+
238
+ ```yaml
239
+ id: text_processing_app
240
+ name: Text Processing Application
241
+
242
+ tools:
243
+ - import: my_utilities.qtype.yml
244
+
245
+ flows:
246
+ - id: word_counter_flow
247
+ name: Count Words Flow
248
+ inputs:
249
+ - id: input_text
250
+ type: text
251
+ steps:
252
+ - id: count
253
+ type: tool
254
+ tool: my_utilities.count_words
255
+ inputs:
256
+ text: $input_text
257
+ outputs:
258
+ - id: word_count
259
+ source: count.result
260
+ ```
261
+
262
+ ## Best Practices
263
+
264
+ ### Function Design
265
+ 1. **Clear Docstrings**: Write descriptive docstrings as they become tool descriptions
266
+ 2. **Single Responsibility**: Keep functions focused on one task
267
+ 3. **Type Safety**: Use precise type hints rather than `Any`
268
+ 4. **Error Handling**: Include proper error handling in your functions
269
+
270
+ ### Module Organization
271
+ 1. **Logical Grouping**: Group related functions in the same module
272
+ 2. **Dependencies**: Keep external dependencies minimal
273
+ 3. **Testing**: Write tests for your functions before converting
274
+
275
+ ### Custom Types
276
+ 1. **Pydantic Models**: Use Pydantic BaseModel for complex return types
277
+ 2. **Field Documentation**: Add docstrings to model fields
278
+ 3. **Type Validation**: Leverage Pydantic's validation features
279
+
280
+ ## Troubleshooting
281
+
282
+ ### Common Issues
283
+
284
+ **"Function must have a return type annotation"**
285
+ - Ensure all functions have explicit return type annotations
286
+
287
+ **"Unsupported Python type"**
288
+ - Check that all parameter and return types are supported
289
+ - Consider using custom Pydantic models for complex types
290
+
291
+ **"No public functions found"**
292
+ - Verify functions don't start with underscore
293
+ - Check functions are defined in the target module
294
+
295
+ ### Debugging Tips
296
+ 1. Start with simple functions and gradually add complexity
297
+ 2. Test your Python functions independently before conversion
298
+ 3. Use `mypy` to validate type annotations before conversion
299
+
@@ -0,0 +1,188 @@
1
+ ---
2
+ name: qtype-architect
3
+ description: Expert assistant for designing and building AI applications using QType's declarative YAML specification language. Helps users architect flows from concept to implementation, validates QType code, generates visualizations, and recommends best practices. Use when users want to build chatbots, RAG systems, agents, data pipelines, or any AI application with QType. Use when the user mentions building AI apps, RAG pipelines, or YAML-based agent orchestration.
4
+ compatibility: Requires the 'qtype-mcp' MCP server to be active for schema lookup and validation.
5
+ metadata:
6
+ author: qtype
7
+ version: "1.0"
8
+ allowed-tools: qtype-mcp:*
9
+ ---
10
+
11
+ # QType Architect
12
+
13
+ Expert assistant for designing and building AI applications using the QType DSL.
14
+
15
+ ## When to use this skill
16
+
17
+ Activate when users want to:
18
+ - Design QType applications (chatbots, RAG, agents, pipelines)
19
+ - Convert requirements into QType YAML specifications
20
+ - Validate or debug QType code
21
+ - Visualize application architecture
22
+ - Learn QType best practices and patterns
23
+
24
+ ## What is QType?
25
+
26
+ **QType is a domain-specific language (DSL) for rapid prototyping of AI applications.**
27
+
28
+ Qtype is a declarative, text-based language that lets you specify *what* your AI application should do, not *how* to do it. You write YAML specifications that describe flows, steps, models, and data transformations, and QType handles the execution.
29
+
30
+ **Elevator pitch:** QType turns AI application prototypes from days of Python coding into hours of YAML configuration, without sacrificing maintainability or requiring you to learn yet another GUI tool.
31
+
32
+ ## Core Mental Model
33
+
34
+ Understanding QType requires understanding core concepts and how they relate:
35
+
36
+ **Think of QType like this:**
37
+
38
+ **Variables** are your data containers (typed boxes)
39
+ **Steps** are your transformations (functions on boxes)
40
+ **Flows** are your pipelines (sequences of transformations)
41
+ **The DSL** is your specification language (what you write)
42
+ **The Semantic layer** is your validator (what checks it)
43
+ **The Interpreter** is your executor (what runs it)
44
+
45
+ ## Core workflow
46
+
47
+ ### 1. Understand requirements
48
+
49
+ Clarify the user's goal through targeted questions:
50
+ - What is the overall goal?
51
+ - What are the inputs and outputs?
52
+ - What processing steps are needed?
53
+ - Which models, APIs, or tools are required?
54
+ - Authentication requirements?
55
+ - Conversational vs batch processing?
56
+
57
+ Prefer inferring reasonable defaults over excessive questions.
58
+
59
+ ### 2. Use MCP tools to research
60
+
61
+ **CRITICAL: Always use the qtype-mcp server to look up information rather than guessing.**
62
+
63
+ - Use `list_components` to discover available component types
64
+ - Use `get_component_schema` to get detailed field requirements for specific components
65
+ - Use `search_library` to find relevant documentation and examples
66
+ - Use `list_examples` and `get_example` to see real QType code patterns
67
+ - Use `list_documentation` and `get_documentation` to get specific guides, tutorials, or references
68
+
69
+ **Don't make assumptions about component fields, syntax, or capabilities - look them up!**
70
+
71
+ ### 3. Design architecture
72
+
73
+ Map requirements to QType components. For guidance:
74
+ - See [references/patterns.md](references/patterns.md) for common architecture patterns
75
+ - See [references/cheatsheet.md](references/cheatsheet.md) for quick component reference
76
+ - See `assets/*.qtype.yaml` for complete working examples
77
+
78
+ Use MCP tools to verify component schemas and field requirements as you design.
79
+
80
+ ### 4. Generate and validate
81
+
82
+ **ALWAYS validate:**
83
+
84
+ 1. Generate complete QType YAML
85
+ 2. Call `validate_qtype_yaml` with your YAML
86
+ 3. If errors: fix specific issues and validate again
87
+ 4. Present validated code to user
88
+ 5. If success and you have mermaid preview capability, call `visualize_qtype_architecture` and use the mermaid preview to visalize the result to the user.
89
+
90
+ **Never skip validation.** Invalid code wastes user time.
91
+
92
+ ### 5. Visualization (Optional)
93
+
94
+ The `visualize` tool in qtype-mcp converts the qtype yaml to an archiecture diagram.
95
+ If you or the user desires it, use the tool and then open it with either the claude-mermaid mcp (if you are claude code) or the mermaid preview (if you are in vscode).
96
+ If neither of those tools are available, just let the user know and save the mermaid to disk.
97
+
98
+ ### 6. Provide context
99
+
100
+ After presenting validated code:
101
+ - Explain key architectural decisions
102
+ - Show how to run: `qtype run`, or `qtype validate`, `qtype serve`
103
+ - Point to relevant documentation
104
+ - Suggest next steps or improvements
105
+
106
+ ### 7. Optional Next Steps
107
+
108
+ If the user desires, or you think they would like it, you can run `qtype serve --reload <yaml_file>` to start the interpreter server. The serve command will print a url, open that in the users web browser so they can see the app.
109
+
110
+ The `--reload` will refresh each time the yaml is changed.
111
+
112
+ ## Using the qtype-mcp server
113
+
114
+ **CRITICAL: Use MCP tools constantly - don't guess or rely on memory!**
115
+
116
+ The qtype-mcp server provides tools for:
117
+ - **Discovery**: Browse components, docs, and examples
118
+ - **Schema lookup**: Get exact field requirements with `get_component_schema`
119
+ - **Search**: Full-text search across all documentation and examples
120
+ - **Validation**: `validate_qtype_yaml` - **Use before every code presentation**
121
+ - **Visualization**: Generate Mermaid diagrams of flows
122
+ - **Code generation**: Convert APIs/Python to QType tools
123
+
124
+ **Key workflow patterns:**
125
+ 1. Unsure about a component? → Use `get_component_schema`
126
+ 2. Need an example? → Use `search_library` or `list_examples`
127
+ 3. Generated YAML? → **Always call `validate_qtype_yaml`**
128
+ 4. Complex flow? → Use `visualize_qtype_architecture`
129
+
130
+ ## Reference materials
131
+
132
+ See bundled reference files for quick lookup:
133
+ - [references/patterns.md](references/patterns.md) - Common architecture patterns
134
+ - [references/cheatsheet.md](references/cheatsheet.md) - Component quick reference
135
+ - `assets/examples/*.qtype.yaml` for complete working examples.
136
+
137
+ ## Key guidelines
138
+
139
+ ### Self-correction on validation failure
140
+ If validation fails:
141
+ - **Do not guess the fix**
142
+ - Read the error message carefully
143
+ - Call `get_component_schema` for the failing component
144
+ - Compare your YAML against the official schema
145
+ - Make precise corrections based on schema requirements
146
+
147
+ ### Use MCP for everything
148
+ - Component details? → `get_component_schema`
149
+ - Need examples? → `list_examples` + `get_example`
150
+ - Unclear syntax? → `search_library` for relevant docs
151
+ - Best practices? → `get_documentation` for concept guides
152
+
153
+ ### Common pitfalls
154
+ ❌ Skipping validation
155
+ ❌ Guessing component fields instead of using `get_component_schema`
156
+ ❌ Undefined variables
157
+ ❌ Missing authentication
158
+ ❌ Hardcoding secrets instead of `${ENV_VAR}`
159
+
160
+ ### Respect Virtual Environments
161
+
162
+ The user is likely running in a virtual environment. The `qtype` executable may not be in your default `path`.
163
+
164
+ You may try:
165
+ ```
166
+ uv run qtype
167
+ ```
168
+ If the user is using `uv`
169
+
170
+ or `source .venv/bin/activate` before calling `qtype`.
171
+
172
+
173
+ ## Response format
174
+
175
+ 0. **High-level plan** - Briefly state which components you've chosen and why they fit the user's requirements based on [references/patterns.md](references/patterns.md) and the components listed in the mcp server.
176
+ 1. **Brief explanation** (what it does, how data flows)
177
+ 2. **Complete validated YAML** (with comments)
178
+ 3. **Visualization** (for complex flows)
179
+ 4. **Next steps** (`qtype validate`, `qtype run`, `qtype serve`)
180
+
181
+ ## When NOT to use QType
182
+
183
+ QType doesn't fit:
184
+ - Complex conditional branching (use Python)
185
+ - Pure data pipelines without AI (use Dagster/Airflow)
186
+ - Simple API calls (use SDKs directly)
187
+
188
+ Be honest if QType isn't the right tool.
@@ -0,0 +1,198 @@
1
+ # Cheatsheet
2
+
3
+ ## Abbreviated Shape Reference
4
+
5
+ ### Application (Root Object)
6
+ ```yaml
7
+ id: <string> # REQUIRED
8
+ flows: [<Flow>] # REQUIRED (at least one)
9
+ models: [<Model>] # OPTIONAL
10
+ tools: [<Tool>] # OPTIONAL
11
+ types: [<CustomType>] # OPTIONAL
12
+ ```
13
+
14
+ ### Flow
15
+ ```yaml
16
+ type: Flow
17
+ id: <string> # REQUIRED
18
+ steps: [<Step>] # REQUIRED (at least one)
19
+ variables: [<Variable>] # OPTIONAL
20
+ inputs: [<string>] # OPTIONAL (Variable IDs)
21
+ outputs: [<string>] # OPTIONAL (Variable IDs)
22
+ interface: # OPTIONAL
23
+ type: <chat|form|agent>
24
+ ```
25
+
26
+ ### Variable
27
+ ```yaml
28
+ type: Variable
29
+ id: <string> # REQUIRED
30
+ value_type: <type> # REQUIRED (see Type Reference)
31
+ ui: # OPTIONAL
32
+ type: <text-input|text-area|...>
33
+ label: <string>
34
+ ```
35
+
36
+ **Type Reference:**
37
+ - Primitives: `string`, `int`, `float`, `bool`
38
+ - Collections: `list`, `dict`
39
+ - Built-ins: `ChatMessage`, `Document`, `Embedding`
40
+ - Custom: Any CustomType `id`
41
+ - List syntax: `value_type: list` + `item_type: <type>`
42
+
43
+ ### Model
44
+ ```yaml
45
+ type: Model
46
+ id: <string> # REQUIRED
47
+ provider: <bedrock|openai|anthropic> # REQUIRED
48
+ model_id: <string> # REQUIRED
49
+ auth: <string> # OPTIONAL (AuthProvider ID)
50
+ ```
51
+
52
+ ### CustomType
53
+ ```yaml
54
+ id: <string> # REQUIRED
55
+ fields: # REQUIRED (at least one)
56
+ - name: <string> # REQUIRED
57
+ field_type: <type> # REQUIRED
58
+ - name: <string>
59
+ field_type: list[<type>]
60
+ ```
61
+
62
+ ---
63
+
64
+ ## Abbreviated Step Reference
65
+
66
+ ### LLMInference
67
+ ```yaml
68
+ type: LLMInference
69
+ id: <string> # REQUIRED
70
+ model: <string> # REQUIRED (Model ID)
71
+ inputs: [<string>] # OPTIONAL (Variable IDs)
72
+ outputs: [<string>] # OPTIONAL (Variable IDs)
73
+ system_message: <string> # OPTIONAL
74
+ memory: <string> # OPTIONAL (Variable ID for chat history)
75
+ ```
76
+
77
+ ### Agent
78
+ ```yaml
79
+ type: Agent
80
+ id: <string> # REQUIRED
81
+ model: <string> # REQUIRED (Model ID)
82
+ tools: [<string>] # REQUIRED (Tool IDs)
83
+ inputs: [<string>] # OPTIONAL
84
+ outputs: [<string>] # OPTIONAL
85
+ system_message: <string> # OPTIONAL
86
+ ```
87
+
88
+ ### PromptTemplate
89
+ ```yaml
90
+ type: PromptTemplate
91
+ id: <string> # REQUIRED
92
+ template: <string> # REQUIRED (use {{var_id}} syntax)
93
+ inputs: [<string>] # REQUIRED (Variable IDs to interpolate)
94
+ outputs: [<string>] # REQUIRED (single Variable ID)
95
+ ```
96
+
97
+ ### InvokeFlow
98
+ ```yaml
99
+ type: InvokeFlow
100
+ id: <string> # REQUIRED
101
+ flow: <string> # REQUIRED (Flow ID)
102
+ input_bindings: # REQUIRED (even if empty: {})
103
+ <flow_input_id>: <local_var_id>
104
+ output_bindings: # REQUIRED (even if empty: {})
105
+ <local_var_id>: <flow_output_id>
106
+ ```
107
+
108
+ ### InvokeTool
109
+ ```yaml
110
+ type: InvokeTool
111
+ id: <string> # REQUIRED
112
+ tool: <string> # REQUIRED (Tool ID)
113
+ input_bindings: # REQUIRED
114
+ <tool_param>: <local_var_id>
115
+ output_bindings: # REQUIRED
116
+ <tool_output>: <local_var_id>
117
+ ```
118
+
119
+ ### Decoder
120
+ ```yaml
121
+ type: Decoder
122
+ id: <string> # REQUIRED
123
+ format: <json|xml> # REQUIRED
124
+ inputs: [<string>] # REQUIRED (single Variable ID with text)
125
+ outputs: [<string>] # REQUIRED (single Variable ID)
126
+ ```
127
+
128
+ ### Construct
129
+ ```yaml
130
+ type: Construct
131
+ id: <string> # REQUIRED
132
+ output_type: <string> # REQUIRED (CustomType ID)
133
+ field_bindings: # REQUIRED
134
+ <field_name>: <var_id>
135
+ outputs: [<string>] # REQUIRED (single Variable ID)
136
+ ```
137
+
138
+ ### VectorSearch
139
+ ```yaml
140
+ type: VectorSearch
141
+ id: <string> # REQUIRED
142
+ index: <string> # REQUIRED (DocumentIndex ID)
143
+ inputs: [<string>] # REQUIRED (query Variable ID)
144
+ outputs: [<string>] # REQUIRED (results Variable ID)
145
+ top_k: <int> # OPTIONAL (default: 5)
146
+ ```
147
+
148
+ ### Explode
149
+ ```yaml
150
+ type: Explode
151
+ id: <string> # REQUIRED
152
+ inputs: [<string>] # REQUIRED (list Variable ID)
153
+ outputs: [<string>] # REQUIRED (single item Variable ID)
154
+ ```
155
+
156
+ ### FileSource
157
+ ```yaml
158
+ type: FileSource
159
+ id: <string> # REQUIRED
160
+ path: <string> # REQUIRED
161
+ outputs: [<string>] # REQUIRED (Variable ID)
162
+ ```
163
+
164
+ ## Critical Rules
165
+
166
+ ### ID Rules
167
+ - All `id` fields must be unique within their scope
168
+ - IDs must be valid identifiers (alphanumeric + underscore/hyphen)
169
+ - Reference other objects by their exact `id` string
170
+
171
+ ### Variable Rules
172
+ - Variables in `inputs`/`outputs` must be defined in `variables` list
173
+ - Variables must have `value_type` specified
174
+ - List variables REQUIRE `item_type` field
175
+ - Variable types must match their usage in steps
176
+
177
+ ### Step Rules
178
+ - Steps execute in order within `steps` array
179
+ - Step `inputs` must reference existing variables (from previous steps or flow inputs)
180
+ - Step `outputs` create or update variables for subsequent steps
181
+ - All referenced Model/Tool/Flow/CustomType IDs must exist
182
+
183
+ ### Binding Rules
184
+ - `input_bindings`: Map local variables TO external inputs
185
+ - Format: `{external_input_name: local_variable_id}`
186
+ - `output_bindings`: Map external outputs TO local variables
187
+ - Format: `{local_variable_id: external_output_name}`
188
+ - Both must be present even if empty: `{}`
189
+
190
+ ### Template Rules
191
+ - Use `{{variable_id}}` syntax only
192
+ - All variables in template must be in `inputs` list
193
+ - Template must be a single string (use `\n` for newlines)
194
+
195
+ ### Type Rules
196
+ - Decoder outputs must match expected structure
197
+ - Construct `field_bindings` must map to all required CustomType fields
198
+ - List operations (Explode/Collect) require matching list types