pygeai 0.6.0b7__py3-none-any.whl → 0.6.0b11__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 (178) hide show
  1. pygeai/_docs/source/conf.py +78 -6
  2. pygeai/_docs/source/content/api_reference/embeddings.rst +31 -1
  3. pygeai/_docs/source/content/api_reference/evaluation.rst +590 -0
  4. pygeai/_docs/source/content/api_reference/feedback.rst +237 -0
  5. pygeai/_docs/source/content/api_reference/files.rst +592 -0
  6. pygeai/_docs/source/content/api_reference/gam.rst +401 -0
  7. pygeai/_docs/source/content/api_reference/proxy.rst +318 -0
  8. pygeai/_docs/source/content/api_reference/secrets.rst +495 -0
  9. pygeai/_docs/source/content/api_reference/usage_limits.rst +390 -0
  10. pygeai/_docs/source/content/api_reference.rst +7 -0
  11. pygeai/_docs/source/content/debugger.rst +376 -83
  12. pygeai/_docs/source/content/migration.rst +528 -0
  13. pygeai/_docs/source/content/modules.rst +1 -1
  14. pygeai/_docs/source/pygeai.cli.rst +8 -0
  15. pygeai/_docs/source/pygeai.tests.cli.rst +16 -0
  16. pygeai/_docs/source/pygeai.tests.core.embeddings.rst +16 -0
  17. pygeai/_docs/source/pygeai.tests.snippets.chat.rst +40 -0
  18. pygeai/_docs/source/pygeai.tests.snippets.dbg.rst +45 -0
  19. pygeai/_docs/source/pygeai.tests.snippets.embeddings.rst +40 -0
  20. pygeai/_docs/source/pygeai.tests.snippets.evaluation.dataset.rst +197 -0
  21. pygeai/_docs/source/pygeai.tests.snippets.evaluation.plan.rst +133 -0
  22. pygeai/_docs/source/pygeai.tests.snippets.evaluation.result.rst +37 -0
  23. pygeai/_docs/source/pygeai.tests.snippets.evaluation.rst +10 -0
  24. pygeai/_docs/source/pygeai.tests.snippets.rst +1 -0
  25. pygeai/admin/clients.py +5 -0
  26. pygeai/assistant/clients.py +7 -0
  27. pygeai/assistant/data_analyst/clients.py +2 -0
  28. pygeai/assistant/rag/clients.py +11 -0
  29. pygeai/chat/clients.py +236 -25
  30. pygeai/chat/endpoints.py +3 -1
  31. pygeai/cli/commands/chat.py +322 -1
  32. pygeai/cli/commands/embeddings.py +56 -8
  33. pygeai/cli/commands/migrate.py +994 -434
  34. pygeai/cli/error_handler.py +116 -0
  35. pygeai/cli/geai.py +28 -10
  36. pygeai/cli/parsers.py +8 -2
  37. pygeai/core/base/clients.py +3 -1
  38. pygeai/core/common/exceptions.py +11 -10
  39. pygeai/core/embeddings/__init__.py +19 -0
  40. pygeai/core/embeddings/clients.py +17 -2
  41. pygeai/core/embeddings/mappers.py +16 -2
  42. pygeai/core/embeddings/responses.py +9 -2
  43. pygeai/core/feedback/clients.py +1 -0
  44. pygeai/core/files/clients.py +5 -7
  45. pygeai/core/files/managers.py +42 -0
  46. pygeai/core/llm/clients.py +4 -0
  47. pygeai/core/plugins/clients.py +1 -0
  48. pygeai/core/rerank/clients.py +1 -0
  49. pygeai/core/secrets/clients.py +6 -0
  50. pygeai/core/services/rest.py +1 -1
  51. pygeai/dbg/__init__.py +3 -0
  52. pygeai/dbg/debugger.py +565 -70
  53. pygeai/evaluation/clients.py +1 -1
  54. pygeai/evaluation/dataset/clients.py +45 -44
  55. pygeai/evaluation/plan/clients.py +27 -26
  56. pygeai/evaluation/result/clients.py +37 -5
  57. pygeai/gam/clients.py +4 -0
  58. pygeai/health/clients.py +1 -0
  59. pygeai/lab/agents/clients.py +8 -1
  60. pygeai/lab/models.py +3 -3
  61. pygeai/lab/processes/clients.py +21 -0
  62. pygeai/lab/strategies/clients.py +4 -0
  63. pygeai/lab/tools/clients.py +1 -0
  64. pygeai/migration/__init__.py +31 -0
  65. pygeai/migration/strategies.py +404 -155
  66. pygeai/migration/tools.py +170 -3
  67. pygeai/organization/clients.py +13 -0
  68. pygeai/organization/limits/clients.py +15 -0
  69. pygeai/proxy/clients.py +3 -1
  70. pygeai/tests/admin/test_clients.py +16 -11
  71. pygeai/tests/assistants/rag/test_clients.py +35 -23
  72. pygeai/tests/assistants/test_clients.py +22 -15
  73. pygeai/tests/auth/test_clients.py +14 -6
  74. pygeai/tests/chat/test_clients.py +211 -1
  75. pygeai/tests/cli/commands/test_embeddings.py +32 -9
  76. pygeai/tests/cli/commands/test_evaluation.py +7 -0
  77. pygeai/tests/cli/commands/test_migrate.py +112 -243
  78. pygeai/tests/cli/test_error_handler.py +225 -0
  79. pygeai/tests/cli/test_geai_driver.py +154 -0
  80. pygeai/tests/cli/test_parsers.py +5 -5
  81. pygeai/tests/core/embeddings/test_clients.py +144 -0
  82. pygeai/tests/core/embeddings/test_managers.py +171 -0
  83. pygeai/tests/core/embeddings/test_mappers.py +142 -0
  84. pygeai/tests/core/feedback/test_clients.py +2 -0
  85. pygeai/tests/core/files/test_clients.py +1 -0
  86. pygeai/tests/core/llm/test_clients.py +14 -9
  87. pygeai/tests/core/plugins/test_clients.py +5 -3
  88. pygeai/tests/core/rerank/test_clients.py +1 -0
  89. pygeai/tests/core/secrets/test_clients.py +19 -13
  90. pygeai/tests/dbg/test_debugger.py +453 -75
  91. pygeai/tests/evaluation/dataset/test_clients.py +3 -1
  92. pygeai/tests/evaluation/plan/test_clients.py +4 -2
  93. pygeai/tests/evaluation/result/test_clients.py +7 -5
  94. pygeai/tests/gam/test_clients.py +1 -1
  95. pygeai/tests/health/test_clients.py +1 -0
  96. pygeai/tests/lab/agents/test_clients.py +9 -0
  97. pygeai/tests/lab/processes/test_clients.py +36 -0
  98. pygeai/tests/lab/processes/test_mappers.py +3 -0
  99. pygeai/tests/lab/strategies/test_clients.py +14 -9
  100. pygeai/tests/migration/test_strategies.py +45 -218
  101. pygeai/tests/migration/test_tools.py +133 -9
  102. pygeai/tests/organization/limits/test_clients.py +17 -0
  103. pygeai/tests/organization/test_clients.py +22 -0
  104. pygeai/tests/proxy/test_clients.py +2 -0
  105. pygeai/tests/proxy/test_integration.py +1 -0
  106. pygeai/tests/snippets/chat/chat_completion_with_reasoning_effort.py +18 -0
  107. pygeai/tests/snippets/chat/get_response.py +15 -0
  108. pygeai/tests/snippets/chat/get_response_streaming.py +20 -0
  109. pygeai/tests/snippets/chat/get_response_with_files.py +16 -0
  110. pygeai/tests/snippets/chat/get_response_with_tools.py +36 -0
  111. pygeai/tests/snippets/dbg/__init__.py +0 -0
  112. pygeai/tests/snippets/dbg/basic_debugging.py +32 -0
  113. pygeai/tests/snippets/dbg/breakpoint_management.py +48 -0
  114. pygeai/tests/snippets/dbg/stack_navigation.py +45 -0
  115. pygeai/tests/snippets/dbg/stepping_example.py +40 -0
  116. pygeai/tests/snippets/embeddings/cache_example.py +31 -0
  117. pygeai/tests/snippets/embeddings/cohere_example.py +41 -0
  118. pygeai/tests/snippets/embeddings/openai_base64_example.py +27 -0
  119. pygeai/tests/snippets/embeddings/openai_example.py +30 -0
  120. pygeai/tests/snippets/embeddings/similarity_example.py +42 -0
  121. pygeai/tests/snippets/evaluation/dataset/__init__.py +0 -0
  122. pygeai/tests/snippets/evaluation/dataset/complete_workflow_example.py +195 -0
  123. pygeai/tests/snippets/evaluation/dataset/create_dataset.py +26 -0
  124. pygeai/tests/snippets/evaluation/dataset/create_dataset_from_file.py +11 -0
  125. pygeai/tests/snippets/evaluation/dataset/create_dataset_row.py +17 -0
  126. pygeai/tests/snippets/evaluation/dataset/create_expected_source.py +18 -0
  127. pygeai/tests/snippets/evaluation/dataset/create_filter_variable.py +19 -0
  128. pygeai/tests/snippets/evaluation/dataset/delete_dataset.py +9 -0
  129. pygeai/tests/snippets/evaluation/dataset/delete_dataset_row.py +10 -0
  130. pygeai/tests/snippets/evaluation/dataset/delete_expected_source.py +15 -0
  131. pygeai/tests/snippets/evaluation/dataset/delete_filter_variable.py +15 -0
  132. pygeai/tests/snippets/evaluation/dataset/get_dataset.py +9 -0
  133. pygeai/tests/snippets/evaluation/dataset/get_dataset_row.py +10 -0
  134. pygeai/tests/snippets/evaluation/dataset/get_expected_source.py +15 -0
  135. pygeai/tests/snippets/evaluation/dataset/get_filter_variable.py +15 -0
  136. pygeai/tests/snippets/evaluation/dataset/list_dataset_rows.py +9 -0
  137. pygeai/tests/snippets/evaluation/dataset/list_datasets.py +6 -0
  138. pygeai/tests/snippets/evaluation/dataset/list_expected_sources.py +10 -0
  139. pygeai/tests/snippets/evaluation/dataset/list_filter_variables.py +10 -0
  140. pygeai/tests/snippets/evaluation/dataset/update_dataset.py +15 -0
  141. pygeai/tests/snippets/evaluation/dataset/update_dataset_row.py +20 -0
  142. pygeai/tests/snippets/evaluation/dataset/update_expected_source.py +18 -0
  143. pygeai/tests/snippets/evaluation/dataset/update_filter_variable.py +19 -0
  144. pygeai/tests/snippets/evaluation/dataset/upload_dataset_rows_file.py +10 -0
  145. pygeai/tests/snippets/evaluation/plan/__init__.py +0 -0
  146. pygeai/tests/snippets/evaluation/plan/add_plan_system_metric.py +13 -0
  147. pygeai/tests/snippets/evaluation/plan/complete_workflow_example.py +136 -0
  148. pygeai/tests/snippets/evaluation/plan/create_evaluation_plan.py +24 -0
  149. pygeai/tests/snippets/evaluation/plan/create_rag_evaluation_plan.py +22 -0
  150. pygeai/tests/snippets/evaluation/plan/delete_evaluation_plan.py +9 -0
  151. pygeai/tests/snippets/evaluation/plan/delete_plan_system_metric.py +13 -0
  152. pygeai/tests/snippets/evaluation/plan/execute_evaluation_plan.py +11 -0
  153. pygeai/tests/snippets/evaluation/plan/get_evaluation_plan.py +9 -0
  154. pygeai/tests/snippets/evaluation/plan/get_plan_system_metric.py +13 -0
  155. pygeai/tests/snippets/evaluation/plan/get_system_metric.py +9 -0
  156. pygeai/tests/snippets/evaluation/plan/list_evaluation_plans.py +7 -0
  157. pygeai/tests/snippets/evaluation/plan/list_plan_system_metrics.py +9 -0
  158. pygeai/tests/snippets/evaluation/plan/list_system_metrics.py +7 -0
  159. pygeai/tests/snippets/evaluation/plan/update_evaluation_plan.py +22 -0
  160. pygeai/tests/snippets/evaluation/plan/update_plan_system_metric.py +14 -0
  161. pygeai/tests/snippets/evaluation/result/__init__.py +0 -0
  162. pygeai/tests/snippets/evaluation/result/complete_workflow_example.py +150 -0
  163. pygeai/tests/snippets/evaluation/result/get_evaluation_result.py +26 -0
  164. pygeai/tests/snippets/evaluation/result/list_evaluation_results.py +17 -0
  165. pygeai/tests/snippets/migrate/__init__.py +45 -0
  166. pygeai/tests/snippets/migrate/agent_migration.py +110 -0
  167. pygeai/tests/snippets/migrate/assistant_migration.py +64 -0
  168. pygeai/tests/snippets/migrate/orchestrator_examples.py +179 -0
  169. pygeai/tests/snippets/migrate/process_migration.py +64 -0
  170. pygeai/tests/snippets/migrate/project_migration.py +42 -0
  171. pygeai/tests/snippets/migrate/tool_migration.py +64 -0
  172. pygeai/tests/snippets/organization/create_project.py +2 -2
  173. {pygeai-0.6.0b7.dist-info → pygeai-0.6.0b11.dist-info}/METADATA +1 -1
  174. {pygeai-0.6.0b7.dist-info → pygeai-0.6.0b11.dist-info}/RECORD +178 -96
  175. {pygeai-0.6.0b7.dist-info → pygeai-0.6.0b11.dist-info}/WHEEL +0 -0
  176. {pygeai-0.6.0b7.dist-info → pygeai-0.6.0b11.dist-info}/entry_points.txt +0 -0
  177. {pygeai-0.6.0b7.dist-info → pygeai-0.6.0b11.dist-info}/licenses/LICENSE +0 -0
  178. {pygeai-0.6.0b7.dist-info → pygeai-0.6.0b11.dist-info}/top_level.txt +0 -0
