aiqtoolkit 1.1.0a20250516__py3-none-any.whl → 1.1.0a20251020__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.

Potentially problematic release.


This version of aiqtoolkit might be problematic. Click here for more details.

Files changed (319) hide show
  1. aiqtoolkit-1.1.0a20251020.dist-info/METADATA +37 -0
  2. aiqtoolkit-1.1.0a20251020.dist-info/RECORD +4 -0
  3. {aiqtoolkit-1.1.0a20250516.dist-info → aiqtoolkit-1.1.0a20251020.dist-info}/WHEEL +1 -1
  4. aiqtoolkit-1.1.0a20251020.dist-info/top_level.txt +1 -0
  5. aiq/agent/__init__.py +0 -0
  6. aiq/agent/base.py +0 -76
  7. aiq/agent/dual_node.py +0 -67
  8. aiq/agent/react_agent/__init__.py +0 -0
  9. aiq/agent/react_agent/agent.py +0 -322
  10. aiq/agent/react_agent/output_parser.py +0 -104
  11. aiq/agent/react_agent/prompt.py +0 -46
  12. aiq/agent/react_agent/register.py +0 -148
  13. aiq/agent/reasoning_agent/__init__.py +0 -0
  14. aiq/agent/reasoning_agent/reasoning_agent.py +0 -224
  15. aiq/agent/register.py +0 -23
  16. aiq/agent/rewoo_agent/__init__.py +0 -0
  17. aiq/agent/rewoo_agent/agent.py +0 -410
  18. aiq/agent/rewoo_agent/prompt.py +0 -108
  19. aiq/agent/rewoo_agent/register.py +0 -158
  20. aiq/agent/tool_calling_agent/__init__.py +0 -0
  21. aiq/agent/tool_calling_agent/agent.py +0 -123
  22. aiq/agent/tool_calling_agent/register.py +0 -105
  23. aiq/builder/__init__.py +0 -0
  24. aiq/builder/builder.py +0 -223
  25. aiq/builder/component_utils.py +0 -303
  26. aiq/builder/context.py +0 -227
  27. aiq/builder/embedder.py +0 -24
  28. aiq/builder/eval_builder.py +0 -120
  29. aiq/builder/evaluator.py +0 -29
  30. aiq/builder/framework_enum.py +0 -24
  31. aiq/builder/front_end.py +0 -73
  32. aiq/builder/function.py +0 -297
  33. aiq/builder/function_base.py +0 -376
  34. aiq/builder/function_info.py +0 -627
  35. aiq/builder/intermediate_step_manager.py +0 -176
  36. aiq/builder/llm.py +0 -25
  37. aiq/builder/retriever.py +0 -25
  38. aiq/builder/user_interaction_manager.py +0 -71
  39. aiq/builder/workflow.py +0 -143
  40. aiq/builder/workflow_builder.py +0 -757
  41. aiq/cli/__init__.py +0 -14
  42. aiq/cli/cli_utils/__init__.py +0 -0
  43. aiq/cli/cli_utils/config_override.py +0 -231
  44. aiq/cli/cli_utils/validation.py +0 -37
  45. aiq/cli/commands/__init__.py +0 -0
  46. aiq/cli/commands/configure/__init__.py +0 -0
  47. aiq/cli/commands/configure/channel/__init__.py +0 -0
  48. aiq/cli/commands/configure/channel/add.py +0 -28
  49. aiq/cli/commands/configure/channel/channel.py +0 -36
  50. aiq/cli/commands/configure/channel/remove.py +0 -30
  51. aiq/cli/commands/configure/channel/update.py +0 -30
  52. aiq/cli/commands/configure/configure.py +0 -33
  53. aiq/cli/commands/evaluate.py +0 -139
  54. aiq/cli/commands/info/__init__.py +0 -14
  55. aiq/cli/commands/info/info.py +0 -39
  56. aiq/cli/commands/info/list_channels.py +0 -32
  57. aiq/cli/commands/info/list_components.py +0 -129
  58. aiq/cli/commands/info/list_mcp.py +0 -126
  59. aiq/cli/commands/registry/__init__.py +0 -14
  60. aiq/cli/commands/registry/publish.py +0 -88
  61. aiq/cli/commands/registry/pull.py +0 -118
  62. aiq/cli/commands/registry/registry.py +0 -38
  63. aiq/cli/commands/registry/remove.py +0 -108
  64. aiq/cli/commands/registry/search.py +0 -155
  65. aiq/cli/commands/start.py +0 -250
  66. aiq/cli/commands/uninstall.py +0 -83
  67. aiq/cli/commands/validate.py +0 -47
  68. aiq/cli/commands/workflow/__init__.py +0 -14
  69. aiq/cli/commands/workflow/templates/__init__.py.j2 +0 -0
  70. aiq/cli/commands/workflow/templates/config.yml.j2 +0 -16
  71. aiq/cli/commands/workflow/templates/pyproject.toml.j2 +0 -22
  72. aiq/cli/commands/workflow/templates/register.py.j2 +0 -5
  73. aiq/cli/commands/workflow/templates/workflow.py.j2 +0 -36
  74. aiq/cli/commands/workflow/workflow.py +0 -37
  75. aiq/cli/commands/workflow/workflow_commands.py +0 -313
  76. aiq/cli/entrypoint.py +0 -133
  77. aiq/cli/main.py +0 -44
  78. aiq/cli/register_workflow.py +0 -408
  79. aiq/cli/type_registry.py +0 -879
  80. aiq/data_models/__init__.py +0 -14
  81. aiq/data_models/api_server.py +0 -588
  82. aiq/data_models/common.py +0 -143
  83. aiq/data_models/component.py +0 -46
  84. aiq/data_models/component_ref.py +0 -135
  85. aiq/data_models/config.py +0 -349
  86. aiq/data_models/dataset_handler.py +0 -122
  87. aiq/data_models/discovery_metadata.py +0 -286
  88. aiq/data_models/embedder.py +0 -26
  89. aiq/data_models/evaluate.py +0 -104
  90. aiq/data_models/evaluator.py +0 -26
  91. aiq/data_models/front_end.py +0 -26
  92. aiq/data_models/function.py +0 -30
  93. aiq/data_models/function_dependencies.py +0 -64
  94. aiq/data_models/interactive.py +0 -237
  95. aiq/data_models/intermediate_step.py +0 -269
  96. aiq/data_models/invocation_node.py +0 -38
  97. aiq/data_models/llm.py +0 -26
  98. aiq/data_models/logging.py +0 -26
  99. aiq/data_models/memory.py +0 -26
  100. aiq/data_models/profiler.py +0 -53
  101. aiq/data_models/registry_handler.py +0 -26
  102. aiq/data_models/retriever.py +0 -30
  103. aiq/data_models/step_adaptor.py +0 -64
  104. aiq/data_models/streaming.py +0 -33
  105. aiq/data_models/swe_bench_model.py +0 -54
  106. aiq/data_models/telemetry_exporter.py +0 -26
  107. aiq/embedder/__init__.py +0 -0
  108. aiq/embedder/langchain_client.py +0 -41
  109. aiq/embedder/nim_embedder.py +0 -58
  110. aiq/embedder/openai_embedder.py +0 -42
  111. aiq/embedder/register.py +0 -24
  112. aiq/eval/__init__.py +0 -14
  113. aiq/eval/config.py +0 -42
  114. aiq/eval/dataset_handler/__init__.py +0 -0
  115. aiq/eval/dataset_handler/dataset_downloader.py +0 -106
  116. aiq/eval/dataset_handler/dataset_filter.py +0 -52
  117. aiq/eval/dataset_handler/dataset_handler.py +0 -169
  118. aiq/eval/evaluate.py +0 -325
  119. aiq/eval/evaluator/__init__.py +0 -14
  120. aiq/eval/evaluator/evaluator_model.py +0 -44
  121. aiq/eval/intermediate_step_adapter.py +0 -93
  122. aiq/eval/rag_evaluator/__init__.py +0 -0
  123. aiq/eval/rag_evaluator/evaluate.py +0 -138
  124. aiq/eval/rag_evaluator/register.py +0 -138
  125. aiq/eval/register.py +0 -23
  126. aiq/eval/remote_workflow.py +0 -128
  127. aiq/eval/runtime_event_subscriber.py +0 -52
  128. aiq/eval/swe_bench_evaluator/__init__.py +0 -0
  129. aiq/eval/swe_bench_evaluator/evaluate.py +0 -215
  130. aiq/eval/swe_bench_evaluator/register.py +0 -36
  131. aiq/eval/trajectory_evaluator/__init__.py +0 -0
  132. aiq/eval/trajectory_evaluator/evaluate.py +0 -118
  133. aiq/eval/trajectory_evaluator/register.py +0 -40
  134. aiq/eval/tunable_rag_evaluator/__init__.py +0 -0
  135. aiq/eval/tunable_rag_evaluator/evaluate.py +0 -263
  136. aiq/eval/tunable_rag_evaluator/register.py +0 -50
  137. aiq/eval/utils/__init__.py +0 -0
  138. aiq/eval/utils/output_uploader.py +0 -131
  139. aiq/eval/utils/tqdm_position_registry.py +0 -40
  140. aiq/front_ends/__init__.py +0 -14
  141. aiq/front_ends/console/__init__.py +0 -14
  142. aiq/front_ends/console/console_front_end_config.py +0 -32
  143. aiq/front_ends/console/console_front_end_plugin.py +0 -107
  144. aiq/front_ends/console/register.py +0 -25
  145. aiq/front_ends/cron/__init__.py +0 -14
  146. aiq/front_ends/fastapi/__init__.py +0 -14
  147. aiq/front_ends/fastapi/fastapi_front_end_config.py +0 -150
  148. aiq/front_ends/fastapi/fastapi_front_end_plugin.py +0 -103
  149. aiq/front_ends/fastapi/fastapi_front_end_plugin_worker.py +0 -607
  150. aiq/front_ends/fastapi/intermediate_steps_subscriber.py +0 -80
  151. aiq/front_ends/fastapi/job_store.py +0 -161
  152. aiq/front_ends/fastapi/main.py +0 -70
  153. aiq/front_ends/fastapi/message_handler.py +0 -279
  154. aiq/front_ends/fastapi/message_validator.py +0 -345
  155. aiq/front_ends/fastapi/register.py +0 -25
  156. aiq/front_ends/fastapi/response_helpers.py +0 -195
  157. aiq/front_ends/fastapi/step_adaptor.py +0 -320
  158. aiq/front_ends/fastapi/websocket.py +0 -148
  159. aiq/front_ends/mcp/__init__.py +0 -14
  160. aiq/front_ends/mcp/mcp_front_end_config.py +0 -32
  161. aiq/front_ends/mcp/mcp_front_end_plugin.py +0 -93
  162. aiq/front_ends/mcp/register.py +0 -27
  163. aiq/front_ends/mcp/tool_converter.py +0 -242
  164. aiq/front_ends/register.py +0 -22
  165. aiq/front_ends/simple_base/__init__.py +0 -14
  166. aiq/front_ends/simple_base/simple_front_end_plugin_base.py +0 -52
  167. aiq/llm/__init__.py +0 -0
  168. aiq/llm/nim_llm.py +0 -45
  169. aiq/llm/openai_llm.py +0 -45
  170. aiq/llm/register.py +0 -22
  171. aiq/llm/utils/__init__.py +0 -14
  172. aiq/llm/utils/env_config_value.py +0 -94
  173. aiq/llm/utils/error.py +0 -17
  174. aiq/memory/__init__.py +0 -20
  175. aiq/memory/interfaces.py +0 -183
  176. aiq/memory/models.py +0 -112
  177. aiq/meta/module_to_distro.json +0 -3
  178. aiq/meta/pypi.md +0 -58
  179. aiq/observability/__init__.py +0 -0
  180. aiq/observability/async_otel_listener.py +0 -429
  181. aiq/observability/register.py +0 -99
  182. aiq/plugins/.namespace +0 -1
  183. aiq/profiler/__init__.py +0 -0
  184. aiq/profiler/callbacks/__init__.py +0 -0
  185. aiq/profiler/callbacks/agno_callback_handler.py +0 -295
  186. aiq/profiler/callbacks/base_callback_class.py +0 -20
  187. aiq/profiler/callbacks/langchain_callback_handler.py +0 -278
  188. aiq/profiler/callbacks/llama_index_callback_handler.py +0 -205
  189. aiq/profiler/callbacks/semantic_kernel_callback_handler.py +0 -238
  190. aiq/profiler/callbacks/token_usage_base_model.py +0 -27
  191. aiq/profiler/data_frame_row.py +0 -51
  192. aiq/profiler/decorators/__init__.py +0 -0
  193. aiq/profiler/decorators/framework_wrapper.py +0 -131
  194. aiq/profiler/decorators/function_tracking.py +0 -254
  195. aiq/profiler/forecasting/__init__.py +0 -0
  196. aiq/profiler/forecasting/config.py +0 -18
  197. aiq/profiler/forecasting/model_trainer.py +0 -75
  198. aiq/profiler/forecasting/models/__init__.py +0 -22
  199. aiq/profiler/forecasting/models/forecasting_base_model.py +0 -40
  200. aiq/profiler/forecasting/models/linear_model.py +0 -196
  201. aiq/profiler/forecasting/models/random_forest_regressor.py +0 -268
  202. aiq/profiler/inference_metrics_model.py +0 -25
  203. aiq/profiler/inference_optimization/__init__.py +0 -0
  204. aiq/profiler/inference_optimization/bottleneck_analysis/__init__.py +0 -0
  205. aiq/profiler/inference_optimization/bottleneck_analysis/nested_stack_analysis.py +0 -452
  206. aiq/profiler/inference_optimization/bottleneck_analysis/simple_stack_analysis.py +0 -258
  207. aiq/profiler/inference_optimization/data_models.py +0 -386
  208. aiq/profiler/inference_optimization/experimental/__init__.py +0 -0
  209. aiq/profiler/inference_optimization/experimental/concurrency_spike_analysis.py +0 -468
  210. aiq/profiler/inference_optimization/experimental/prefix_span_analysis.py +0 -405
  211. aiq/profiler/inference_optimization/llm_metrics.py +0 -212
  212. aiq/profiler/inference_optimization/prompt_caching.py +0 -163
  213. aiq/profiler/inference_optimization/token_uniqueness.py +0 -107
  214. aiq/profiler/inference_optimization/workflow_runtimes.py +0 -72
  215. aiq/profiler/intermediate_property_adapter.py +0 -102
  216. aiq/profiler/profile_runner.py +0 -433
  217. aiq/profiler/utils.py +0 -184
  218. aiq/registry_handlers/__init__.py +0 -0
  219. aiq/registry_handlers/local/__init__.py +0 -0
  220. aiq/registry_handlers/local/local_handler.py +0 -176
  221. aiq/registry_handlers/local/register_local.py +0 -37
  222. aiq/registry_handlers/metadata_factory.py +0 -60
  223. aiq/registry_handlers/package_utils.py +0 -198
  224. aiq/registry_handlers/pypi/__init__.py +0 -0
  225. aiq/registry_handlers/pypi/pypi_handler.py +0 -251
  226. aiq/registry_handlers/pypi/register_pypi.py +0 -40
  227. aiq/registry_handlers/register.py +0 -21
  228. aiq/registry_handlers/registry_handler_base.py +0 -157
  229. aiq/registry_handlers/rest/__init__.py +0 -0
  230. aiq/registry_handlers/rest/register_rest.py +0 -56
  231. aiq/registry_handlers/rest/rest_handler.py +0 -237
  232. aiq/registry_handlers/schemas/__init__.py +0 -0
  233. aiq/registry_handlers/schemas/headers.py +0 -42
  234. aiq/registry_handlers/schemas/package.py +0 -68
  235. aiq/registry_handlers/schemas/publish.py +0 -63
  236. aiq/registry_handlers/schemas/pull.py +0 -82
  237. aiq/registry_handlers/schemas/remove.py +0 -36
  238. aiq/registry_handlers/schemas/search.py +0 -91
  239. aiq/registry_handlers/schemas/status.py +0 -47
  240. aiq/retriever/__init__.py +0 -0
  241. aiq/retriever/interface.py +0 -37
  242. aiq/retriever/milvus/__init__.py +0 -14
  243. aiq/retriever/milvus/register.py +0 -81
  244. aiq/retriever/milvus/retriever.py +0 -228
  245. aiq/retriever/models.py +0 -74
  246. aiq/retriever/nemo_retriever/__init__.py +0 -14
  247. aiq/retriever/nemo_retriever/register.py +0 -60
  248. aiq/retriever/nemo_retriever/retriever.py +0 -190
  249. aiq/retriever/register.py +0 -22
  250. aiq/runtime/__init__.py +0 -14
  251. aiq/runtime/loader.py +0 -188
  252. aiq/runtime/runner.py +0 -176
  253. aiq/runtime/session.py +0 -140
  254. aiq/runtime/user_metadata.py +0 -131
  255. aiq/settings/__init__.py +0 -0
  256. aiq/settings/global_settings.py +0 -318
  257. aiq/test/.namespace +0 -1
  258. aiq/tool/__init__.py +0 -0
  259. aiq/tool/code_execution/__init__.py +0 -0
  260. aiq/tool/code_execution/code_sandbox.py +0 -188
  261. aiq/tool/code_execution/local_sandbox/Dockerfile.sandbox +0 -60
  262. aiq/tool/code_execution/local_sandbox/__init__.py +0 -13
  263. aiq/tool/code_execution/local_sandbox/local_sandbox_server.py +0 -83
  264. aiq/tool/code_execution/local_sandbox/sandbox.requirements.txt +0 -4
  265. aiq/tool/code_execution/local_sandbox/start_local_sandbox.sh +0 -25
  266. aiq/tool/code_execution/register.py +0 -70
  267. aiq/tool/code_execution/utils.py +0 -100
  268. aiq/tool/datetime_tools.py +0 -42
  269. aiq/tool/document_search.py +0 -141
  270. aiq/tool/github_tools/__init__.py +0 -0
  271. aiq/tool/github_tools/create_github_commit.py +0 -133
  272. aiq/tool/github_tools/create_github_issue.py +0 -87
  273. aiq/tool/github_tools/create_github_pr.py +0 -106
  274. aiq/tool/github_tools/get_github_file.py +0 -106
  275. aiq/tool/github_tools/get_github_issue.py +0 -166
  276. aiq/tool/github_tools/get_github_pr.py +0 -256
  277. aiq/tool/github_tools/update_github_issue.py +0 -100
  278. aiq/tool/mcp/__init__.py +0 -14
  279. aiq/tool/mcp/mcp_client.py +0 -220
  280. aiq/tool/mcp/mcp_tool.py +0 -95
  281. aiq/tool/memory_tools/__init__.py +0 -0
  282. aiq/tool/memory_tools/add_memory_tool.py +0 -79
  283. aiq/tool/memory_tools/delete_memory_tool.py +0 -67
  284. aiq/tool/memory_tools/get_memory_tool.py +0 -72
  285. aiq/tool/nvidia_rag.py +0 -95
  286. aiq/tool/register.py +0 -37
  287. aiq/tool/retriever.py +0 -89
  288. aiq/tool/server_tools.py +0 -63
  289. aiq/utils/__init__.py +0 -0
  290. aiq/utils/data_models/__init__.py +0 -0
  291. aiq/utils/data_models/schema_validator.py +0 -58
  292. aiq/utils/debugging_utils.py +0 -43
  293. aiq/utils/exception_handlers/__init__.py +0 -0
  294. aiq/utils/exception_handlers/schemas.py +0 -114
  295. aiq/utils/io/__init__.py +0 -0
  296. aiq/utils/io/yaml_tools.py +0 -119
  297. aiq/utils/metadata_utils.py +0 -74
  298. aiq/utils/optional_imports.py +0 -142
  299. aiq/utils/producer_consumer_queue.py +0 -178
  300. aiq/utils/reactive/__init__.py +0 -0
  301. aiq/utils/reactive/base/__init__.py +0 -0
  302. aiq/utils/reactive/base/observable_base.py +0 -65
  303. aiq/utils/reactive/base/observer_base.py +0 -55
  304. aiq/utils/reactive/base/subject_base.py +0 -79
  305. aiq/utils/reactive/observable.py +0 -59
  306. aiq/utils/reactive/observer.py +0 -76
  307. aiq/utils/reactive/subject.py +0 -131
  308. aiq/utils/reactive/subscription.py +0 -49
  309. aiq/utils/settings/__init__.py +0 -0
  310. aiq/utils/settings/global_settings.py +0 -197
  311. aiq/utils/type_converter.py +0 -232
  312. aiq/utils/type_utils.py +0 -397
  313. aiq/utils/url_utils.py +0 -27
  314. aiqtoolkit-1.1.0a20250516.dist-info/METADATA +0 -331
  315. aiqtoolkit-1.1.0a20250516.dist-info/RECORD +0 -316
  316. aiqtoolkit-1.1.0a20250516.dist-info/entry_points.txt +0 -17
  317. aiqtoolkit-1.1.0a20250516.dist-info/licenses/LICENSE-3rd-party.txt +0 -3686
  318. aiqtoolkit-1.1.0a20250516.dist-info/licenses/LICENSE.md +0 -201
  319. aiqtoolkit-1.1.0a20250516.dist-info/top_level.txt +0 -1
