quantalogic 0.2.0__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 (68) hide show
  1. quantalogic/__init__.py +20 -0
  2. quantalogic/agent.py +638 -0
  3. quantalogic/agent_config.py +138 -0
  4. quantalogic/coding_agent.py +83 -0
  5. quantalogic/event_emitter.py +223 -0
  6. quantalogic/generative_model.py +226 -0
  7. quantalogic/interactive_text_editor.py +190 -0
  8. quantalogic/main.py +185 -0
  9. quantalogic/memory.py +217 -0
  10. quantalogic/model_names.py +19 -0
  11. quantalogic/print_event.py +66 -0
  12. quantalogic/prompts.py +99 -0
  13. quantalogic/server/__init__.py +3 -0
  14. quantalogic/server/agent_server.py +633 -0
  15. quantalogic/server/models.py +60 -0
  16. quantalogic/server/routes.py +117 -0
  17. quantalogic/server/state.py +199 -0
  18. quantalogic/server/static/js/event_visualizer.js +430 -0
  19. quantalogic/server/static/js/quantalogic.js +571 -0
  20. quantalogic/server/templates/index.html +134 -0
  21. quantalogic/tool_manager.py +68 -0
  22. quantalogic/tools/__init__.py +46 -0
  23. quantalogic/tools/agent_tool.py +88 -0
  24. quantalogic/tools/download_http_file_tool.py +64 -0
  25. quantalogic/tools/edit_whole_content_tool.py +70 -0
  26. quantalogic/tools/elixir_tool.py +240 -0
  27. quantalogic/tools/execute_bash_command_tool.py +116 -0
  28. quantalogic/tools/input_question_tool.py +57 -0
  29. quantalogic/tools/language_handlers/__init__.py +21 -0
  30. quantalogic/tools/language_handlers/c_handler.py +33 -0
  31. quantalogic/tools/language_handlers/cpp_handler.py +33 -0
  32. quantalogic/tools/language_handlers/go_handler.py +33 -0
  33. quantalogic/tools/language_handlers/java_handler.py +37 -0
  34. quantalogic/tools/language_handlers/javascript_handler.py +42 -0
  35. quantalogic/tools/language_handlers/python_handler.py +29 -0
  36. quantalogic/tools/language_handlers/rust_handler.py +33 -0
  37. quantalogic/tools/language_handlers/scala_handler.py +33 -0
  38. quantalogic/tools/language_handlers/typescript_handler.py +42 -0
  39. quantalogic/tools/list_directory_tool.py +123 -0
  40. quantalogic/tools/llm_tool.py +119 -0
  41. quantalogic/tools/markitdown_tool.py +105 -0
  42. quantalogic/tools/nodejs_tool.py +515 -0
  43. quantalogic/tools/python_tool.py +469 -0
  44. quantalogic/tools/read_file_block_tool.py +140 -0
  45. quantalogic/tools/read_file_tool.py +79 -0
  46. quantalogic/tools/replace_in_file_tool.py +300 -0
  47. quantalogic/tools/ripgrep_tool.py +353 -0
  48. quantalogic/tools/search_definition_names.py +419 -0
  49. quantalogic/tools/task_complete_tool.py +35 -0
  50. quantalogic/tools/tool.py +146 -0
  51. quantalogic/tools/unified_diff_tool.py +387 -0
  52. quantalogic/tools/write_file_tool.py +97 -0
  53. quantalogic/utils/__init__.py +17 -0
  54. quantalogic/utils/ask_user_validation.py +12 -0
  55. quantalogic/utils/download_http_file.py +77 -0
  56. quantalogic/utils/get_coding_environment.py +15 -0
  57. quantalogic/utils/get_environment.py +26 -0
  58. quantalogic/utils/get_quantalogic_rules_content.py +19 -0
  59. quantalogic/utils/git_ls.py +121 -0
  60. quantalogic/utils/read_file.py +54 -0
  61. quantalogic/utils/read_http_text_content.py +101 -0
  62. quantalogic/xml_parser.py +242 -0
  63. quantalogic/xml_tool_parser.py +99 -0
  64. quantalogic-0.2.0.dist-info/LICENSE +201 -0
  65. quantalogic-0.2.0.dist-info/METADATA +1034 -0
  66. quantalogic-0.2.0.dist-info/RECORD +68 -0
  67. quantalogic-0.2.0.dist-info/WHEEL +4 -0
  68. quantalogic-0.2.0.dist-info/entry_points.txt +3 -0