@@ -4,9 +4,17 @@ PyGEAI Debugger
4
4
  Overview
5
5
  --------
6
6
 
7
- ``geai-dbg`` is a command-line debugger for the ``geai`` CLI tool, part of the ``pygeai`` package. It allows developers to pause execution at specified points (breakpoints) in the ``geai`` codebase, inspect local variables, execute arbitrary Python code in the current context, and control program flow interactively. Breakpoints can be set by module or function name, providing flexibility for debugging complex CLI workflows.
7
+ ``geai-dbg`` is a command-line debugger for the ``geai`` CLI tool, part of the ``pygeai`` package. It allows developers to pause execution at specified points (breakpoints) in the ``geai`` codebase, inspect local variables, navigate the call stack, step through code execution, and control program flow interactively.
8
8
 
9
- The debugger is invoked by running the ``geai-dbg`` command, typically with the same arguments as the ``geai`` CLI. It pauses execution at predefined or user-specified breakpoints, presenting an interactive prompt ``(geai-dbg)`` for issuing commands.
9
+ The debugger provides features similar to Python's built-in ``pdb`` debugger, including:
10
+
11
+ - **Breakpoint management**: Set, list, enable/disable, and remove breakpoints
12
+ - **Stepping**: Step into, over, and out of function calls
13
+ - **Stack navigation**: Move up and down the call stack to inspect different frames
14
+ - **Variable inspection**: Print, pretty-print, and examine local/global variables
15
+ - **Source code display**: View source code around the current execution point
16
+ - **Performance optimization**: Only traces relevant modules to minimize overhead
17
+ - **Command history**: Uses readline for command history and editing
10
18
 