@@ -1,452 +0,0 @@
1
- # SPDX-FileCopyrightText: Copyright (c) 2025, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2
- # SPDX-License-Identifier: Apache-2.0
3
- #
4
- # Licensed under the Apache License, Version 2.0 (the "License");
5
- # you may not use this file except in compliance with the License.
6
- # You may obtain a copy of the License at
7
- #
8
- # http://www.apache.org/licenses/LICENSE-2.0
9
- #
10
- # Unless required by applicable law or agreed to in writing, software
11
- # distributed under the License is distributed on an "AS IS" BASIS,
12
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- # See the License for the specific language governing permissions and
14
- # limitations under the License.
15
- """
16
- An enhanced script that:
17
-
18
- 1. Groups events by example_number.
19
- 2. Builds a nested call tree (stack-based) for each example_number, so calls from different examples never nest.
20
- 3. Combines all calls into one global list for concurrency analysis.
21
- 4. Computes:
22
-
23
- - self_time, subtree_time for each call
24
- - concurrency distribution (p50, p90, p95, p99) across all examples
25
- - each node's midpoint concurrency
26
- - a custom 'bottleneck_score' (here = subtree_time)
27
-
28
- 5. Optionally saves a Gantt chart.
29
- 6. Returns a Pydantic object with concurrency stats, node metrics, top bottlenecks, and a textual report.
30
- """
31
-
32
- import logging
33
- import os
34
-
35
- import pandas as pd
36
-
37
- from aiq.data_models.intermediate_step import IntermediateStep
38
- from aiq.profiler.inference_optimization.data_models import CallNode
39
- from aiq.profiler.inference_optimization.data_models import ConcurrencyDistribution
40
- from aiq.profiler.inference_optimization.data_models import NestedCallProfilingResult
41
- from aiq.profiler.inference_optimization.data_models import NodeMetrics
42
- from aiq.profiler.utils import create_standardized_dataframe
43
-
44
- logger = logging.getLogger(__name__)
45
-
46
- # --------------------------------------------------------------------------------
47
- # 1) Build the Nested Call Tree PER EXAMPLE
48
- # --------------------------------------------------------------------------------
49
-
50
-
51
- def build_call_tree_for_example(example_df: pd.DataFrame) -> list[CallNode]:
52
- """
53
- Stack-based approach for a single example:
54
-
55
- 1. Sort events by timestamp ascending.
56
- 2. On `*_START` => push a new node, attach to parent's children if stack not empty.
57
- 3. On `*_END` => pop from stack if matches the top's UUID, finalize end_time/duration.
58
-
59
- Returns:
60
- A list of top-level calls for this example.
61
- """
62
- stack: list[CallNode] = []
63
- top_level_dict: dict[str, CallNode] = {}
64
- partial_map: dict[str, CallNode] = {}
65
-
66
- def parse_op_type(evt: str) -> str | None:
67
- evt = evt.upper()
68
- if evt.startswith("LLM_"):
69
- return "LLM"
70
- if evt.startswith("TOOL_"):
71
- return "TOOL"
72
- return None
73
-
74
- def get_op_name(row: pd.Series, op_type: str) -> str:
75
- if op_type == "LLM":
76
- return row.get("llm_name") or "unknown_llm"
77
- if op_type == "TOOL":
78
- return row.get("tool_name") or "unknown_tool"
79
- return "unknown_op"
80
-
81
- for _, row in example_df.iterrows():
82
- et = row["event_type"].value.upper()
83
- uuid = str(row["UUID"])
84
- ts = float(row["event_timestamp"])
85
-
86
- op_type = parse_op_type(et)
87
- if not op_type:
88
- # not an LLM_/TOOL_ event => skip
89
- continue
90
-
91
- if et.endswith("_START"):
92
- name = get_op_name(row, op_type)
93
- node = CallNode(uuid=uuid,
94
- operation_type=op_type,
95
- operation_name=name,
96
- start_time=ts,
97
- end_time=ts,
98
- duration=0.0,
99
- children=[],
100
- parent=None)
101
- if stack:
102
- parent = stack[-1]
103
- node.parent = parent
104
- parent.children.append(node)
105
- else:
106
- # top-level
107
- top_level_dict[uuid] = node
108
-
109
- stack.append(node)
110
- partial_map[uuid] = node
111
-
112
- elif et.endswith("_END"):
113
- if uuid not in partial_map:
114
- # no known start => skip
115
- continue
116
- node = partial_map[uuid]
117
- if stack and stack[-1].uuid == uuid:
118
- stack.pop()
119
-
120
- node.end_time = ts
121
- node.duration = max(0.0, ts - node.start_time)
122
- del partial_map[uuid]
123
-
124
- # partial calls remain in stack => they have no final end_time
125
- # we won't forcibly remove them
126
-
127
- # collect top-level nodes
128
- roots = []
129
- for _, node in top_level_dict.items():
130
- if node.parent is None:
131
- roots.append(node)
132
-
133
- return roots
134
-
135
-
136
- def build_call_tree_per_example(all_steps: list[list[IntermediateStep]]) -> list[CallNode]:
137
- """
138
- 1) Group the DataFrame by example_number.
139
- 2) For each example, build a separate stack-based call tree.
140
- 3) Return a combined list of all top-level calls from all examples.
141
-
142
- This ensures no cross-example nesting.
143
- """
144
- df = create_standardized_dataframe(all_steps)
145
- required = {"example_number", "event_type", "UUID", "event_timestamp"}
146
- missing = required - set(df.columns)
147
- if missing:
148
- raise ValueError(f"DataFrame missing required columns: {missing}")
149
-
150
- # Sort globally first (so each example is also in ascending time)
151
- dfc = df.copy()
152
- dfc.sort_values(["example_number", "event_timestamp"], inplace=True)
153
-
154
- # We'll collect top-level calls for each example
155
- all_roots: list[CallNode] = []
156
-
157
- for _, group_df in dfc.groupby("example_number"):
158
- # Build the call tree for this single example
159
- # group_df is already sorted within this example
160
- roots_for_example = build_call_tree_for_example(group_df)
161
- all_roots.extend(roots_for_example)
162
-
163
- return all_roots
164
-
165
-
166
- # --------------------------------------------------------------------------------
167
- # 2) Concurrency Computation
168
- # --------------------------------------------------------------------------------
169
-
170
-
171
- def compute_time_based_concurrency(roots: list[CallNode]) -> ConcurrencyDistribution:
172
- """
173
- Build a timeline of (start, +1), (end, -1) from all calls, then:
174
- - Sort events by time
175
- - Create segments [ (t_i, t_{i+1}, concurrency) ]
176
- - Compute concurrency percentiles (p50, p90, p95, p99) based on total time spent at each concurrency.
177
- - This concurrency is across ALL calls from ALL examples.
178
-
179
- Returns:
180
- --------
181
- ConcurrencyDistribution
182
- with the piecewise segments + concurrency percentiles.
183
- """
184
- # Flatten
185
- all_nodes = []
186
-
187
- def dfs(n: CallNode):
188
- all_nodes.append(n)
189
- for c in n.children:
190
- dfs(c)
191
-
192
- for r in roots:
193
- dfs(r)
194
-
195
- if not all_nodes:
196
- return ConcurrencyDistribution(timeline_segments=[], p50=0, p90=0, p95=0, p99=0)
197
-
198
- events = []
199
- for n in all_nodes:
200
- st = n.start_time
201
- et = n.end_time
202
- if st > et:
203
- # partial or invalid => skip
204
- continue
205
- events.append((st, +1))
206
- events.append((et, -1))
207
-
208
- events.sort(key=lambda x: x[0])
209
- timeline_segments: list[tuple[float, float, int]] = []
210
- curr_concurrency = 0
211
- prev_time = events[0][0]
212
-
213
- for _, (t, delta) in enumerate(events):
214
- if t > prev_time:
215
- # segment is [prev_time, t) at concurrency=curr_concurrency
216
- timeline_segments.append((prev_time, t, curr_concurrency))
217
- curr_concurrency += delta
218
- prev_time = t
219
-
220
- # Summaries
221
- total_time = 0.0
222
- concurrency_durations: dict[int, float] = {}
223
-
224
- for (seg_start, seg_end, c_val) in timeline_segments:
225
- length = seg_end - seg_start
226
- if length <= 0:
227
- continue
228
- total_time += length
229
- concurrency_durations[c_val] = concurrency_durations.get(c_val, 0) + length
230
-
231
- if total_time <= 0:
232
- return ConcurrencyDistribution(timeline_segments=timeline_segments, p50=0, p90=0, p95=0, p99=0)
233
-
234
- # Build concurrency-level distribution
235
- sorted_levels = sorted(concurrency_durations.items(), key=lambda x: x[0]) # ascending concurrency
236
-
237
- def concurrency_at_percentile(p: float) -> float:
238
- threshold = total_time * (p / 100.0)
239
- accum = 0.0
240
- last_c = 0
241
- for c_val, c_dur in sorted_levels:
242
- accum += c_dur
243
- if accum >= threshold:
244
- return float(c_val)
245
- last_c = c_val
246
- return float(last_c)
247
-
248
- p50_val = concurrency_at_percentile(50)
249
- p90_val = concurrency_at_percentile(90)
250
- p95_val = concurrency_at_percentile(95)
251
- p99_val = concurrency_at_percentile(99)
252
-
253
- return ConcurrencyDistribution(timeline_segments=timeline_segments,
254
- p50=p50_val,
255
- p90=p90_val,
256
- p95=p95_val,
257
- p99=p99_val)
258
-
259
-
260
- def find_midpoint_concurrency(node: CallNode, segments: list[tuple[float, float, int]]) -> float:
261
- """
262
- Approximate concurrency for a node by finding the concurrency in timeline_segments
263
- at the node's midpoint (or start if zero-length).
264
- """
265
- if node.start_time >= node.end_time:
266
- mid = node.start_time
267
- else:
268
- mid = 0.5 * (node.start_time + node.end_time)
269
-
270
- # Binary search in segments
271
- left, right = 0, len(segments) - 1
272
- while left <= right:
273
- mid_idx = (left + right) // 2
274
- seg_start, seg_end, seg_conc = segments[mid_idx]
275
- if seg_start <= mid < seg_end:
276
- return float(seg_conc)
277
- if mid < seg_start:
278
- right = mid_idx - 1
279
- else:
280
- left = mid_idx + 1
281
- return 0.0
282
-
283
-
284
- # --------------------------------------------------------------------------------
285
- # 3) Gantt Chart
286
- # --------------------------------------------------------------------------------
287
-
288
-
289
- def save_gantt_chart(all_nodes: list[CallNode], output_path: str) -> None:
290
- """
291
- Save a Gantt chart as a PNG, color-coded by operation_type.
292
- Each node is displayed as a horizontal bar from start_time to end_time.
293
- The y-axis is the node index (sorted by start_time).
294
- """
295
-
296
- try:
297
- import matplotlib.pyplot as plt
298
- except ImportError:
299
- logger.error("matplotlib is not installed. Please install matplotlib to use generate plots for the profiler "
300
- "or install `aiq[profiler]` to install all necessary profiling packages.")
301
-
302
- raise
303
-
304
- # Sort calls by start_time
305
- sorted_nodes = sorted(all_nodes, key=lambda x: x.start_time)
306
- min_start = sorted_nodes[0].start_time
307
- max_end = max(node.end_time for node in sorted_nodes)
308
-
309
- color_map = {
310
- "LLM": "tab:blue",
311
- "TOOL": "tab:green",
312
- }
313
- default_color = "tab:gray"
314
-
315
- fig, ax = plt.subplots(figsize=(20, 15))
316
-
317
- y_positions = range(len(sorted_nodes))
318
- labels = []
319
- for i, node in enumerate(sorted_nodes):
320
- start = node.start_time
321
- width = node.end_time - node.start_time
322
- c = color_map.get(node.operation_type, default_color)
323
- ax.barh(y=i, width=width, left=start - min_start, height=0.6, color=c, edgecolor="black")
324
- labels.append(f"{node.operation_type}:{node.operation_name}")
325
-
326
- ax.set_yticks(list(y_positions))
327
- ax.set_yticklabels(labels)
328
- ax.invert_yaxis()
329
- ax.set_xlim(0, max_end - min_start)
330
- ax.set_xlabel("Time")
331
- ax.set_title("Gantt Chart of Nested Calls (All Examples)")
332
- plt.tight_layout()
333
- plt.savefig(output_path, dpi=150)
334
- plt.close(fig)
335
-
336
-
337
- # --------------------------------------------------------------------------------
338
- # 4) Analysis & Final Pydantic Result
339
- # --------------------------------------------------------------------------------
340
-
341
-
342
- def analyze_calls_and_build_result(roots: list[CallNode], output_dir: str | None = None) -> NestedCallProfilingResult:
343
- """
344
- 1. Compute concurrency distribution (p50, p90, p95, p99) across ALL calls in all examples.
345
- 2. For each node, compute self_time, subtree_time, concurrency at midpoint, bottleneck_score.
346
- 3. Identify top 5 bottlenecks (by subtree_time).
347
- 4. Build a textual report.
348
- 5. Optionally save a Gantt chart to 'output_dir'.
349
-
350
- Returns NestedCallProfilingResult.
351
- """
352
- if not roots:
353
- empty_concurrency = ConcurrencyDistribution(timeline_segments=[], p50=0, p90=0, p95=0, p99=0)
354
- return NestedCallProfilingResult(concurrency=empty_concurrency,
355
- node_metrics={},
356
- top_bottlenecks=[],
357
- textual_report="No calls found.")
358
-
359
- # Flatten all calls
360
- all_nodes: list[CallNode] = []
361
-
362
- def dfs(n: CallNode):
363
- all_nodes.append(n)
364
- for c in n.children:
365
- dfs(c)
366
-
367
- for r in roots:
368
- dfs(r)
369
-
370
- # 1) concurrency across all calls
371
- concurrency_info = compute_time_based_concurrency(roots)
372
-
373
- # 2) build NodeMetrics
374
- node_metrics_map: dict[str, NodeMetrics] = {}
375
- for node in all_nodes:
376
- self_t = node.compute_self_time()
377
- subtree_t = node.compute_subtree_time()
378
- bscore = subtree_t
379
- mid_conc = find_midpoint_concurrency(node, concurrency_info.timeline_segments)
380
-
381
- m = NodeMetrics(uuid=node.uuid,
382
- operation_type=node.operation_type,
383
- operation_name=node.operation_name,
384
- start_time=node.start_time,
385
- end_time=node.end_time,
386
- duration=node.duration,
387
- self_time=self_t,
388
- subtree_time=subtree_t,
389
- concurrency_midpoint=mid_conc,
390
- bottleneck_score=bscore)
391
- node_metrics_map[node.uuid] = m
392
-
393
- # 3) top 5
394
- all_metrics = list(node_metrics_map.values())
395
- sorted_metrics = sorted(all_metrics, key=lambda x: x.bottleneck_score, reverse=True)
396
- top_5 = sorted_metrics[:5]
397
-
398
- # 4) textual report
399
- lines = []
400
- lines.append("=== Multi-Example Nested Call Profiling Report ===")
401
- lines.append(f"Total calls (across all examples): {len(all_nodes)}")
402
-
403
- lines.append("\n-- Concurrency Distribution (all examples) --")
404
- lines.append(f"p50={concurrency_info.p50:.1f}, p90={concurrency_info.p90:.1f}, "
405
- f"p95={concurrency_info.p95:.1f}, p99={concurrency_info.p99:.1f}")
406
-
407
- lines.append("\n-- Top 5 Calls by Bottleneck Score (subtree_time) --")
408
- for i, tm in enumerate(top_5, start=1):
409
- lines.append(f"{i}) UUID={tm.uuid}, {tm.operation_type} '{tm.operation_name}', "
410
- f"dur={tm.duration:.2f}, self_time={tm.self_time:.2f}, "
411
- f"subtree_time={tm.subtree_time:.2f}, concurrency={tm.concurrency_midpoint:.1f}, "
412
- f"score={tm.bottleneck_score:.2f}")
413
-
414
- lines.append("\n-- Full Tree(s) (All Examples) --")
415
-
416
- for root in roots:
417
- lines.append(str(root))
418
-
419
- report_text = "\n".join(lines)
420
-
421
- # 5) optional Gantt chart
422
- if output_dir:
423
- os.makedirs(output_dir, exist_ok=True)
424
- chart_path = os.path.join(output_dir, "gantt_chart.png")
425
- save_gantt_chart(all_nodes, chart_path)
426
-
427
- # Return the final Pydantic result
428
- return NestedCallProfilingResult(concurrency=concurrency_info,
429
- node_metrics=node_metrics_map,
430
- top_bottlenecks=top_5,
431
- textual_report=report_text)
432
-
433
-
434
- def multi_example_call_profiling(all_steps: list[list[IntermediateStep]],
435
- output_dir: str | None = None) -> NestedCallProfilingResult:
436
- """
437
- The high-level function:
438
-
439
- 1. Build a forest of calls by grouping by example_number (so no cross-example nesting).
440
- 2. Analyze concurrency across all calls in all examples.
441
- 3. Return a NestedCallProfilingResult with concurrency distribution, node metrics, top bottlenecks, and textual
442
- report. Optionally saves a Gantt chart.
443
-
444
- :param all_steps: Intermediate steps for each example.
445
- :param output_dir: Directory path to save gantt_chart.png (if provided)
446
- :return: NestedCallProfilingResult (pydantic)
447
- """
448
- # Build the forest (all examples combined)
449
- roots = build_call_tree_per_example(all_steps)
450
- # Analyze calls
451
- result = analyze_calls_and_build_result(roots, output_dir=output_dir)
452
- return result