@@ -0,0 +1,1034 @@
1
+ Metadata-Version: 2.1
2
+ Name: quantalogic
3
+ Version: 0.2.0
4
+ Summary: QuantaLogic ReAct Agents
5
+ Author: Raphaël MANSUY
6
+ Author-email: raphael.mansuy@gmail.com
7
+ Requires-Python: >=3.12,<4.0
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: Programming Language :: Python :: 3.12
10
+ Classifier: Programming Language :: Python :: 3.13
11
+ Requires-Dist: boto3 (>=1.35.86,<2.0.0)
12
+ Requires-Dist: click (>=8.1.8,<9.0.0)
13
+ Requires-Dist: fastapi (>=0.115.6,<0.116.0)
14
+ Requires-Dist: google-auth (>=2.20.0,<3.0.0)
15
+ Requires-Dist: litellm (>=1.56.4,<2.0.0)
16
+ Requires-Dist: loguru (>=0.7.3,<0.8.0)
17
+ Requires-Dist: markitdown (>=0.0.1a3,<0.0.2)
18
+ Requires-Dist: pathspec (>=0.12.1,<0.13.0)
19
+ Requires-Dist: prompt-toolkit (>=3.0.48,<4.0.0)
20
+ Requires-Dist: pydantic (>=2.10.4,<3.0.0)
21
+ Requires-Dist: rich (>=13.9.4,<14.0.0)
22
+ Requires-Dist: tenacity (>=9.0.0,<10.0.0)
23
+ Requires-Dist: tree-sitter (>=0.23.2,<0.24.0)
24
+ Requires-Dist: tree-sitter-c (>=0.23.4,<0.24.0)
25
+ Requires-Dist: tree-sitter-cpp (>=0.23.4,<0.24.0)
26
+ Requires-Dist: tree-sitter-go (>=0.23.4,<0.24.0)
27
+ Requires-Dist: tree-sitter-java (>=0.23.5,<0.24.0)
28
+ Requires-Dist: tree-sitter-javascript (>=0.23.1,<0.24.0)
29
+ Requires-Dist: tree-sitter-python (>=0.23.6,<0.24.0)
30
+ Requires-Dist: tree-sitter-rust (>=0.23.2,<0.24.0)
31
+ Requires-Dist: tree-sitter-scala (>=0.23.4,<0.24.0)
32
+ Requires-Dist: tree-sitter-typescript (>=0.23.2,<0.24.0)
33
+ Requires-Dist: uvicorn (>=0.34.0,<0.35.0)
34
+ Requires-Dist: websocket (>=0.2.1,<0.3.0)
35
+ Description-Content-Type: text/markdown
36
+
37
+ # QuantaLogic
38
+
39
+ [![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
40
+ [![Python](https://img.shields.io/badge/Python-3.12+-blue.svg)](https://www.python.org/downloads/)
41
+ [![Documentation](https://img.shields.io/badge/docs-latest-brightgreen.svg)]()
42
+
43
+ QuantaLogic is a ReAct (Reasoning & Action) framework for building advanced AI agents.
44
+
45
+ It seamlessly integrates large language models (LLMs) with a robust tool system, enabling agents to understand, reason about, and execute complex tasks through natural language interaction.
46
+
47
+ The `cli` version include coding capabilities comparable to Aider.
48
+
49
+
50
+ ## Why QuantaLogic?
51
+
52
+ We created [QuantaLogic](https://www.quantalogic.app) because we saw a significant gap between the advanced AI models developed by companies like OpenAI, Anthropic, DeepSeek and their practical implementation in everyday business processes.
53
+
54
+ > Our mission is to bridge this gap, making the power of generative AI accessible and actionable for businesses of all sizes.
55
+
56
+
57
+ ## 🌟 Highlights
58
+
59
+ - **ReAct Framework**: Advanced implementation combining LLM reasoning with concrete actions
60
+ - **Universal LLM Support**: Integration with OpenAI, Anthropic, LM Studio, Bedrock, Ollama, DeepSeek V3, via LiteLLM
61
+ - **Secure Tool System**: Docker-based code execution and file manipulation tools
62
+ - **Real-time Monitoring**: Web interface with SSE-based event visualization
63
+ - **Memory Management**: Intelligent context handling and optimization
64
+ - **Enterprise Ready**: Comprehensive logging, error handling, and validation system
65
+
66
+ ## 📋 Table of Contents
67
+
68
+ - [Installation](#-installation)
69
+ - [Quick Start](#-quickstart)
70
+ - [Key Components](#-key-components)
71
+ - [Agent System](#-agent-system)
72
+ - [Tool System](#-tool-system)
73
+ - [Web Interface](#-web-interface)
74
+ - [Examples](#-examples)
75
+ - [Development](#-development)
76
+ - [Contributing](#-contributing)
77
+ - [License](#-license)
78
+
79
+ ## 📦 Installation
80
+
81
+ ### Prerequisites
82
+
83
+ - Python 3.12+
84
+ - Docker (optional for code execution tools)
85
+
86
+ ### Via pip
87
+
88
+ ```bash
89
+ # Basic installation
90
+ pip install quantalogic
91
+ ```
92
+
93
+ ### From Source
94
+
95
+ ```bash
96
+ git clone https://github.com/quantalogic/quantalogic.git
97
+ cd quantalogic
98
+ python -m venv .venv
99
+ source ./venv/bin/activate
100
+ poetry install
101
+ ```
102
+
103
+ ## Using pipx
104
+
105
+ ```
106
+ pipx install quantalogic
107
+ ```
108
+
109
+
110
+ ## 🚀 Quickstart
111
+
112
+ ### Basic Usage
113
+
114
+ ## 📖 CLI Reference
115
+
116
+ The QuantaLogic CLI provides powerful command-line capabilities:
117
+
118
+ ```bash
119
+ quantalogic [OPTIONS] COMMAND [ARGS]...
120
+ ```
121
+
122
+ ### Options
123
+ --model-name TEXT Model to use (default: deepseek/deepseek-chat)
124
+ --verbose Enable verbose output
125
+ --mode TEXT Agent mode (code/basic/interpreter/full/code-basic)
126
+ --file PATH Path to task file
127
+ --version Show version and exit
128
+
129
+ ### Commands
130
+ task Execute a task with the QuantaLogic AI Assistant
131
+
132
+ ### Detailed Usage
133
+
134
+ #### Agent Modes
135
+ - code: Coding-focused agent with basic capabilities
136
+ - basic: General-purpose agent without coding tools
137
+ - interpreter: Interactive code execution agent
138
+ - full: Full-featured agent with all capabilities
139
+ - code-basic: Coding agent with basic reasoning
140
+
141
+ #### Task Execution
142
+ Tasks can be provided:
143
+ 1. Directly via --task parameter
144
+ 2. Through a file using --file parameter
145
+ 3. Interactively via standard input
146
+
147
+ #### Error Handling
148
+ The CLI provides comprehensive error handling:
149
+ - File not found errors
150
+ - Permission errors
151
+ - Model configuration errors
152
+ - Task validation errors
153
+
154
+ #### Examples
155
+
156
+ Basic task execution:
157
+ ```bash
158
+ quantalogic --task "Write a Python function to calculate Fibonacci numbers"
159
+ ```
160
+
161
+ Using a task file:
162
+ ```bash
163
+ quantalogic --file tasks/example.md --verbose
164
+ ```
165
+
166
+ Selecting agent mode:
167
+ ```bash
168
+ quantalogic --mode interpreter --task "Explain quantum computing"
169
+ ```
170
+
171
+ Interactive mode:
172
+ ```bash
173
+ quantalogic
174
+ ```
175
+
176
+ ### Examples
177
+
178
+ Basic task execution:
179
+ ```bash
180
+ quantalogic --task "Write a Python function to calculate Fibonacci numbers"
181
+ ```
182
+
183
+ Using a task file:
184
+ ```bash
185
+ quantalogic --file tasks/example.md --verbose
186
+ ```
187
+
188
+ Selecting agent mode:
189
+ ```bash
190
+ quantalogic --mode interpreter --task "Explain quantum computing"
191
+ ```
192
+
193
+ ```python
194
+ from quantalogic import Agent
195
+
196
+ # Initialize agent with default configuration
197
+ agent = Agent(model_name="deepseek/deepseek-chat")
198
+
199
+ # Execute a task
200
+ result = agent.solve_task(
201
+ "Create a Python function that calculates the Fibonacci sequence"
202
+ )
203
+ print(result)
204
+ ```
205
+
206
+ ### Environment Configuration Example
207
+
208
+ ```python
209
+ import os
210
+
211
+ from quantalogic import Agent
212
+
213
+ # Verify that DEEPSEEK_API_KEY is set
214
+ if not os.environ.get("DEEPSEEK_API_KEY"):
215
+ raise ValueError("DEEPSEEK_API_KEY environment variable is not set")
216
+
217
+ # Initialize the AI agent with default configuration
218
+ agent = Agent(model_name="deepseek/deepseek-chat")
219
+
220
+ # Execute a sample task
221
+ result = agent.solve_task("Create a Python function that calculates the Fibonacci sequence")
222
+ print(result)
223
+ ```
224
+
225
+ ### Command Line Interface
226
+
227
+ ```bash
228
+ # Simple task execution
229
+ quantalogic --task "Write a FastAPI endpoint that handles file uploads"
230
+ ```
231
+
232
+
233
+ `instruction.md`
234
+
235
+ ```md
236
+ Write a poem
237
+ Translate the poem in English
238
+ Choose 2 French Authors
239
+ And then rewrite the translation with the style of each author
240
+ ```
241
+
242
+ `
243
+ ```bash
244
+ # Advanced usage with options
245
+ quantalogic \
246
+ --model openrouter/deepseek-chat \
247
+ --execute-file instruction.md \
248
+ --verbose
249
+ ```
250
+
251
+ ## 🔨 Key Components
252
+
253
+ ### Agent System
254
+
255
+ The core agent implements the `ReAct`paradigm, combining:
256
+
257
+ - Language model reasoning
258
+ - Tool execution capabilities
259
+ - Memory management
260
+ - Event handling
261
+ - Task validation
262
+
263
+ ```python
264
+ from quantalogic import Agent
265
+ from quantalogic.tools import PythonTool, ReadFileTool
266
+
267
+ # Create agent with specific tools
268
+ agent = Agent(
269
+ model_name="openrouter/deepseek-chat",
270
+ tools=[
271
+ PythonTool(),
272
+ ReadFileTool()
273
+ ]
274
+ )
275
+
276
+ ```
277
+
278
+ ### How it works
279
+
280
+
281
+ The ReAct (Reasoning & Action) framework represents a significant advancement in the development of intelligent agents capable of autonomously reasoning through tasks and taking appropriate actions.
282
+
283
+ QuantaLogic implements this framework, allowing integration with large language models (LLMs) to construct sophisticated agents that can tackle complex problems through natural language interaction.
284
+
285
+ ## What is a ReAct Agent?
286
+
287
+ ### Basic Concept
288
+
289
+ A ReAct agent utilizes the synergy of reasoning and action. It not only processes natural language inputs but also executes actions in response to these inputs, utilizing various available tools. This functionality is particularly beneficial for environments where complex tasks can be decomposed into manageable subtasks.
290
+
291
+ ### The QuantaLogic Implementation
292
+
293
+ QuantaLogic provides an effective implementation of the ReAct framework with several core components:
294
+
295
+ - **Generative Model**: This serves as the agent's brain, enabling it to interpret tasks and generate human-like text responses.
296
+ - **Memory Management**: This capability allows the agent to maintain context, keeping track of previous inputs and interactions to provide coherent responses.
297
+ - **Tool Management**: The agent has access to a diverse range of tools, enabling it to perform actions such as code execution, file manipulation, and API communication.
298
+
299
+ ## How the ReAct Framework Works
300
+
301
+ ### Workflow of a ReAct Agent
302
+
303
+ The following state diagram shows the core workflow of a QuantaLogic agent:
304
+
305
+ ```mermaid
306
+ stateDiagram-v2
307
+ [*] --> InitializeAgent
308
+ InitializeAgent --> Idle: Agent Initialized
309
+
310
+ state Idle {
311
+ [*] --> WaitForTask
312
+ WaitForTask --> SolveTask: Task Received
313
+ }
314
+
315
+ state SolveTask {
316
+ [*] --> ResetSession
317
+ ResetSession --> AddSystemPrompt
318
+ AddSystemPrompt --> PreparePrompt
319
+ PreparePrompt --> EmitTaskStartEvent
320
+ EmitTaskStartEvent --> UpdateTokens
321
+ UpdateTokens --> CompactMemoryIfNeeded
322
+ CompactMemoryIfNeeded --> GenerateResponse
323
+ GenerateResponse --> ObserveResponse
324
+ ObserveResponse --> CheckToolExecution
325
+ CheckToolExecution --> TaskComplete: Tool Executed (task_complete)
326
+ CheckToolExecution --> UpdatePrompt: Tool Not Executed
327
+ UpdatePrompt --> UpdateTokens
328
+ TaskComplete --> EmitTaskCompleteEvent
329
+ EmitTaskCompleteEvent --> [*]
330
+ }
331
+
332
+ state CompactMemoryIfNeeded {
333
+ [*] --> CheckMemoryOccupancy
334
+ CheckMemoryOccupancy --> CompactMemory: Memory Occupancy > MAX_OCCUPANCY
335
+ CheckMemoryOccupancy --> [*]: Memory Occupancy <= MAX_OCCUPANCY
336
+ CompactMemory --> [*]
337
+ }
338
+
339
+ state ObserveResponse {
340
+ [*] --> ProcessResponse
341
+ ProcessResponse --> ExecuteTool: Tool Identified
342
+ ProcessResponse --> UpdateAnswer: No Tool Identified
343
+ ExecuteTool --> UpdateAnswer
344
+ UpdateAnswer --> [*]
345
+ }
346
+
347
+
348
+
349
+ Idle --> [*]: Task Completed
350
+ SolveTask --> Idle: Task Completed
351
+ ```
352
+
353
+ The following sequence diagram illustrates the workflow of a ReAct agent as it processes and solves a task:
354
+
355
+ ```mermaid
356
+ sequenceDiagram
357
+ participant User
358
+ participant Agent
359
+ participant ToolManager
360
+ participant Memory
361
+
362
+ User->>Agent: Submit task
363
+ Agent->>Memory: Store task details
364
+ Agent->>ToolManager: Retrieve tools
365
+ ToolManager-->>Agent: Provide available tools
366
+ Agent->>Agent: Prepare prompt for task
367
+ Agent->>Agent: Analyze input and generate response
368
+ Agent->>ToolManager: Execute required tool
369
+ ToolManager-->>Agent: Return tool execution result
370
+ Agent->>User: Present final result
371
+ ```
372
+
373
+ ### Key Components Explained
374
+
375
+ 1. **User Input**: The agent begins by receiving a task or question from the user, which initiates the interaction.
376
+ 2. **Memory Management**: Before tackling the task, the agent logs relevant task details into its memory, ensuring it has the necessary context for processing.
377
+ 3. **Tool Retrieval**: The agent communicates with the ToolManager to inquire about available tools that can facilitate the required actions.
378
+ 4. **Prompt Generation**: The agent constructs a prompt that outlines the task specifics, available tools, and any other pertinent context information.
379
+ 5. **Analysis and Response Generation**: The agent uses its generative model to analyze the task input and formulate a response.
380
+ 6. **Tool Execution**: If certain tools are needed for the task, the agent instructs the ToolManager to execute those tools, fetching the results for processing.
381
+ 7. **Output to User**: Finally, the agent compiles and presents the results back to the user.
382
+
383
+ ### Tool System
384
+
385
+ The QuantaLogic framework incorporates a well-defined tool system that enhances the functionality of AI agents by enabling them to perform a variety of tasks efficiently. Each tool is designed to address specific needs that arise in the context of complex problem-solving and task execution:
386
+
387
+ 1. **Core Functionality**: Tools such as **AgentTool** and **LLMTool** are fundamental to the agent's operation, allowing it to manage tasks and interact with large language models. The integration of these tools enables the agent to process natural language inputs and execute corresponding actions effectively. **AgentTool** enables the agent to delegate tasks to specialized agents, and **LLMTool** provides the agent to explore a specific area of a latent space using role play.
388
+
389
+ 2. **Code Execution**: Tools like **PythonTool**, **NodeJsTool**, and **ElixirTool** are vital for executing code in different programming languages. This capability allows the agent to handle programming tasks directly, facilitating real-time coding assistance and code evaluation.
390
+
391
+ 3. **File Operations**: The framework includes tools for file management, such as **ReadFileTool**, **WriteFileTool**, and **ReplaceInFileTool**. These tools are essential for enabling the agent to read from and write to files, as well as update file content dynamically. This functionality supports scenarios where agents need to manipulate data or configuration files as part of the task execution process.
392
+
393
+ 4. **Search Capabilities**: Tools like **RipgrepTool** and **SearchDefinitionNames** enhance the agent's ability to search through codebases and identify relevant definitions. This is crucial when dealing with large volumes of code, allowing the agent to quickly locate information necessary for problem-solving.
394
+
395
+ 5. **Utility Functions**: Additional tools such as **DownloadHttpFileTool**, **ListDirectoryTool**, and **ExecuteBashCommandTool** provide broader functionality that supports various tasks, from fetching external resources to executing system commands. These utilities expand the operational scope of agents, allowing them to perform diverse actions beyond simple text processing.
396
+
397
+ 6. **Documentation and Representation**: Tools like **MarkitdownTool** facilitate the generation of documentation, ensuring that output from the agent can be formatted and presented clearly. This is particularly beneficial for creating reports or guides based on the agent's findings and actions.
398
+
399
+ By integrating these tools into its architecture, QuantaLogic allows agents to perform a wide range of tasks autonomously while ensuring that they have the necessary resources and capabilities to do so effectively. This tool system is fundamental to the agent's ability to reason and act in sophisticated ways, thereby enhancing the overall utility of the framework in complex scenarios.
400
+
401
+
402
+
403
+ ### Tools Documentation
404
+
405
+ #### Overview of Tools
406
+
407
+ | Category | Tools |
408
+ |-----------------------|---------------------------------------------------------------------------------------------------|
409
+ | Task Automation | Agent Tool, Task Complete Tool, Input Question Tool, Execute Bash Command Tool |
410
+ | Script Execution | Python Tool, Node.js Tool, Elixir Tool |
411
+ | File Operations | Read File Tool, Write File Tool, Edit Whole Content Tool, Replace In File Tool |
412
+ | Code Analysis | Search Definition Names Tool, Ripgrep Tool |
413
+ | Content Generation | LLM Tool |
414
+ | Utility and Management | Download HTTP File Tool, List Directory Tool, Markitdown Tool, Unified Diff Tool |
415
+
416
+ ---
417
+
418
+ #### 1. Agent Tool
419
+
420
+ The **Agent Tool** enables task delegation to another agent, providing specialized functionality for handling tasks.
421
+
422
+ ##### Parameters
423
+
424
+ | Parameter | Type | Description | Example |
425
+ |--------------|--------|-------------------------------------------------------------------------------------|---------------------------------|
426
+ | `agent_role` | string | The role of the agent (e.g., expert, assistant) | `expert` |
427
+ | `agent` | Any | The agent to delegate tasks to | `Agent` object |
428
+ | `task` | string | The task to delegate to the specified agent. | `Summarize the latest news.` |
429
+
430
+ ##### Example Usage
431
+ ```python
432
+ agent_tool = AgentTool(agent_role="expert", agent=some_agent)
433
+ result = agent_tool.execute(task="Summarize the latest news.")
434
+ print(result)
435
+ ```
436
+
437
+ ---
438
+
439
+ #### 2. Task Complete Tool
440
+
441
+ The **Task Complete Tool** is used to respond to users after a task has been completed.
442
+
443
+ ##### Parameters
444
+
445
+ | Parameter | Type | Description | Example |
446
+ |-----------|--------|-------------------------------------------------|--------------------------------------|
447
+ | `answer` | string | The answer to the user. | `"The answer to the meaning of life"`|
448
+
449
+ ##### Example Usage
450
+ ```python
451
+ task_tool = TaskCompleteTool()
452
+ response = task_tool.execute(answer="The answer is 42.")
453
+ print(response)
454
+ ```
455
+
456
+ ---
457
+
458
+ #### 3. Input Question Tool
459
+
460
+ The **Input Question Tool** prompts the user with a question and captures their input.
461
+
462
+ ##### Parameters
463
+
464
+ | Parameter | Type | Description | Example |
465
+ |-----------|--------|-----------------------------------------------------|-------------------------------|
466
+ | `question`| string | The question to ask the user. | `What is your favorite color?`|
467
+ | `default` | string | Optional default value if no input is provided. | `blue` |
468
+
469
+ ##### Example Usage
470
+ ```python
471
+ input_tool = InputQuestionTool()
472
+ user_response = input_tool.execute(question="What is your favorite color?", default="blue")
473
+ print("User Response:", user_response)
474
+ ```
475
+
476
+ ---
477
+
478
+ #### 4. Execute Bash Command Tool
479
+
480
+ The **Execute Bash Command Tool** allows for the execution of bash commands and captures their output.
481
+
482
+ ##### Parameters
483
+
484
+ | Parameter | Type | Description | Example |
485
+ |-----------------|---------|----------------------------------------------------------------------|---------------------------|
486
+ | `command` | string | The bash command to execute. | `ls -la` |
487
+ | `working_dir` | string | The working directory where the command will be executed. | `/path/to/directory` |
488
+ | `timeout` | int | Maximum time in seconds to wait for the command to complete. | `60` |
489
+
490
+ ##### Example Usage
491
+ ```python
492
+ bash_tool = ExecuteBashCommandTool()
493
+ output = bash_tool.execute(command="ls -la")
494
+ print(output)
495
+ ```
496
+
497
+ ---
498
+
499
+ #### 5. Python Tool
500
+
501
+ The **Python Tool** executes Python scripts in an isolated Docker environment.
502
+
503
+ ##### Parameters
504
+
505
+ | Parameter | Type | Description | Example |
506
+ |-------------------|---------|------------------------------------------------------------------------------------|--------------------------------------------|
507
+ | `install_commands` | string | Commands to install Python packages before running the script. | `pip install rich requests` |
508
+ | `script` | string | The Python script to execute. | `print("Hello, World!")` |
509
+ | `version` | string | The Python version to use in the Docker container. | `3.11` |
510
+ | `host_dir` | string | The absolute path on the host machine to mount for file access. | `./demo01/` |
511
+ | `memory_limit` | string | Optional memory limit for the Docker container. | `1g` |
512
+ | `environment_vars`| string | Environment variables to set inside the Docker container. | `ENV=production DEBUG=False` |
513
+
514
+ #### Example Usage
515
+ ```python
516
+ python_tool = PythonTool()
517
+ output = python_tool.execute(
518
+ install_commands="pip install rich requests",
519
+ script='print("Hello, World!")',
520
+ version="3.12",
521
+ host_dir="./demo01/",
522
+ )
523
+ print("Script Output:", output)
524
+ ```
525
+
526
+ ---
527
+
528
+ ### 6. Node.js Tool
529
+
530
+ The **Node.js Tool** executes Node.js scripts in an isolated Docker environment.
531
+
532
+ #### Parameters
533
+
534
+ | Parameter | Type | Description | Example |
535
+ |-------------------|---------|-------------------------------------------------------------------------------|--------------------------------------------|
536
+ | `install_commands`| string | Commands to install Node.js packages before running the script. | `npm install chalk` |
537
+ | `script` | string | The Node.js script to execute. | `console.log('Hello, World!');` |
538
+ | `version` | string | The Node.js version to use in the Docker container. | `20` |
539
+ | `host_dir` | string | The absolute path on the host machine to mount for file access. | `./project/` |
540
+ | `memory_limit` | string | Optional memory limit for the Docker container. | `1g` |
541
+ | `module_type` | string | The module system to use: 'esm' for ECMAScript Modules or 'commonjs' for CommonJS. | `esm` |
542
+
543
+ #### Example Usage
544
+ ```python
545
+ node_tool = NodeJsTool()
546
+ output = node_tool.execute(
547
+ install_commands="npm install chalk",
548
+ script='console.log("Hello, Node.js World!");',
549
+ version="20",
550
+ host_dir="./project/"
551
+ )
552
+ print("Node.js Output:", output)
553
+ ```
554
+
555
+ ---
556
+
557
+ ### 7. Elixir Tool
558
+
559
+ The **Elixir Tool** executes Elixir code in an isolated Docker environment with Mix support.
560
+
561
+ #### Parameters
562
+
563
+ | Parameter | Type | Description | Example |
564
+ |------------------|---------|-----------------------------------------------------------------------------|-------------------------------------------|
565
+ | `mix_commands` | string | Mix commands to run before executing the script. | `mix deps.get && mix compile` |
566
+ | `script` | string | Elixir code to execute. | `IO.puts("Hello from Elixir!")` |
567
+ | `version` | string | The Elixir version to use. | `1.15` |
568
+ | `host_dir` | string | Host directory to mount. | `./elixir_project/` |
569
+ | `memory_limit` | string | Container memory limit. | `512m` |
570
+ | `environment_vars`| string | Environment variables to set. | `MIX_ENV=prod` |
571
+
572
+ #### Example Usage
573
+ ```python
574
+ elixir_tool = ElixirTool()
575
+ output = elixir_tool.execute(script='IO.puts("Hello from Elixir!")')
576
+ print("Elixir Output:", output)
577
+ ```
578
+
579
+ ---
580
+
581
+ ### 8. Read File Tool
582
+
583
+ The **Read File Tool** reads content from a specified file.
584
+
585
+ #### Parameters
586
+
587
+ | Parameter | Type | Description | Example |
588
+ |--------------|--------|-------------------------------------------------|--------------------------------------|
589
+ | `file_path` | string | The path of the file to read. | `/path/to/file.txt` |
590
+
591
+ #### Example Usage
592
+ ```python
593
+ read_tool = ReadFileTool()
594
+ content = read_tool.execute(file_path="/path/to/file.txt")
595
+ print("File Content:", content)
596
+ ```
597
+
598
+ ---
599
+
600
+ ### 9. Write File Tool
601
+
602
+ The **Write File Tool** writes content to a specified file.
603
+
604
+ #### Parameters
605
+
606
+ | Parameter | Type | Description | Example |
607
+ |-------------|--------|-------------------------------------------------|--------------------------------------|
608
+ | `file_path` | string | The path of the file to write to. | `/path/to/file.txt` |
609
+ | `content` | string | The content to write. | `Hello, World!` |
610
+
611
+ #### Example Usage
612
+ ```python
613
+ write_tool = WriteFileTool()
614
+ result = write_tool.execute(file_path="/path/to/file.txt", content="Hello, World!")
615
+ print(result)
616
+ ```
617
+
618
+ ---
619
+
620
+ ### 10. Edit Whole Content Tool
621
+
622
+ The **Edit Whole Content Tool** replaces the entire content of a specified file.
623
+
624
+ #### Parameters
625
+
626
+ | Parameter | Type | Description | Example |
627
+ |-------------|--------|-------------------------------------------------|--------------------------------------|
628
+ | `file_path` | string | The path to the file to edit. | `/path/to/file.txt` |
629
+ | `content` | string | The new content to write to the file. | `New Content Here!` |
630
+
631
+ #### Example Usage
632
+ ```python
633
+ edit_tool = EditWholeContentTool()
634
+ result = edit_tool.execute(file_path="/path/to/file.txt", content="New Content Here!")
635
+ print(result)
636
+ ```
637
+
638
+ ---
639
+
640
+ ### 11. Replace In File Tool
641
+
642
+ The **Replace In File Tool** replaces specific content in a file with new content.
643
+
644
+ #### Parameters
645
+
646
+ | Parameter | Type | Description | Example |
647
+ |-------------|--------|-------------------------------------------------|--------------------------------------|
648
+ | `file_path` | string | The path of the file to edit. | `/path/to/file.txt` |
649
+ | `search` | string | The string to search for in the file. | `Old Content` |
650
+ | `replace` | string | The string to replace the searched content. | `New Content` |
651
+
652
+ #### Example Usage
653
+ ```python
654
+ replace_tool = ReplaceInFileTool()
655
+ result = replace_tool.execute(file_path="/path/to/file.txt", search="Old Content", replace="New Content")
656
+ print(result)
657
+ ```
658
+
659
+ ---
660
+
661
+ ### 12. Search Definition Names Tool
662
+
663
+ The **Search Definition Names Tool** searches for definition names in a directory using Tree-sitter.
664
+
665
+ #### Parameters
666
+
667
+ | Parameter | Type | Description | Example |
668
+ |----------------|--------|-----------------------------------------------------------|-------------------------------|
669
+ | `directory_path`| string | The path to the directory to search in. | `./path/to` |
670
+ | `language_name`| string | The Tree-sitter language name (python, js, etc.). | `python` |
671
+ | `file_pattern` | string | Optional glob pattern to filter files (default: '*'). | `**/*.py` |
672
+
673
+ #### Example Usage
674
+ ```python
675
+ search_tool = SearchDefinitionNames()
676
+ results = search_tool.execute(directory_path="./my_project", language_name="python", file_pattern="**/*.py")
677
+ print("Found Definitions:", results)
678
+ ```
679
+
680
+ ---
681
+
682
+ ### 13. Ripgrep Tool
683
+
684
+ The **Ripgrep Tool** searches for text blocks in files using ripgrep.
685
+
686
+ #### Parameters
687
+
688
+ | Parameter | Type | Description | Example |
689
+ |------------------|---------|------------------------------------------------------------------------------|-------------------------------|
690
+ | `cwd` | string | Base path for relative searches | `.` |
691
+ | `directory_path` | string | The directory path to search in. | `./src` |
692
+ | `regex_rust_syntax`| string| The regex pattern to search for (in Rust syntax). | `r"\bfunction\b"` |
693
+ | `file_pattern` | string | Optional glob pattern to filter files. | `**/*.js` |
694
+ | `context_lines` | string | Number of context lines to include before and after matches. | `2` |
695
+
696
+ #### Example Usage
697
+ ```python
698
+ ripgrep_tool = RipgrepTool()
699
+ output = ripgrep_tool.execute(
700
+ directory_path="./my_project",
701
+ regex_rust_syntax=r"\bfunction\b",
702
+ context_lines="2"
703
+ )
704
+ print("Ripgrep Results:", output)
705
+ ```
706
+
707
+ ---
708
+
709
+ ### 14. LLM Tool
710
+
711
+ The **LLM Tool** generates answers using a specified language model.
712
+
713
+ #### Parameters
714
+
715
+ | Parameter | Type | Description | Example |
716
+ |----------------|---------|------------------------------------------------------------------------|--------------------------------------------|
717
+ | `system_prompt`| string | The persona or system prompt to guide the language model's behavior. | `You are a helpful assistant.` |
718
+ | `prompt` | string | The question to ask the language model. | `What is the meaning of life?` |
719
+ | `temperature` | string | Sampling temperature between 0.0 and 1.0. | `0.5` |
720
+
721
+ #### Example Usage
722
+ ```python
723
+ llm_tool = LLMTool(model_name="gpt-4")
724
+ response = llm_tool.execute(
725
+ system_prompt="You are a knowledgeable assistant.",
726
+ prompt="What is the meaning of life?",
727
+ temperature="0.7"
728
+ )
729
+ print("LLM Response:", response)
730
+ ```
731
+
732
+ ---
733
+
734
+ ### 15. Download HTTP File Tool
735
+
736
+ The **Download HTTP File Tool** downloads a file from a specified HTTP URL.
737
+
738
+ #### Parameters
739
+
740
+ | Parameter | Type | Description | Example |
741
+ |---------------|--------|------------------------------------------------|------------------------------------|
742
+ | `url` | string | The URL of the file to download. | `http://example.com/file.txt` |
743
+ | `destination` | string | The path where the file should be saved. | `/path/to/save/file.txt` |
744
+
745
+ #### Example Usage
746
+ ```python
747
+ download_tool = DownloadHttpFileTool()
748
+ result = download_tool.execute(url="http://example.com/file.txt", destination="/path/to/save/file.txt")
749
+ print(result)
750
+ ```
751
+
752
+ ---
753
+
754
+ ### 16. List Directory Tool
755
+
756
+ The **List Directory Tool** lists files in a specified directory.
757
+
758
+ #### Parameters
759
+
760
+ | Parameter | Type | Description | Example |
761
+ |------------------|---------|------------------------------------------------|------------------------|
762
+ | `directory_path` | string | The path of the directory to list files from. | `./path/to/directory` |
763
+
764
+ #### Example Usage
765
+ ```python
766
+ list_tool = ListDirectoryTool()
767
+ result = list_tool.execute(directory_path="./path/to/directory")
768
+ print("Directory Files:", result)
769
+ ```
770
+
771
+ ---
772
+
773
+ ### 17. Markitdown Tool
774
+
775
+ The **Markitdown Tool** processes markdown files, possibly for conversion or rendering.
776
+
777
+ #### Parameters
778
+
779
+ | Parameter | Type | Description | Example |
780
+ |------------------|---------|------------------------------------------------|------------------------|
781
+ | `markdown_path` | string | The path of the markdown file to process. | `./path/to/file.md` |
782
+
783
+ #### Example Usage
784
+ ```python
785
+ markitdown_tool = MarkitdownTool()
786
+ result = markitdown_tool.execute(markdown_path="./path/to/file.md")
787
+ print("Processed Markdown Output:", result)
788
+ ```
789
+
790
+ ---
791
+
792
+ ### 18. Unified Diff Tool
793
+
794
+ The **Unified Diff Tool** generates a unified diff between two texts or files.
795
+
796
+ #### Parameters
797
+
798
+ | Parameter | Type | Description | Example |
799
+ |--------------|--------|------------------------------------------------|------------------------|
800
+ | `original` | string | The original content or file path. | `old_text.txt` |
801
+ | `updated` | string | The updated content or file path. | `new_text.txt` |
802
+
803
+ #### Example Usage
804
+ ```python
805
+ diff_tool = UnifiedDiffTool()
806
+ result = diff_tool.execute(original="old_text.txt", updated="new_text.txt")
807
+ print("Unified Diff Output:", result)
808
+ ```
809
+
810
+
811
+ #### Creating Custom Tools
812
+
813
+ ```python
814
+ from quantalogic.tools import Tool, ToolArgument
815
+
816
+ class DatabaseTool(Tool):
817
+ name: str = "database_tool"
818
+ description: str = "Execute database operations"
819
+ need_validation: bool = True
820
+
821
+ arguments: list[ToolArgument] = [
822
+ ToolArgument(
823
+ name="query",
824
+ arg_type="string",
825
+ description="SQL query to execute",
826
+ required=True
827
+ )
828
+ ]
829
+
830
+ def execute(self, query: str) -> str:
831
+ # Tool implementation
832
+ return "Query results"
833
+ ```
834
+
835
+
836
+ ## 🌐 Web Interface
837
+
838
+ Features:
839
+ - Real-time event visualization
840
+ - Task submission and monitoring
841
+ - Interactive validation dialogs
842
+ - Model selection
843
+ - Event filtering and search
844
+
845
+ ### API Endpoints
846
+
847
+ | Endpoint | Method | Description |
848
+ | ------------------ | ------ | --------------- |
849
+ | `/tasks` | POST | Submit tasks |
850
+ | `/tasks/{task_id}` | GET | Task status |
851
+ | `/events` | GET | SSE endpoint |
852
+ | `/validate` | POST | Task validation |
853
+
854
+
855
+ ## 📖 Examples
856
+
857
+ ### Python Tool Integration Example
858
+
859
+ ```python
860
+ import os
861
+
862
+ from quantalogic import Agent, console_print_events
863
+ from quantalogic.tools import (
864
+ PythonTool,
865
+ )
866
+
867
+ # Verify API key is set - required for authentication with DeepSeek's API
868
+ # This check ensures the agent won't fail during runtime due to missing credentials
869
+ if not os.environ.get("DEEPSEEK_API_KEY"):
870
+ raise ValueError("DEEPSEEK_API_KEY environment variable is not set")
871
+
872
+ # Initialize agent with DeepSeek model and Python tool
873
+ agent = Agent(model_name="deepseek/deepseek-chat", tools=[PythonTool()])
874
+
875
+ # Configure comprehensive event monitoring system
876
+ # Tracks all agent activities including:
877
+ # - Code execution steps
878
+ # - Tool interactions
879
+ # - Error conditions
880
+ # Essential for debugging and performance optimization
881
+ agent.event_emitter.on(
882
+ "*",
883
+ console_print_events,
884
+ )
885
+
886
+ # Execute a precision mathematics task demonstrating:
887
+ # - High-precision calculations
888
+ # - PythonTool integration
889
+ # - Real-time monitoring capabilities
890
+ result = agent.solve_task("1. Calculate PI with 10000 decimal places.")
891
+ print(result)
892
+ ```
893
+
894
+ ### Agent with Event Monitoring
895
+
896
+ ```python
897
+ import os
898
+
899
+ from quantalogic import Agent, console_print_events
900
+ from quantalogic.tools import (
901
+ LLMTool,
902
+ )
903
+
904
+ # Verify API key is set - required for authentication with DeepSeek's API
905
+ # This check ensures the agent won't fail during runtime due to missing credentials
906
+ if not os.environ.get("DEEPSEEK_API_KEY"):
907
+ raise ValueError("DEEPSEEK_API_KEY environment variable is not set")
908
+
909
+ # Initialize agent with DeepSeek model and LLM tool
910
+ # The LLM tool serves dual purpose:
911
+ # 1. As a reasoning engine for the agent's cognitive processes
912
+ # 2. As a latent space explorer, enabling the agent to:
913
+ # - Discover novel solution paths
914
+ # - Generate creative combinations of concepts
915
+ # - Explore alternative reasoning strategies
916
+ # Using the same model ensures consistent behavior across both roles
917
+ agent = Agent(model_name="deepseek/deepseek-chat", tools=[LLMTool(model_name="deepseek/deepseek-chat")])
918
+
919
+ # Set up event monitoring to track agent's lifecycle
920
+ # This helps in debugging and understanding the agent's behavior
921
+ agent.event_emitter.on(
922
+ [
923
+ "task_complete",
924
+ "task_think_start",
925
+ "task_think_end",
926
+ "tool_execution_start",
927
+ "tool_execution_end",
928
+ "error_max_iterations_reached",
929
+ "memory_full",
930
+ "memory_compacted",
931
+ "memory_summary",
932
+ ],
933
+ console_print_events,
934
+ )
935
+
936
+ # Execute a multi-step task showcasing agent's capabilities
937
+ # Demonstrates:
938
+ # 1. Creative content generation
939
+ # 2. Language translation
940
+ # 3. Style adaptation
941
+ # 4. Multi-step reasoning and execution
942
+ result = agent.solve_task(
943
+ "1. Write a poem in English about a dog. "
944
+ "2. Translate the poem into French. "
945
+ "3. Choose 2 French authors"
946
+ "4. Rewrite the translated poem with the style of the chosen authors. "
947
+ )
948
+ print(result)
949
+ ```
950
+
951
+
952
+
953
+ ### Project Documentation
954
+
955
+ ```python
956
+ from quantalogic import Agent
957
+ from quantalogic.tools import MarkitdownTool, ReadFileTool
958
+
959
+ agent = Agent(
960
+ model_name="openrouter/deepseek-chat",
961
+ tools=[MarkitdownTool(), ReadFileTool()]
962
+ )
963
+
964
+ result = agent.solve_task("""
965
+ Generate a comprehensive documentation for:
966
+
967
+ 1. Navigate and Read https://api.nasa.gov/ documentation
968
+ 2. Write an API reference for https://api.nasa.gov/
969
+ 2. Examples how to use the API using curl
970
+ 3. Examples how to use the API from Python
971
+ """)
972
+ ```
973
+
974
+
975
+ ## 🔧 Development
976
+
977
+ ### Setup Development Environment
978
+
979
+ ```bash
980
+ # Clone repository
981
+ git clone https://github.com/quantalogic/quantalogic.git
982
+ cd quantalogic
983
+
984
+ # Create virtual environment
985
+ python -m venv venv
986
+ source venv/bin/activate # Windows: venv\Scripts\activate
987
+
988
+ # Install dependencies
989
+ poetry install
990
+
991
+ ```
992
+
993
+ ### Run Tests
994
+
995
+ ```bash
996
+ # Run all tests
997
+ pytest
998
+
999
+ # With coverage
1000
+ pytest --cov=quantalogic
1001
+
1002
+ # Run specific tests
1003
+ pytest tests/unit
1004
+ ```
1005
+
1006
+ ### Code Quality
1007
+
1008
+ ```bash
1009
+ # Format code
1010
+ ruff format
1011
+
1012
+ # Type checking
1013
+ mypy quantalogic
1014
+
1015
+ # Linting
1016
+ ruff check quantalogic
1017
+ ```
1018
+
1019
+ ## 🤝 Contributing
1020
+
1021
+ 1. Fork the repository
1022
+ 2. Create a feature branch
1023
+ 3. Write tests
1024
+ 4. Implement changes
1025
+ 5. Submit pull request
1026
+
1027
+ See [CONTRIBUTING.md](CONTRIBUTING.md) for detailed guidelines.
1028
+
1029
+ ## 📄 License
1030
+
1031
+ Copyright 2024 QuantaLogic Contributors
1032
+
1033
+ Licensed under the Apache License, Version 2.0. See [LICENSE](LICENSE) for details.
1034
+