11
19
  Installation and Setup
12
20
  ---------------------
@@ -22,6 +30,9 @@ No additional setup is required. The debugger script (``debugger.py``) is locate
22
30
  Usage
23
31
  -----
24
32
 
33
+ Basic Usage
34
+ ~~~~~~~~~~~
35
+
25
36
  To use ``geai-dbg``, run it with the same arguments you would pass to the ``geai`` CLI. For example:
26
37
 
27
38
  .. code-block:: bash
@@ -32,50 +43,163 @@ This command runs the ``geai`` CLI with the arguments ``ail lrs`` under the debu
32
43
 
33
44
  Upon hitting a breakpoint, the debugger displays:
34
45
 
35
- - The location (module and function) where execution is paused.
36
- - Local variables in the current context.
37
- - An interactive prompt ``(geai-dbg)`` for entering commands.
46
+ - The location (module and function) where execution is paused
47
+ - Source code context around the current line
48
+ - An interactive prompt ``(geai-dbg)`` for entering commands
38
49
 
39
- You can then inspect variables, add breakpoints, execute code, or control execution using the available commands.
50
+ Custom Target Functions
51
+ ~~~~~~~~~~~~~~~~~~~~~~~
40
52
 
41
- Commands
42
- --------
53
+ You can also debug custom Python functions using the ``Debugger`` class directly:
54
+
55
+ .. code-block:: python
56
+
57
+ from pygeai.dbg.debugger import Debugger
58
+
59
+ def my_function():
60
+ x = 10
61
+ y = 20
62
+ result = x + y
63
+ print(f"Result: {result}")
64
+
65
+ # Create debugger and set breakpoint
66
+ dbg = Debugger(target=my_function, module_filter="__main__")
67
+ dbg.add_breakpoint(module="__main__", function_name="my_function")
68
+ dbg.run()
69
+
70
+ Commands Reference
71
+ ------------------
43
72
 
