quantalogic 0.32.0__tar.gz → 0.33.0__tar.gz
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.
- {quantalogic-0.32.0 → quantalogic-0.33.0}/PKG-INFO +1 -1
- {quantalogic-0.32.0 → quantalogic-0.33.0}/pyproject.toml +1 -1
- {quantalogic-0.32.0 → quantalogic-0.33.0}/quantalogic/agent.py +71 -53
- {quantalogic-0.32.0 → quantalogic-0.33.0}/quantalogic/generative_model.py +7 -3
- {quantalogic-0.32.0 → quantalogic-0.33.0}/quantalogic/llm.py +6 -0
- {quantalogic-0.32.0 → quantalogic-0.33.0}/quantalogic/model_info_list.py +5 -2
- quantalogic-0.33.0/quantalogic/prompts.py +116 -0
- {quantalogic-0.32.0 → quantalogic-0.33.0}/quantalogic/tools/replace_in_file_tool.py +1 -0
- quantalogic-0.32.0/quantalogic/prompts.py +0 -119
- {quantalogic-0.32.0 → quantalogic-0.33.0}/LICENSE +0 -0
- {quantalogic-0.32.0 → quantalogic-0.33.0}/README.md +0 -0
- {quantalogic-0.32.0 → quantalogic-0.33.0}/quantalogic/__init__.py +0 -0
- {quantalogic-0.32.0 → quantalogic-0.33.0}/quantalogic/agent_config.py +0 -0
- {quantalogic-0.32.0 → quantalogic-0.33.0}/quantalogic/agent_factory.py +0 -0
- {quantalogic-0.32.0 → quantalogic-0.33.0}/quantalogic/coding_agent.py +0 -0
- {quantalogic-0.32.0 → quantalogic-0.33.0}/quantalogic/config.py +0 -0
- {quantalogic-0.32.0 → quantalogic-0.33.0}/quantalogic/console_print_events.py +0 -0
- {quantalogic-0.32.0 → quantalogic-0.33.0}/quantalogic/console_print_token.py +0 -0
- {quantalogic-0.32.0 → quantalogic-0.33.0}/quantalogic/docs_cli.py +0 -0
- {quantalogic-0.32.0 → quantalogic-0.33.0}/quantalogic/event_emitter.py +0 -0
- {quantalogic-0.32.0 → quantalogic-0.33.0}/quantalogic/get_model_info.py +0 -0
- {quantalogic-0.32.0 → quantalogic-0.33.0}/quantalogic/interactive_text_editor.py +0 -0
- {quantalogic-0.32.0 → quantalogic-0.33.0}/quantalogic/main.py +0 -0
- {quantalogic-0.32.0 → quantalogic-0.33.0}/quantalogic/memory.py +0 -0
- {quantalogic-0.32.0 → quantalogic-0.33.0}/quantalogic/model_info.py +0 -0
- {quantalogic-0.32.0 → quantalogic-0.33.0}/quantalogic/model_info_litellm.py +0 -0
- {quantalogic-0.32.0 → quantalogic-0.33.0}/quantalogic/model_names.py +0 -0
- {quantalogic-0.32.0 → quantalogic-0.33.0}/quantalogic/search_agent.py +0 -0
- {quantalogic-0.32.0 → quantalogic-0.33.0}/quantalogic/server/__init__.py +0 -0
- {quantalogic-0.32.0 → quantalogic-0.33.0}/quantalogic/server/agent_server.py +0 -0
- {quantalogic-0.32.0 → quantalogic-0.33.0}/quantalogic/server/models.py +0 -0
- {quantalogic-0.32.0 → quantalogic-0.33.0}/quantalogic/server/routes.py +0 -0
- {quantalogic-0.32.0 → quantalogic-0.33.0}/quantalogic/server/state.py +0 -0
- {quantalogic-0.32.0 → quantalogic-0.33.0}/quantalogic/server/static/js/event_visualizer.js +0 -0
- {quantalogic-0.32.0 → quantalogic-0.33.0}/quantalogic/server/static/js/quantalogic.js +0 -0
- {quantalogic-0.32.0 → quantalogic-0.33.0}/quantalogic/server/templates/index.html +0 -0
- {quantalogic-0.32.0 → quantalogic-0.33.0}/quantalogic/task_file_reader.py +0 -0
- {quantalogic-0.32.0 → quantalogic-0.33.0}/quantalogic/task_runner.py +0 -0
- {quantalogic-0.32.0 → quantalogic-0.33.0}/quantalogic/tool_manager.py +0 -0
- {quantalogic-0.32.0 → quantalogic-0.33.0}/quantalogic/tools/__init__.py +0 -0
- {quantalogic-0.32.0 → quantalogic-0.33.0}/quantalogic/tools/agent_tool.py +0 -0
- {quantalogic-0.32.0 → quantalogic-0.33.0}/quantalogic/tools/dalle_e.py +0 -0
- {quantalogic-0.32.0 → quantalogic-0.33.0}/quantalogic/tools/download_http_file_tool.py +0 -0
- {quantalogic-0.32.0 → quantalogic-0.33.0}/quantalogic/tools/duckduckgo_search_tool.py +0 -0
- {quantalogic-0.32.0 → quantalogic-0.33.0}/quantalogic/tools/edit_whole_content_tool.py +0 -0
- {quantalogic-0.32.0 → quantalogic-0.33.0}/quantalogic/tools/elixir_tool.py +0 -0
- {quantalogic-0.32.0 → quantalogic-0.33.0}/quantalogic/tools/execute_bash_command_tool.py +0 -0
- {quantalogic-0.32.0 → quantalogic-0.33.0}/quantalogic/tools/generate_database_report_tool.py +0 -0
- {quantalogic-0.32.0 → quantalogic-0.33.0}/quantalogic/tools/grep_app_tool.py +0 -0
- {quantalogic-0.32.0 → quantalogic-0.33.0}/quantalogic/tools/input_question_tool.py +0 -0
- {quantalogic-0.32.0 → quantalogic-0.33.0}/quantalogic/tools/jinja_tool.py +0 -0
- {quantalogic-0.32.0 → quantalogic-0.33.0}/quantalogic/tools/language_handlers/__init__.py +0 -0
- {quantalogic-0.32.0 → quantalogic-0.33.0}/quantalogic/tools/language_handlers/c_handler.py +0 -0
- {quantalogic-0.32.0 → quantalogic-0.33.0}/quantalogic/tools/language_handlers/cpp_handler.py +0 -0
- {quantalogic-0.32.0 → quantalogic-0.33.0}/quantalogic/tools/language_handlers/go_handler.py +0 -0
- {quantalogic-0.32.0 → quantalogic-0.33.0}/quantalogic/tools/language_handlers/java_handler.py +0 -0
- {quantalogic-0.32.0 → quantalogic-0.33.0}/quantalogic/tools/language_handlers/javascript_handler.py +0 -0
- {quantalogic-0.32.0 → quantalogic-0.33.0}/quantalogic/tools/language_handlers/python_handler.py +0 -0
- {quantalogic-0.32.0 → quantalogic-0.33.0}/quantalogic/tools/language_handlers/rust_handler.py +0 -0
- {quantalogic-0.32.0 → quantalogic-0.33.0}/quantalogic/tools/language_handlers/scala_handler.py +0 -0
- {quantalogic-0.32.0 → quantalogic-0.33.0}/quantalogic/tools/language_handlers/typescript_handler.py +0 -0
- {quantalogic-0.32.0 → quantalogic-0.33.0}/quantalogic/tools/list_directory_tool.py +0 -0
- {quantalogic-0.32.0 → quantalogic-0.33.0}/quantalogic/tools/llm_tool.py +0 -0
- {quantalogic-0.32.0 → quantalogic-0.33.0}/quantalogic/tools/llm_vision_tool.py +0 -0
- {quantalogic-0.32.0 → quantalogic-0.33.0}/quantalogic/tools/markitdown_tool.py +0 -0
- {quantalogic-0.32.0 → quantalogic-0.33.0}/quantalogic/tools/nodejs_tool.py +0 -0
- {quantalogic-0.32.0 → quantalogic-0.33.0}/quantalogic/tools/python_tool.py +0 -0
- {quantalogic-0.32.0 → quantalogic-0.33.0}/quantalogic/tools/read_file_block_tool.py +0 -0
- {quantalogic-0.32.0 → quantalogic-0.33.0}/quantalogic/tools/read_file_tool.py +0 -0
- {quantalogic-0.32.0 → quantalogic-0.33.0}/quantalogic/tools/read_html_tool.py +0 -0
- {quantalogic-0.32.0 → quantalogic-0.33.0}/quantalogic/tools/ripgrep_tool.py +0 -0
- {quantalogic-0.32.0 → quantalogic-0.33.0}/quantalogic/tools/search_definition_names.py +0 -0
- {quantalogic-0.32.0 → quantalogic-0.33.0}/quantalogic/tools/serpapi_search_tool.py +0 -0
- {quantalogic-0.32.0 → quantalogic-0.33.0}/quantalogic/tools/sql_query_tool.py +0 -0
- {quantalogic-0.32.0 → quantalogic-0.33.0}/quantalogic/tools/task_complete_tool.py +0 -0
- {quantalogic-0.32.0 → quantalogic-0.33.0}/quantalogic/tools/tool.py +0 -0
- {quantalogic-0.32.0 → quantalogic-0.33.0}/quantalogic/tools/unified_diff_tool.py +0 -0
- {quantalogic-0.32.0 → quantalogic-0.33.0}/quantalogic/tools/utils/__init__.py +0 -0
- {quantalogic-0.32.0 → quantalogic-0.33.0}/quantalogic/tools/utils/create_sample_database.py +0 -0
- {quantalogic-0.32.0 → quantalogic-0.33.0}/quantalogic/tools/utils/generate_database_report.py +0 -0
- {quantalogic-0.32.0 → quantalogic-0.33.0}/quantalogic/tools/wikipedia_search_tool.py +0 -0
- {quantalogic-0.32.0 → quantalogic-0.33.0}/quantalogic/tools/write_file_tool.py +0 -0
- {quantalogic-0.32.0 → quantalogic-0.33.0}/quantalogic/utils/__init__.py +0 -0
- {quantalogic-0.32.0 → quantalogic-0.33.0}/quantalogic/utils/ask_user_validation.py +0 -0
- {quantalogic-0.32.0 → quantalogic-0.33.0}/quantalogic/utils/check_version.py +0 -0
- {quantalogic-0.32.0 → quantalogic-0.33.0}/quantalogic/utils/download_http_file.py +0 -0
- {quantalogic-0.32.0 → quantalogic-0.33.0}/quantalogic/utils/get_all_models.py +0 -0
- {quantalogic-0.32.0 → quantalogic-0.33.0}/quantalogic/utils/get_coding_environment.py +0 -0
- {quantalogic-0.32.0 → quantalogic-0.33.0}/quantalogic/utils/get_environment.py +0 -0
- {quantalogic-0.32.0 → quantalogic-0.33.0}/quantalogic/utils/get_quantalogic_rules_content.py +0 -0
- {quantalogic-0.32.0 → quantalogic-0.33.0}/quantalogic/utils/git_ls.py +0 -0
- {quantalogic-0.32.0 → quantalogic-0.33.0}/quantalogic/utils/lm_studio_model_info.py +0 -0
- {quantalogic-0.32.0 → quantalogic-0.33.0}/quantalogic/utils/read_file.py +0 -0
- {quantalogic-0.32.0 → quantalogic-0.33.0}/quantalogic/utils/read_http_text_content.py +0 -0
- {quantalogic-0.32.0 → quantalogic-0.33.0}/quantalogic/version.py +0 -0
- {quantalogic-0.32.0 → quantalogic-0.33.0}/quantalogic/version_check.py +0 -0
- {quantalogic-0.32.0 → quantalogic-0.33.0}/quantalogic/welcome_message.py +0 -0
- {quantalogic-0.32.0 → quantalogic-0.33.0}/quantalogic/xml_parser.py +0 -0
- {quantalogic-0.32.0 → quantalogic-0.33.0}/quantalogic/xml_tool_parser.py +0 -0
@@ -52,11 +52,7 @@ class ObserveResponseResult(BaseModel):
|
|
52
52
|
class Agent(BaseModel):
|
53
53
|
"""Enhanced QuantaLogic agent implementing ReAct framework."""
|
54
54
|
|
55
|
-
model_config = ConfigDict(
|
56
|
-
arbitrary_types_allowed=True,
|
57
|
-
validate_assignment=True,
|
58
|
-
extra="forbid"
|
59
|
-
)
|
55
|
+
model_config = ConfigDict(arbitrary_types_allowed=True, validate_assignment=True, extra="forbid")
|
60
56
|
|
61
57
|
specific_expertise: str
|
62
58
|
model: GenerativeModel
|
@@ -95,7 +91,7 @@ class Agent(BaseModel):
|
|
95
91
|
"""Initialize the agent with model, memory, tools, and configurations."""
|
96
92
|
try:
|
97
93
|
logger.debug("Initializing agent...")
|
98
|
-
|
94
|
+
|
99
95
|
# Create event emitter
|
100
96
|
event_emitter = EventEmitter()
|
101
97
|
|
@@ -142,9 +138,9 @@ class Agent(BaseModel):
|
|
142
138
|
compact_every_n_iterations=compact_every_n_iterations or 30,
|
143
139
|
max_tokens_working_memory=max_tokens_working_memory,
|
144
140
|
)
|
145
|
-
|
141
|
+
|
146
142
|
self._model_name = model_name
|
147
|
-
|
143
|
+
|
148
144
|
logger.debug(f"Memory will be compacted every {self.compact_every_n_iterations} iterations")
|
149
145
|
logger.debug(f"Max tokens for working memory set to: {self.max_tokens_working_memory}")
|
150
146
|
logger.debug("Agent initialized successfully.")
|
@@ -168,7 +164,9 @@ class Agent(BaseModel):
|
|
168
164
|
"""Clear the memory and reset the session."""
|
169
165
|
self._reset_session(clear_memory=True)
|
170
166
|
|
171
|
-
def solve_task(
|
167
|
+
def solve_task(
|
168
|
+
self, task: str, max_iterations: int = 30, streaming: bool = False, clear_memory: bool = True
|
169
|
+
) -> str:
|
172
170
|
"""Solve the given task using the ReAct framework.
|
173
171
|
|
174
172
|
Args:
|
@@ -182,7 +180,7 @@ class Agent(BaseModel):
|
|
182
180
|
str: The final response after task completion.
|
183
181
|
"""
|
184
182
|
logger.debug(f"Solving task... {task}")
|
185
|
-
self._reset_session(task_to_solve=task, max_iterations=max_iterations,clear_memory=clear_memory)
|
183
|
+
self._reset_session(task_to_solve=task, max_iterations=max_iterations, clear_memory=clear_memory)
|
186
184
|
|
187
185
|
# Generate task summary
|
188
186
|
self.task_to_solve_summary = self._generate_task_summary(task)
|
@@ -228,7 +226,9 @@ class Agent(BaseModel):
|
|
228
226
|
# For streaming, collect the response chunks
|
229
227
|
content = ""
|
230
228
|
for chunk in self.model.generate_with_history(
|
231
|
-
messages_history=self.memory.memory,
|
229
|
+
messages_history=self.memory.memory,
|
230
|
+
prompt=current_prompt,
|
231
|
+
streaming=True,
|
232
232
|
):
|
233
233
|
content += chunk
|
234
234
|
|
@@ -245,7 +245,8 @@ class Agent(BaseModel):
|
|
245
245
|
)
|
246
246
|
else:
|
247
247
|
result = self.model.generate_with_history(
|
248
|
-
messages_history=self.memory.memory, prompt=current_prompt, streaming=False
|
248
|
+
messages_history=self.memory.memory, prompt=current_prompt, streaming=False,
|
249
|
+
stop_words=["thinking"]
|
249
250
|
)
|
250
251
|
|
251
252
|
content = result.response
|
@@ -296,7 +297,7 @@ class Agent(BaseModel):
|
|
296
297
|
|
297
298
|
return answer
|
298
299
|
|
299
|
-
def _reset_session(self, task_to_solve: str = "", max_iterations: int = 30,clear_memory: bool = True):
|
300
|
+
def _reset_session(self, task_to_solve: str = "", max_iterations: int = 30, clear_memory: bool = True):
|
300
301
|
"""Reset the agent's session."""
|
301
302
|
logger.debug("Resetting session...")
|
302
303
|
self.task_to_solve = task_to_solve
|
@@ -316,29 +317,30 @@ class Agent(BaseModel):
|
|
316
317
|
def _compact_memory_if_needed(self, current_prompt: str = ""):
|
317
318
|
"""Compacts the memory if it exceeds the maximum occupancy or token limit."""
|
318
319
|
ratio_occupied = self._calculate_context_occupancy()
|
319
|
-
|
320
|
+
|
320
321
|
# Compact memory if any of these conditions are met:
|
321
322
|
# 1. Memory occupancy exceeds MAX_OCCUPANCY, or
|
322
323
|
# 2. Current iteration is a multiple of compact_every_n_iterations, or
|
323
324
|
# 3. Working memory exceeds max_tokens_working_memory (if set)
|
324
325
|
should_compact_by_occupancy = ratio_occupied >= MAX_OCCUPANCY
|
325
326
|
should_compact_by_iteration = (
|
326
|
-
self.compact_every_n_iterations is not None
|
327
|
-
self.current_iteration > 0
|
328
|
-
self.current_iteration % self.compact_every_n_iterations == 0
|
327
|
+
self.compact_every_n_iterations is not None
|
328
|
+
and self.current_iteration > 0
|
329
|
+
and self.current_iteration % self.compact_every_n_iterations == 0
|
329
330
|
)
|
330
331
|
should_compact_by_token_limit = (
|
331
|
-
self.max_tokens_working_memory is not None and
|
332
|
-
self.total_tokens > self.max_tokens_working_memory
|
332
|
+
self.max_tokens_working_memory is not None and self.total_tokens > self.max_tokens_working_memory
|
333
333
|
)
|
334
|
-
|
334
|
+
|
335
335
|
if should_compact_by_occupancy or should_compact_by_iteration or should_compact_by_token_limit:
|
336
336
|
if should_compact_by_occupancy:
|
337
337
|
logger.debug(f"Memory compaction triggered: Occupancy {ratio_occupied}% exceeds {MAX_OCCUPANCY}%")
|
338
|
-
|
338
|
+
|
339
339
|
if should_compact_by_iteration:
|
340
|
-
logger.debug(
|
341
|
-
|
340
|
+
logger.debug(
|
341
|
+
f"Memory compaction triggered: Iteration {self.current_iteration} is a multiple of {self.compact_every_n_iterations}"
|
342
|
+
)
|
343
|
+
|
342
344
|
self._emit_event("memory_full")
|
343
345
|
self.memory.compact()
|
344
346
|
self.total_tokens = self.model.token_counter_with_history(self.memory.memory, current_prompt)
|
@@ -399,7 +401,7 @@ class Agent(BaseModel):
|
|
399
401
|
return self._handle_tool_execution_failure(response)
|
400
402
|
|
401
403
|
variable_name = self.variable_store.add(response)
|
402
|
-
new_prompt = self._format_observation_response(response, variable_name, iteration)
|
404
|
+
new_prompt = self._format_observation_response(response, executed_tool, variable_name, iteration)
|
403
405
|
|
404
406
|
return ObserveResponseResult(
|
405
407
|
next_prompt=new_prompt,
|
@@ -414,7 +416,7 @@ class Agent(BaseModel):
|
|
414
416
|
"""Extract tool usage from the response content."""
|
415
417
|
if not content or not isinstance(content, str):
|
416
418
|
return {}
|
417
|
-
|
419
|
+
|
418
420
|
xml_parser = ToleranceXMLParser()
|
419
421
|
tool_names = self.tools.tool_names()
|
420
422
|
return xml_parser.extract_elements(text=content, element_names=tool_names)
|
@@ -461,7 +463,7 @@ class Agent(BaseModel):
|
|
461
463
|
answer=None,
|
462
464
|
)
|
463
465
|
|
464
|
-
def _handle_repeated_tool_call(self, tool_name: str, arguments_with_values: dict) -> (str,str):
|
466
|
+
def _handle_repeated_tool_call(self, tool_name: str, arguments_with_values: dict) -> (str, str):
|
465
467
|
"""Handle the case where a tool call is repeated."""
|
466
468
|
repeat_count = self.last_tool_call.get("count", 0)
|
467
469
|
error_message = (
|
@@ -494,7 +496,9 @@ class Agent(BaseModel):
|
|
494
496
|
answer=None,
|
495
497
|
)
|
496
498
|
|
497
|
-
def _format_observation_response(
|
499
|
+
def _format_observation_response(
|
500
|
+
self, response: str, last_exectured_tool: str, variable_name: str, iteration: int
|
501
|
+
) -> str:
|
498
502
|
"""Format the observation response with the given response, variable name, and iteration."""
|
499
503
|
response_display = response
|
500
504
|
if len(response) > MAX_RESPONSE_LENGTH:
|
@@ -504,29 +508,45 @@ class Agent(BaseModel):
|
|
504
508
|
)
|
505
509
|
|
506
510
|
# Format the response message
|
507
|
-
formatted_response = (
|
508
|
-
|
509
|
-
f"
|
510
|
-
|
511
|
-
f"
|
512
|
-
f"
|
513
|
-
f"
|
514
|
-
"
|
515
|
-
|
516
|
-
"
|
517
|
-
"
|
518
|
-
"
|
511
|
+
formatted_response = formatted_response = (
|
512
|
+
"# Analysis and Next Action Decision Point\n\n"
|
513
|
+
f"📊 Progress: Iteration {iteration}/{self.max_iterations}\n\n"
|
514
|
+
"## Current Context\n"
|
515
|
+
f"```\n{self.task_to_solve_summary}```\n\n"
|
516
|
+
f"## Latest Tool {last_exectured_tool} Execution Result:\n"
|
517
|
+
f"Variable: ${variable_name}$\n"
|
518
|
+
f"```\n{response_display}```\n\n"
|
519
|
+
"## Available Resources\n"
|
520
|
+
f"🛠️ Tools:\n{self._get_tools_names_prompt()}\n\n"
|
521
|
+
f"📦 Variables:\n{self._get_variable_prompt()}\n\n"
|
522
|
+
"## Your Task\n"
|
523
|
+
"1. Analyze the execution result and progress, formalize if the current step is solved according to the task.\n"
|
524
|
+
"2. Determine the most effective next step\n"
|
525
|
+
"3. Select exactly ONE tool from the available list\n"
|
526
|
+
"4. Utilize variable interpolation where needed\n"
|
527
|
+
"## Response Requirements\n"
|
528
|
+
"Provide TWO markdown-formatted XML blocks:\n"
|
529
|
+
"1. Your analysis of the progression resulting from the execution of the tool in <thinking> tags, don't include <context_analysis/>\n"
|
530
|
+
"2. Your tool execution plan in <tool_name> tags\n\n"
|
531
|
+
"## Response Format\n"
|
519
532
|
"```xml\n"
|
520
533
|
"<thinking>\n"
|
521
|
-
"
|
534
|
+
"[Detailed analysis of progress, and reasoning for next step]\n"
|
522
535
|
"</thinking>\n"
|
523
536
|
"```\n"
|
524
537
|
"```xml\n"
|
525
|
-
"<
|
526
|
-
"
|
527
|
-
"
|
528
|
-
"
|
529
|
-
|
538
|
+
"<action>\n"
|
539
|
+
"<selected_tool_name>\n"
|
540
|
+
"[Precise instruction for tool execution]\n"
|
541
|
+
"</selected_tool_name>\n"
|
542
|
+
"</action>\n"
|
543
|
+
"```\n\n"
|
544
|
+
"⚠️ Important:\n"
|
545
|
+
"- Respond ONLY with the two XML blocks\n"
|
546
|
+
"- No additional commentary\n"
|
547
|
+
"- If previous step failed, revise approach\n"
|
548
|
+
"- Ensure variable interpolation syntax is correct\n"
|
549
|
+
"- Utilize the <task_complete> tool to indicate task completion, display the result or if the task is deemed unfeasible.")
|
530
550
|
|
531
551
|
return formatted_response
|
532
552
|
|
@@ -589,10 +609,10 @@ class Agent(BaseModel):
|
|
589
609
|
arguments_with_values_interpolated = {
|
590
610
|
key: self._interpolate_variables(value) for key, value in arguments_with_values.items()
|
591
611
|
}
|
592
|
-
|
612
|
+
|
593
613
|
arguments_with_values_interpolated = arguments_with_values_interpolated
|
594
614
|
|
595
|
-
# test if tool need variables in context
|
615
|
+
# test if tool need variables in context
|
596
616
|
if tool.need_variables:
|
597
617
|
# Inject variables into the tool if needed
|
598
618
|
arguments_with_values_interpolated["variables"] = self.variable_store
|
@@ -603,8 +623,7 @@ class Agent(BaseModel):
|
|
603
623
|
try:
|
604
624
|
# Convert arguments to proper types
|
605
625
|
converted_args = self.tools.validate_and_convert_arguments(
|
606
|
-
tool_name,
|
607
|
-
arguments_with_values_interpolated
|
626
|
+
tool_name, arguments_with_values_interpolated
|
608
627
|
)
|
609
628
|
except ValueError as e:
|
610
629
|
return "", f"Argument Error: {str(e)}"
|
@@ -637,9 +656,10 @@ class Agent(BaseModel):
|
|
637
656
|
"""Interpolate variables using $var$ syntax in the given text."""
|
638
657
|
try:
|
639
658
|
import re
|
659
|
+
|
640
660
|
for var in self.variable_store.keys():
|
641
661
|
# Escape the variable name for regex, but use raw value for replacement
|
642
|
-
pattern = rf
|
662
|
+
pattern = rf"\${re.escape(var)}\$"
|
643
663
|
replacement = self.variable_store[var]
|
644
664
|
text = re.sub(pattern, replacement, text)
|
645
665
|
return text
|
@@ -729,9 +749,7 @@ class Agent(BaseModel):
|
|
729
749
|
# Remove the last assistant / user message
|
730
750
|
user_message = memory_copy.pop()
|
731
751
|
assistant_message = memory_copy.pop()
|
732
|
-
summary = self.model.generate_with_history(
|
733
|
-
messages_history=memory_copy, prompt=prompt_summary
|
734
|
-
)
|
752
|
+
summary = self.model.generate_with_history(messages_history=memory_copy, prompt=prompt_summary)
|
735
753
|
# Remove user message
|
736
754
|
memory_copy.pop()
|
737
755
|
# Replace by summary
|
@@ -123,7 +123,8 @@ class GenerativeModel:
|
|
123
123
|
|
124
124
|
# Generate a response with conversation history and optional streaming
|
125
125
|
def generate_with_history(
|
126
|
-
self, messages_history: list[Message], prompt: str, image_url: str | None = None, streaming: bool = False
|
126
|
+
self, messages_history: list[Message], prompt: str, image_url: str | None = None, streaming: bool = False,
|
127
|
+
stop_words: list[str] | None = None
|
127
128
|
) -> ResponseStats:
|
128
129
|
"""Generate a response with conversation history and optional image.
|
129
130
|
|
@@ -132,6 +133,7 @@ class GenerativeModel:
|
|
132
133
|
prompt: Current user prompt.
|
133
134
|
image_url: Optional image URL for visual queries.
|
134
135
|
streaming: Whether to stream the response.
|
136
|
+
stop_words: Optional list of stop words for streaming
|
135
137
|
|
136
138
|
Returns:
|
137
139
|
Detailed response statistics or a generator in streaming mode.
|
@@ -163,6 +165,7 @@ class GenerativeModel:
|
|
163
165
|
model=self.model,
|
164
166
|
messages=messages,
|
165
167
|
num_retries=MIN_RETRIES,
|
168
|
+
stop=stop_words,
|
166
169
|
)
|
167
170
|
|
168
171
|
token_usage = TokenUsage(
|
@@ -181,7 +184,7 @@ class GenerativeModel:
|
|
181
184
|
except Exception as e:
|
182
185
|
self._handle_generation_exception(e)
|
183
186
|
|
184
|
-
def _stream_response(self, messages):
|
187
|
+
def _stream_response(self, messages, stop_words: list[str] | None = None):
|
185
188
|
"""Private method to handle streaming responses."""
|
186
189
|
try:
|
187
190
|
for chunk in generate_completion(
|
@@ -189,7 +192,8 @@ class GenerativeModel:
|
|
189
192
|
model=self.model,
|
190
193
|
messages=messages,
|
191
194
|
num_retries=MIN_RETRIES,
|
192
|
-
stream=True, # Enable streaming
|
195
|
+
stream=True, # Enable streaming,
|
196
|
+
stop=stop_words,
|
193
197
|
):
|
194
198
|
if chunk.choices[0].delta.content is not None:
|
195
199
|
self.event_emitter.emit("stream_chunk", chunk.choices[0].delta.content)
|
@@ -60,6 +60,12 @@ PROVIDERS = {
|
|
60
60
|
provider="openai",
|
61
61
|
base_url="https://integrate.api.nvidia.com/v1",
|
62
62
|
env_var="NVIDIA_API_KEY"
|
63
|
+
),
|
64
|
+
"ovh": ModelProviderConfig(
|
65
|
+
prefix="ovh/",
|
66
|
+
provider="openai",
|
67
|
+
base_url="https://deepseek-r1-distill-llama-70b.endpoints.kepler.ai.cloud.ovh.net/api/openai_compat/v1",
|
68
|
+
env_var="OVH_API_KEY"
|
63
69
|
)
|
64
70
|
}
|
65
71
|
|
@@ -52,6 +52,9 @@ model_info = {
|
|
52
52
|
max_output_tokens=8 * 1024,
|
53
53
|
max_input_tokens=1024 * 64,
|
54
54
|
),
|
55
|
-
|
56
|
-
|
55
|
+
"ovh/DeepSeek-R1-Distill-Llama-70B": ModelInfo(
|
56
|
+
model_name="ovh/DeepSeek-R1-Distill-Llama-70B",
|
57
|
+
max_output_tokens=8 * 1024,
|
58
|
+
max_input_tokens=1024 * 64,
|
59
|
+
),
|
57
60
|
}
|
@@ -0,0 +1,116 @@
|
|
1
|
+
from quantalogic.version import get_version
|
2
|
+
|
3
|
+
|
4
|
+
def system_prompt(tools: str, environment: str, expertise: str = ""):
|
5
|
+
"""System prompt for the ReAct chatbot with enhanced cognitive architecture."""
|
6
|
+
return f"""
|
7
|
+
### Agent Identity: QuantaLogic {get_version()}
|
8
|
+
Expert ReAct AI Agent implementing OODA (Observe-Orient-Decide-Act) loop with advanced problem-solving capabilities.
|
9
|
+
|
10
|
+
### Domain Expertise
|
11
|
+
{expertise}
|
12
|
+
|
13
|
+
### Input Protocol
|
14
|
+
Task Format: <task>task_description</task>
|
15
|
+
|
16
|
+
### Cognitive Framework
|
17
|
+
1. 🔍 OBSERVE: Gather and process information
|
18
|
+
2. 🧭 ORIENT: Analyze context and evaluate options
|
19
|
+
3. 🎯 DECIDE: Select optimal action path
|
20
|
+
4. ⚡ ACT: Execute precise tool operations
|
21
|
+
|
22
|
+
### Response Schema [MANDATORY TWO-BLOCK FORMAT]
|
23
|
+
|
24
|
+
1. 🧠 Analysis Block:
|
25
|
+
```xml
|
26
|
+
<thinking>
|
27
|
+
<!-- COGNITIVE PROCESSING MATRIX -->
|
28
|
+
|
29
|
+
<!-- INITIAL TASK ANALYSIS - INCLUDE ONLY IF NO MESSAGE HISTORY EXISTS -->
|
30
|
+
<context_analysis when="no_history">
|
31
|
+
• 📋 Task Decomposition based on task and history: Steps, Dependencies, Constraints
|
32
|
+
• 🎯 Success Metrics: Quantifiable Outcomes
|
33
|
+
• 🛠️ Resource Requirements: Tools, Data, Variables
|
34
|
+
• ⚠️ Risk Assessment: Potential Failures, Mitigations
|
35
|
+
</context_analysis>
|
36
|
+
|
37
|
+
<!-- ALWAYS INCLUDE FOR ONGOING OPERATIONS -->
|
38
|
+
<execution_analysis>
|
39
|
+
<!-- ONGOING OPERATIONS -->
|
40
|
+
• 🔄 Analyze Last Operation Results: Result, Impact, Effectiveness
|
41
|
+
• 📊 Progress Map: Completed%, Remaining%, Blockers
|
42
|
+
• 💾 Variable State: $var: value pairs
|
43
|
+
• 📈 Performance Metrics: Speed, Quality, Resource Usage
|
44
|
+
</execution_analysis>
|
45
|
+
|
46
|
+
<decision_matrix>
|
47
|
+
<!-- ACTION PLANNING -->
|
48
|
+
• 🎯 Next Action: Tool Selection + Rationale
|
49
|
+
• 📥 Input Parameters: Values + Variable Interpolation
|
50
|
+
• 🔄 Fallback Strategy: Alternative Approaches
|
51
|
+
• ✅ Exit Criteria: Completion Conditions
|
52
|
+
</decision_matrix>
|
53
|
+
|
54
|
+
<memory_pad>
|
55
|
+
<!-- OPERATIONAL NOTES -->
|
56
|
+
• 📝 Key Observations
|
57
|
+
• ⚡ Quick Access Data
|
58
|
+
</memory_pad>
|
59
|
+
</thinking>
|
60
|
+
```
|
61
|
+
|
62
|
+
2. ⚡ Action Block:
|
63
|
+
```xml
|
64
|
+
<action>
|
65
|
+
<tool_name>
|
66
|
+
<!-- PRECISE TOOL EXECUTION -->
|
67
|
+
<param1>value1</param1> <!-- Use $var$ for variable interpolation -->
|
68
|
+
<param2>value2</param2> <!-- Keep parameters minimal but sufficient -->
|
69
|
+
</tool_name>
|
70
|
+
</action>
|
71
|
+
```
|
72
|
+
|
73
|
+
### Action Patterns
|
74
|
+
1. 🆕 New Task:
|
75
|
+
```xml
|
76
|
+
<action>
|
77
|
+
<analyzer>
|
78
|
+
<input>$data$</input>
|
79
|
+
<mode>initialize</mode>
|
80
|
+
</analyzer>
|
81
|
+
</action>
|
82
|
+
```
|
83
|
+
|
84
|
+
2. 🔄 Continuation:
|
85
|
+
```xml
|
86
|
+
<action>
|
87
|
+
<processor>
|
88
|
+
<state>$current$</state>
|
89
|
+
<action>optimize</action>
|
90
|
+
</processor>
|
91
|
+
</action>
|
92
|
+
```
|
93
|
+
|
94
|
+
3. ✅ Completion:
|
95
|
+
```xml
|
96
|
+
<action>
|
97
|
+
<task_complete>
|
98
|
+
<result>$final_output$</result>
|
99
|
+
</task_complete>
|
100
|
+
</action>
|
101
|
+
```
|
102
|
+
|
103
|
+
### Operational Parameters
|
104
|
+
🛠️ Tools: {tools}
|
105
|
+
🌐 Environment: {environment}
|
106
|
+
|
107
|
+
### Execution Guidelines
|
108
|
+
1. 🎯 Maintain laser focus on task objectives
|
109
|
+
2. 📊 Use data-driven decision making
|
110
|
+
3. 🔄 Implement feedback loops for continuous optimization
|
111
|
+
4. ⚡ Maximize efficiency through variable interpolation
|
112
|
+
5. 🔍 Monitor and validate each action's impact
|
113
|
+
6. 🛑 Fail fast and adapt when encountering blockers
|
114
|
+
7. ✅ Verify completion criteria rigorously
|
115
|
+
"""
|
116
|
+
|
@@ -62,6 +62,7 @@ class ReplaceInFileTool(Tool):
|
|
62
62
|
"Updates sections of content in an existing file using SEARCH/REPLACE blocks. "
|
63
63
|
"If exact matches are not found, the tool attempts to find similar sections based on similarity. "
|
64
64
|
"Returns the updated content or an error."
|
65
|
+
"⚠️ THIS TOOL MUST BE USED IN PRIORITY TO UPDATE AN EXISTING FILE."
|
65
66
|
)
|
66
67
|
need_validation: bool = True
|
67
68
|
|
@@ -1,119 +0,0 @@
|
|
1
|
-
|
2
|
-
def system_prompt(tools: str, environment: str, expertise: str = ""):
|
3
|
-
"""System prompt for the ReAct chatbot."""
|
4
|
-
return f"""
|
5
|
-
### Core Identity
|
6
|
-
You are QuantaLogic, an advanced ReAct AI Agent specializing in systematic problem-solving.
|
7
|
-
|
8
|
-
### Specific Expertise
|
9
|
-
{expertise}
|
10
|
-
|
11
|
-
### Task Format
|
12
|
-
Tasks will be presented within XML tags:
|
13
|
-
<task>task_description</task>
|
14
|
-
|
15
|
-
### Response Protocol
|
16
|
-
Every response must contain exactly two XML blocks:
|
17
|
-
|
18
|
-
1. **Analysis Block**:
|
19
|
-
```xml
|
20
|
-
<thinking>
|
21
|
-
<!-- Follow this precise format. Be concise, dense, and use abbreviations, emojis, and Unicode characters to maximize density. -->
|
22
|
-
<task_analysis_if_no_history>
|
23
|
-
<!-- Only include if no conversation history exists: -->
|
24
|
-
* Rewrite the <task> and its context in your own words, ensuring clarity and specificity.
|
25
|
-
* Define detailed criteria for task completion if not already provided.
|
26
|
-
* Identify key components, constraints, and potential challenges.
|
27
|
-
* Break the <task> into smaller, manageable sub-tasks if necessary.
|
28
|
-
- Each sub-task should have a clear objective, specific deliverables, and a logical sequence for progress tracking.
|
29
|
-
</task_analysis_if_no_history>
|
30
|
-
<success_criteria_if_no_history>
|
31
|
-
<!-- Only include if no conversation history exists: -->
|
32
|
-
* Specify measurable outcomes for task completion.
|
33
|
-
* Define explicit quality benchmarks and performance indicators.
|
34
|
-
* Note any constraints or limitations affecting the task.
|
35
|
-
</success_criteria_if_no_history>
|
36
|
-
<strategic_approach_if_no_history>
|
37
|
-
<!-- Only include if no conversation history exists: -->
|
38
|
-
* Outline a high-level strategy for solving the task.
|
39
|
-
* Identify required resources, tools, or information.
|
40
|
-
* Anticipate potential roadblocks and propose contingency plans.
|
41
|
-
</strategic_approach_if_no_history>
|
42
|
-
<last_observation>
|
43
|
-
<!-- Include if conversation history exists: -->
|
44
|
-
<variable>
|
45
|
-
<name>...variable name...</name>
|
46
|
-
<description>...concise description...</description>
|
47
|
-
</variable>
|
48
|
-
<result>
|
49
|
-
...concise description of the result...
|
50
|
-
How does this result contribute to task progress?
|
51
|
-
</result>
|
52
|
-
</last_observation>
|
53
|
-
<progress_analysis>
|
54
|
-
<!-- Include if conversation history exists: -->
|
55
|
-
* Summarize completed and failed steps concisely.
|
56
|
-
* Identify and evaluate blockers or challenges.
|
57
|
-
* Highlight repetitions and suggest reevaluating the approach if necessary.
|
58
|
-
* Propose potential solutions or alternative strategies.
|
59
|
-
</progress_analysis>
|
60
|
-
<variables>
|
61
|
-
<!-- Include if conversation history exists: -->
|
62
|
-
* List all variable names and their current values concisely.
|
63
|
-
</variables>
|
64
|
-
<next_steps>
|
65
|
-
* Outline immediate actions required.
|
66
|
-
* Justify tool selection and parameter choices.
|
67
|
-
* Use variable interpolation (e.g., `$var1$`) to minimize token generation.
|
68
|
-
* Consider alternatives or reevaluate the plan if previous attempts failed.
|
69
|
-
* Use the `task_complete` tool to confirm task completion.
|
70
|
-
</next_steps>
|
71
|
-
<taskpad>
|
72
|
-
<!-- Optional: Use for notes about intermediate steps. -->
|
73
|
-
<note>...</note>
|
74
|
-
</taskpad>
|
75
|
-
</thinking>
|
76
|
-
```
|
77
|
-
|
78
|
-
2. **Action Block**:
|
79
|
-
```xml
|
80
|
-
<tool_name>
|
81
|
-
<!-- Replace `tool_name` with the name of the tool from the available tools. -->
|
82
|
-
<parameter1>
|
83
|
-
<!-- Use variable interpolation (e.g., `$var1$`) to pass context and minimize token generation. -->
|
84
|
-
value1
|
85
|
-
</parameter1>
|
86
|
-
<parameter2>value2</parameter2>
|
87
|
-
</tool_name>
|
88
|
-
```
|
89
|
-
|
90
|
-
### Examples of Action Blocks
|
91
|
-
- **New Task Example**:
|
92
|
-
```xml
|
93
|
-
<data_analyzer>
|
94
|
-
<file_path>$input_file$</file_path>
|
95
|
-
<operation>validate_structure</operation>
|
96
|
-
</data_analyzer>
|
97
|
-
```
|
98
|
-
|
99
|
-
- **Continuing Task Example**:
|
100
|
-
```xml
|
101
|
-
<memory_optimizer>
|
102
|
-
<process_id>$current_process$</process_id>
|
103
|
-
<target_utilization>75%</target_utilization>
|
104
|
-
</memory_optimizer>
|
105
|
-
```
|
106
|
-
|
107
|
-
- **Task Completion Example / When a task is completed**:
|
108
|
-
```xml
|
109
|
-
<task_complete>
|
110
|
-
<answer>Task completed successfully</answer>
|
111
|
-
</task_complete>
|
112
|
-
```
|
113
|
-
|
114
|
-
### Available Tools
|
115
|
-
{tools}
|
116
|
-
|
117
|
-
### Environment Details
|
118
|
-
{environment}
|
119
|
-
"""
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
{quantalogic-0.32.0 → quantalogic-0.33.0}/quantalogic/tools/generate_database_report_tool.py
RENAMED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
{quantalogic-0.32.0 → quantalogic-0.33.0}/quantalogic/tools/language_handlers/cpp_handler.py
RENAMED
File without changes
|
File without changes
|
{quantalogic-0.32.0 → quantalogic-0.33.0}/quantalogic/tools/language_handlers/java_handler.py
RENAMED
File without changes
|
{quantalogic-0.32.0 → quantalogic-0.33.0}/quantalogic/tools/language_handlers/javascript_handler.py
RENAMED
File without changes
|
{quantalogic-0.32.0 → quantalogic-0.33.0}/quantalogic/tools/language_handlers/python_handler.py
RENAMED
File without changes
|
{quantalogic-0.32.0 → quantalogic-0.33.0}/quantalogic/tools/language_handlers/rust_handler.py
RENAMED
File without changes
|
{quantalogic-0.32.0 → quantalogic-0.33.0}/quantalogic/tools/language_handlers/scala_handler.py
RENAMED
File without changes
|
{quantalogic-0.32.0 → quantalogic-0.33.0}/quantalogic/tools/language_handlers/typescript_handler.py
RENAMED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
{quantalogic-0.32.0 → quantalogic-0.33.0}/quantalogic/tools/utils/generate_database_report.py
RENAMED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
{quantalogic-0.32.0 → quantalogic-0.33.0}/quantalogic/utils/get_quantalogic_rules_content.py
RENAMED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|