44
73
  At the ``(geai-dbg)`` prompt, the following commands are available:
45
74
 
46
- continue, c
75
+ Flow Control
76
+ ~~~~~~~~~~~~
77
+
78
+ **continue, c**
47
79
  Resume execution until the next breakpoint is hit or the program completes.
48
80
 
49
- quit, q, Ctrl+D
50
- Exit the debugger, terminating the program with a clean exit status (0).
81
+ **step, s**
82
+ Execute the current line and stop at the first possible occasion (either in a function that is called or on the next line in the current function).
83
+
84
+ **next, n**
85
+ Continue execution until the next line in the current function is reached or it returns (step over function calls).
86
+
87
+ **return, ret**
88
+ Continue execution until the current function returns.
51
89
 
52
- run, r
90
+ **run, r**
53
91
  Run the program to completion, disabling all breakpoints and skipping further pauses.
54
92
 
55
- breakpoint-module, bm
56
- Add a breakpoint for a specific module. Prompts for a module name (e.g., ``pygeai.cli.commands``). Press Enter to set a wildcard breakpoint (any module).
93
+ **quit, q, Ctrl+D**
94
+ Exit the debugger, terminating the program with a clean exit status (0).
95
+
96
+ Stack Navigation
97
+ ~~~~~~~~~~~~~~~~
98
+
99
+ **where, w, bt, backtrace**
100
+ Display the stack trace, showing all frames from the current execution point to the top of the call stack.
101
+
102
+ **up, u**
103
+ Move up one level in the stack trace (to an older frame). This allows you to inspect the context of the caller.
104
+
105
+ **down, d**
106
+ Move down one level in the stack trace (to a newer frame).
107
+
108
+ Source Display
109
+ ~~~~~~~~~~~~~~
110
+
111
+ **list, l [n]**
112
+ Show source code around the current line. Optional argument ``n`` specifies the number of lines of context (default: 10).
113
+
114
+ Variable Inspection
115
+ ~~~~~~~~~~~~~~~~~~~
116
+
117
+ **print, p <expression>**
118
+ Evaluate and print the value of a Python expression in the current frame's context.
119
+
120
+ Example: ``p x + y``
121
+
122
+ **pp <expression>**
123
+ Pretty-print the value of a Python expression using ``pprint.pprint()``.
124
+
125
+ Example: ``pp locals()``
57
126
 
58
- breakpoint-function, bf
59
- Add a breakpoint for a specific function, optionally scoped to a module. Prompts for a function name (e.g., ``main``) and an optional module name. Press Enter for wildcards (any function or module).
127
+ **locals, loc**
128
+ Display all local variables in the current frame.
60
129
 
61
- list-modules, lm
62
- List all loaded modules starting with ``pygeai``, useful for identifying valid module names for breakpoints.
130
+ **globals, glob**
131
+ Display all global variables in the current frame (excluding built-ins).
63
132
 
64
- help, h
133
+ **args, a**
134
+ Display the arguments of the current function.
135
+
136
+ Breakpoint Management
137
+ ~~~~~~~~~~~~~~~~~~~~~
138
+
139
+ **break, b**
140
+ List all breakpoints with their status, hit counts, and conditions.
141
+
142
+ **b <function>**
143
+ Set a breakpoint on any function with the given name.
144
+
145
+ Example: ``b main``
146
+
147
+ **b <module>:<function>**
148
+ Set a breakpoint on a specific function in a specific module.
149
+
150
+ Example: ``b pygeai.cli.geai:main``
151
+
152
+ **clear, cl <breakpoint>**
153
+ Remove a breakpoint. Use the same syntax as setting a breakpoint.
154
+
155
+ Example: ``cl main`` or ``cl pygeai.cli.geai:main``
156
+
157
+ **clearall, cla**
158
+ Remove all breakpoints.
159
+
160
+ **enable, en <breakpoint>**
161
+ Enable a disabled breakpoint.
162
+
163
+ Example: ``en main``
164
+
165
+ **disable, dis <breakpoint>**
166
+ Disable a breakpoint without removing it.
167
+
168
+ Example: ``dis main``
169
+
170
+ Legacy Commands
171
+ ~~~~~~~~~~~~~~~
172
+
173
+ These commands are maintained for backward compatibility:
174
+
175
+ **breakpoint-module, bm**
176
+ Add a breakpoint for a specific module (interactive prompt).
177
+
178
+ **breakpoint-function, bf**
179
+ Add a breakpoint for a specific function (interactive prompt).
180
+
181
+ **list-modules, lm**
182
+ List all loaded modules starting with the module filter (default: ``pygeai``).
183
+
184
+ Other Commands
185
+ ~~~~~~~~~~~~~~
186
+
187
+ **help, h, ?**
65
188
  Display a list of available commands and their descriptions.
66
189
 
67
- <Python code>
68
- Execute arbitrary Python code in the current context. For example, ``print(sys.argv)`` displays the command-line arguments. Errors are caught and logged without crashing the debugger.
190
+ **<Python code>**
191
+ Execute arbitrary Python code in the current frame's context. For example, ``x = 42`` or ``print(sys.argv)``. Errors are caught and logged without crashing the debugger.
69
192
 
70
- Ctrl+C
193
+ **Ctrl+C**
71
194
  Interrupt the current command input and resume execution, equivalent to ``continue``.
72
195
 
73
196
  Examples
74
197
  --------
75
198
 
76
- **Example 1: Debugging a geai Command**
199
+ Example 1: Basic Debugging
200
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~
77
201
 
78
- Suppose you want to debug the ``geai ail lrs`` command to inspect its execution. Run:
202
+ Debug the ``geai ail lrs`` command:
79
203
 
80
204
  .. code-block:: bash
81
205
 
@@ -85,84 +209,213 @@ Output:
85
209
 
86
210
  .. code-block:: text
87
211
 
88
- 2025-05-12 15:04:57,263 - geai - INFO - GEAI debugger started.
89
- 2025-05-12 15:04:57,263 - geai - INFO - geai module: pygeai.cli.geai
90
- 2025-05-12 15:04:57,263 - geai - INFO - Breakpoint added: pygeai.cli.geai:main
91
- 2025-05-12 15:04:57,264 - geai - INFO - Setting trace and running geai
92
- 2025-05-12 15:04:57,264 - geai - INFO - Breakpoint hit at pygeai.cli.geai.main
93
- 2025-05-12 15:04:57,264 - geai - INFO - Local variables: {}
94
-
95
- Paused at pygeai.cli.geai.main
96
- Enter commands to execute in the current context (type 'continue' to resume, 'quit' to exit, 'help' to display available commands):
212
+ 2026-01-07 15:04:57,263 - geai.dbg - INFO - GEAI debugger started.
213
+ 2026-01-07 15:04:57,264 - geai.dbg - INFO - Breakpoint added: pygeai.cli.geai:main (enabled, hits: 0)
214
+ 2026-01-07 15:04:57,264 - geai.dbg - INFO - Setting trace and running target
215
+ 2026-01-07 15:04:57,264 - geai.dbg - INFO - Breakpoint hit at pygeai.cli.geai.main (hit #1)
216
+
217
+ ============================================================
218
+ Paused at pygeai.cli.geai.main (line 42)
219
+
220
+ Source (/path/to/pygeai/cli/geai.py):
221
+ 39
222
+ 40 class CLIDriver:
223
+ 41 def main(self):
224
+ -> 42 parser = ArgumentParser()
225
+ 43 args = parser.parse_args()
226
+ 44 return self.execute(args)
227
+ 45
228
+ ============================================================
229
+ Type 'h' for help, 'c' to continue
97
230
  (geai-dbg)
98
231
 
99
- List available commands:
232
+ Example 2: Stepping Through Code
233
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
234
+
235
+ At a breakpoint, step through code execution:
100
236
 
101
237
  .. code-block:: text
102
238
 
103
- (geai-dbg) h
104
- Available commands:
105
- continue, c: Resume execution until next breakpoint
106
- quit, q: Exit the debugger
107
- run, r: Run program without further pauses
108
- breakpoint-module, bm: Add a module breakpoint
109
- breakpoint-function, bf: Add a function breakpoint
110
- list-modules, lm: List available modules
111
- <Python code>: Execute arbitrary Python code in the current context
239
+ (geai-dbg) s
240
+ # Steps into the next function call
241
+
242
+ (geai-dbg) n
243
+ # Steps over function calls, staying in the current function
244
+
245
+ (geai-dbg) ret
246
+ # Continues until the current function returns
112
247
 
113
- List modules to find valid breakpoint targets:
248
+ Example 3: Inspecting Variables
249
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
250
+
251
+ Examine variables at a breakpoint:
114
252
 
115
253
  .. code-block:: text
116
254
 
117
- (geai-dbg) lm
118
- 2025-05-12 15:05:03,595 - geai - INFO - Listing available modules
119
- Available modules: ['pygeai', 'pygeai.dbg', 'pygeai.cli', ...]
255
+ (geai-dbg) p x
256
+ 42
257
+
258
+ (geai-dbg) pp locals()
259
+ {'x': 42,
260
+ 'y': 20,
261
+ 'result': 62}
262
+
263
+ (geai-dbg) args
264
+ Function arguments:
265
+ self = <pygeai.cli.geai.CLIDriver object at 0x...>
266
+ args = None
267
+
268
+ Example 4: Stack Navigation
269
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
120
270
 
121
- Continue to the next breakpoint (e.g., another hit on ``main`` in a different context):
271
+ Navigate the call stack:
122
272
 
123
273
  .. code-block:: text
124
274
 
125
- (geai-dbg) c
126
- 2025-05-12 15:05:18,424 - geai - DEBUG - Alias: default
127
- 2025-05-12 15:05:18,424 - geai - DEBUG - Base URL: api.beta.saia.ai/
128
- 2025-05-12 15:05:18,425 - geai - INFO - Breakpoint hit at pygeai.cli.geai.main
129
- 2025-05-12 15:05:18,425 - geai - INFO - Local variables: {'self': <pygeai.cli.geai.CLIDriver object at 0x100f34080>, 'args': None}
275
+ (geai-dbg) where
276
+ Stack trace (most recent call last):
277
+ #0 __main__.level_3 at /path/to/script.py:15
278
+ > #1 __main__.level_2 at /path/to/script.py:10
279
+ #2 __main__.level_1 at /path/to/script.py:5
280
+
281
+ (geai-dbg) up
282
+ Frame #0: __main__.level_2
283
+
284
+ (geai-dbg) locals
285
+ Local variables:
286
+ {'value': 'level 2'}
287
+
288
+ (geai-dbg) down
289
+ Frame #1: __main__.level_3
290
+
291
+ Example 5: Breakpoint Management
292
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
293
+
294
+ Manage breakpoints during debugging:
130
295
 
131
- Paused at pygeai.cli.geai.main
132
- Enter commands to execute in the current context (type 'continue' to resume, 'quit' to exit, 'help' to display available commands):
133
- (geai-dbg)
296
+ .. code-block:: text
134
297
 
135
- Run the program to completion:
298
+ (geai-dbg) b
299
+ Breakpoints:
300
+ 1. pygeai.cli.geai:main (enabled, hits: 1)
301
+
302
+ (geai-dbg) b process_data
303
+ Breakpoint added: *:process_data (enabled, hits: 0)
304
+
305
+ (geai-dbg) b pygeai.core:helper_function
306
+ Breakpoint added: pygeai.core:helper_function (enabled, hits: 0)
307
+
308
+ (geai-dbg) dis process_data
309
+ Breakpoint disabled: *:process_data (disabled, hits: 0)
310
+
311
+ (geai-dbg) cl pygeai.core:helper_function
312
+ Breakpoint removed: pygeai.core:helper_function
313
+
314
+ Example 6: Viewing Source Code
315
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
316
+
317
+ Display source code around the current line:
136
318
 
137
319
  .. code-block:: text
138
320
 
139
- (geai-dbg) run
140
- 2025-05-12 15:05:21,221 - geai - INFO - Running program without further pauses.
141
- 2025-05-12 15:05:21,222 - geai - DEBUG - Running geai with: /path/to/venv/bin/geai-dbg ail lrs
142
- 2025-05-12 15:05:21,222 - geai - DEBUG - Listing reasoning strategies
143
- [geai output listing reasoning strategies]
144
- 2025-05-12 15:05:21,878 - geai - INFO - Cleaning up trace
321
+ (geai-dbg) list 5
322
+ Source (/path/to/file.py):
323
+ 10 def process_data(data):
324
+ 11 result = []
325
+ 12 for item in data:
326
+ -> 13 processed = helper_function(item)
327
+ 14 result.append(processed)
328
+ 15 return result
145
329
 
146
- **Example 2: Inspecting Variables**
330
+ Advanced Features
331
+ -----------------
147
332
 
148
- At a breakpoint, inspect command-line arguments:
333
+ Module Filtering
334
+ ~~~~~~~~~~~~~~~~
149
335
 
150
- .. code-block:: text
336
+ The debugger includes a performance optimization that only traces modules matching a specified prefix (default: ``pygeai``). This significantly reduces overhead compared to tracing all Python code.
151
337
 
152
- (geai-dbg) print(sys.argv)
153
- 2025-05-12 15:05:21,300 - geai - INFO - Executing interactive command: print(sys.argv)
154
- ['/path/to/venv/bin/geai-dbg', 'ail', 'lrs']
338
+ When creating a custom debugger, you can specify the module filter:
155
339
 
156
- **Example 3: Adding a Breakpoint**
340
+ .. code-block:: python
157
341
 
158
- Add a breakpoint for the ``pygeai.cli.commands`` module:
342
+ dbg = Debugger(target=my_function, module_filter="my_package")
159
343
 
160
- .. code-block:: text
344
+ This will only trace modules starting with ``my_package``, ignoring standard library and third-party code.
345
+
346
+ Conditional Breakpoints
347
+ ~~~~~~~~~~~~~~~~~~~~~~~
348
+
349
+ Breakpoints can include conditions that must be met for the breakpoint to trigger:
350
+
351
+ .. code-block:: python
352
+
353
+ dbg = Debugger(target=my_function)
354
+ dbg.add_breakpoint(
355
+ module="my_module",
356
+ function_name="process_item",
357
+ condition="item > 100"
358
+ )
359
+
360
+ The breakpoint will only trigger when ``item > 100`` evaluates to ``True`` in the function's context.
361
+
362
+ Command History
363
+ ~~~~~~~~~~~~~~~
364
+
365
+ The debugger uses Python's ``readline`` module to provide command history and line editing. You can use:
366
+
367
+ - **Up/Down arrows**: Navigate through command history
368
+ - **Ctrl+R**: Search command history
369
+ - **Tab**: (if configured) Auto-completion
370
+
371
+ Command history is saved to ``~/.geai_dbg_history`` and persists across debugging sessions.
372
+
373
+ Programmatic Usage
374
+ ~~~~~~~~~~~~~~~~~~
375
+
376
+ You can use the ``Debugger`` class programmatically in your own code:
377
+
378
+ .. code-block:: python
379
+
380
+ from pygeai.dbg.debugger import Debugger, Breakpoint
381
+
382
+ def my_target():
383
+ # Your code here
384
+ pass
385
+
386
+ # Create debugger
387
+ dbg = Debugger(target=my_target, module_filter="my_package")
388
+
389
+ # Add breakpoints
390
+ dbg.add_breakpoint(module="my_package.module", function_name="my_function")
391
+ dbg.add_breakpoint(function_name="helper", condition="x > 10")
392
+
393
+ # List breakpoints
394
+ for bp in dbg.list_breakpoints():
395
+ print(f"Breakpoint: {bp}")
396
+
397
+ # Run under debugger
398
+ dbg.run()
399
+
400
+ # Reset state for reuse
401
+ dbg.reset()
402
+
403
+ Tips and Best Practices
404
+ -----------------------
405
+
406
+ 1. **Start with targeted breakpoints**: Set specific breakpoints on the functions you want to debug rather than using wildcards.
161
407
 
162
- (geai-dbg) bm
163
- 2025-05-12 15:05:21,400 - geai - INFO - Adding breakpoint on module
164
- (geai-dbg) Enter module name (or press Enter for any module): pygeai.cli.commands
165
- 2025-05-12 15:05:21,500 - geai - INFO - Breakpoint added: pygeai.cli.commands:*
408
+ 2. **Use step wisely**: The ``step`` command can be slow if it steps into many library functions. Use ``next`` to stay at the same level.
409
+
410
+ 3. **Inspect the stack**: Use ``where`` to understand the call chain, especially in complex codebases.
411
+
412
+ 4. **Pretty-print complex data**: Use ``pp`` instead of ``p`` for dictionaries, lists, and other complex structures.
413
+
414
+ 5. **Disable instead of removing**: Use ``disable`` to temporarily turn off breakpoints you might need again, rather than removing them.
415
+
416
+ 6. **Use module filtering**: When debugging custom code, set ``module_filter`` to your package name to avoid tracing unrelated code.
417
+
418
+ 7. **Conditional breakpoints**: Use conditions to break only when specific criteria are met, reducing manual stepping.
166
419
 
167
420
  Notes
168
421
  -----
@@ -172,17 +425,57 @@ Notes
172
425
  - Pressing ``Ctrl+C`` resumes execution, equivalent to the ``continue`` command.
173
426
 
174
427
  - **Python Code Execution**:
175
- - Arbitrary Python code executed at the prompt runs in the context of the paused frame, with access to local and global variables. Use with caution, as it can modify program state.
428
+ - Arbitrary Python code executed at the prompt runs in the context of the current frame, with access to local and global variables. Use with caution, as it can modify program state.
176
429
 
177
- - **Breakpoint Wildcards**:
178
- - Use ``bm`` or ``bf`` with empty inputs to set wildcard breakpoints, pausing on any module or function. This is useful for exploratory debugging.
430
+ - **Performance**:
431
+ - The debugger uses ``sys.settrace`` which has performance overhead. The module filter helps minimize this, but expect slower execution than running without the debugger.
432
+
433
+ - **Breakpoint Persistence**:
434
+ - Breakpoints persist across ``continue`` commands but are cleared when the program exits. They are not saved to disk.
179
435
 
180
436
  - **Logging**:
181
- - The debugger logs to stdout with timestamps, including breakpoint hits, local variables, and command execution. Errors in Python code execution are logged without crashing the debugger.
437
+ - The debugger logs to stdout with timestamps, including breakpoint hits, state changes, and errors. The log level is set to DEBUG by default.
438
+
439
+ - **Frame Context**:
440
+ - When you move up/down the stack with ``up``/``down``, the current frame changes, affecting what ``locals``, ``globals``, and expression evaluation see.
441
+
442
+ Code Examples
443
+ -------------
444
+
445
+ See the ``pygeai/tests/snippets/dbg/`` directory for complete working examples:
446
+
447
+ - ``basic_debugging.py`` - Simple debugging with variable inspection
448
+ - ``stepping_example.py`` - Demonstrates step, next, and return commands
449
+ - ``stack_navigation.py`` - Shows stack traversal with up/down
450
+ - ``breakpoint_management.py`` - Examples of managing breakpoints
451
+
452
+ Run these examples with:
453
+
454
+ .. code-block:: bash
455
+
456
+ python -m pygeai.tests.snippets.dbg.basic_debugging
457
+
458
+ Troubleshooting
459
+ ---------------
460
+
461
+ **Debugger is too slow**
462
+ Adjust the ``module_filter`` to trace only the modules you care about. The default filter is ``"pygeai"``.
463
+
464
+ **Breakpoint not hitting**
465
+ - Check that the module and function names match exactly (use ``lm`` to list loaded modules)
466
+ - Verify the breakpoint is enabled (use ``b`` to list breakpoints)
467
+ - Check if a condition is preventing the breakpoint from triggering
468
+
469
+ **Can't see local variables**
470
+ Make sure you're in the correct frame. Use ``where`` to see the stack and ``up``/``down`` to navigate.
471
+
472
+ **Source code not displaying**
473
+ The source file might not be accessible or the code might be in a compiled module. The debugger needs access to the ``.py`` source files.
182
474
 
183
- For issues or feature requests, contact the ``pygeai`` development team.
475
+ For issues or feature requests, contact the ``pygeai`` development team or file an issue on the project's GitHub repository.
184
476
 
185
477
  .. seealso::
186
478
 
187
- - ``geai`` CLI documentation for details on the underlying command-line tool.
188
- - Python's ``sys.settrace`` documentation for technical details on the debugging mechanism.
479
+ - ``geai`` CLI documentation for details on the underlying command-line tool
480
+ - Python's ``sys.settrace`` documentation for technical details on the debugging mechanism
481
+ - Python's ``pdb`` module for comparison with the standard Python debugger