quantalogic 0.50.26__py3-none-any.whl → 0.50.29__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.
- quantalogic/agent.py +71 -107
- quantalogic/model_info_litellm.py +15 -4
- quantalogic/prompts/memory_compaction_prompt.j2 +16 -0
- quantalogic/prompts/observation_response_format.j2 +55 -0
- quantalogic/prompts/repeated_tool_call_error.j2 +10 -0
- quantalogic/prompts/system_prompt.j2 +90 -0
- quantalogic/prompts/task_prompt.j2 +12 -0
- quantalogic/prompts/task_summary_prompt.j2 +10 -0
- quantalogic/prompts/tools_prompt.j2 +13 -0
- quantalogic/prompts/variables_prompt.j2 +6 -0
- quantalogic/prompts.py +34 -94
- quantalogic/quantlitellm.py +5 -2
- {quantalogic-0.50.26.dist-info → quantalogic-0.50.29.dist-info}/METADATA +1 -1
- {quantalogic-0.50.26.dist-info → quantalogic-0.50.29.dist-info}/RECORD +17 -9
- {quantalogic-0.50.26.dist-info → quantalogic-0.50.29.dist-info}/LICENSE +0 -0
- {quantalogic-0.50.26.dist-info → quantalogic-0.50.29.dist-info}/WHEEL +0 -0
- {quantalogic-0.50.26.dist-info → quantalogic-0.50.29.dist-info}/entry_points.txt +0 -0
quantalogic/agent.py
CHANGED
@@ -1,10 +1,13 @@
|
|
1
1
|
"""Enhanced QuantaLogic agent implementing the ReAct framework."""
|
2
2
|
|
3
3
|
import asyncio
|
4
|
+
import os
|
4
5
|
from collections.abc import Callable
|
5
6
|
from datetime import datetime
|
7
|
+
from pathlib import Path
|
6
8
|
from typing import Any
|
7
9
|
|
10
|
+
from jinja2 import Environment, FileSystemLoader
|
8
11
|
from loguru import logger
|
9
12
|
from pydantic import BaseModel, ConfigDict, PrivateAttr
|
10
13
|
|
@@ -559,17 +562,7 @@ class Agent(BaseModel):
|
|
559
562
|
Returns:
|
560
563
|
Generated summary text
|
561
564
|
"""
|
562
|
-
|
563
|
-
"Summarize the conversation concisely:\n"
|
564
|
-
"format in markdown:\n"
|
565
|
-
"<thinking>\n"
|
566
|
-
" - 1. **Completed Steps**: Briefly describe the steps.\n"
|
567
|
-
" - 2. **Variables Used**: List the variables.\n"
|
568
|
-
" - 3. **Progress Analysis**: Assess progress.\n"
|
569
|
-
"</thinking>\n"
|
570
|
-
"Keep the summary clear and actionable.\n"
|
571
|
-
)
|
572
|
-
|
565
|
+
# Format conversation history for the template
|
573
566
|
memory_copy = self.memory.memory.copy()
|
574
567
|
|
575
568
|
if len(memory_copy) < 3:
|
@@ -578,6 +571,14 @@ class Agent(BaseModel):
|
|
578
571
|
|
579
572
|
user_message = memory_copy.pop()
|
580
573
|
assistant_message = memory_copy.pop()
|
574
|
+
|
575
|
+
# Create summarization prompt using template
|
576
|
+
prompt_summary = self._render_template('memory_compaction_prompt.j2',
|
577
|
+
conversation_history="\n\n".join(
|
578
|
+
f"[{msg.role.upper()}]: {msg.content}"
|
579
|
+
for msg in memory_copy
|
580
|
+
))
|
581
|
+
|
581
582
|
summary = await self.model.async_generate_with_history(messages_history=memory_copy, prompt=prompt_summary)
|
582
583
|
|
583
584
|
# Remove last system message if present
|
@@ -620,15 +621,7 @@ class Agent(BaseModel):
|
|
620
621
|
if len(content) < 1024 * 4:
|
621
622
|
return content
|
622
623
|
|
623
|
-
prompt = (
|
624
|
-
"Create a task summary that captures ONLY: \n"
|
625
|
-
"1. Primary objective/purpose\n"
|
626
|
-
"2. Core actions/requirements\n"
|
627
|
-
"3. Desired end-state/outcome\n\n"
|
628
|
-
"Guidelines:\n"
|
629
|
-
"- Use imperative voice\n"
|
630
|
-
f"Input Task Description:\n{content}\n\n"
|
631
|
-
)
|
624
|
+
prompt = self._render_template('task_summary_prompt.j2', content=content)
|
632
625
|
result = await self.model.async_generate(prompt=prompt)
|
633
626
|
logger.debug(f"Generated summary: {result.response}")
|
634
627
|
return result.response.strip() + "\n🚨 The FULL task is in <task> tag in the previous messages.\n"
|
@@ -785,16 +778,11 @@ class Agent(BaseModel):
|
|
785
778
|
Tuple of (executed_tool_name, error_message)
|
786
779
|
"""
|
787
780
|
repeat_count = self.last_tool_call.get("count", 0)
|
788
|
-
error_message = (
|
789
|
-
|
790
|
-
|
791
|
-
|
792
|
-
|
793
|
-
"PLEASE:\n"
|
794
|
-
"1. Review your previous steps\n"
|
795
|
-
"2. Consider a different approach\n"
|
796
|
-
"3. Use a different tool or modify the arguments\n"
|
797
|
-
"4. Ensure you're making progress towards the goal"
|
781
|
+
error_message = self._render_template(
|
782
|
+
'repeated_tool_call_error.j2',
|
783
|
+
tool_name=tool_name,
|
784
|
+
arguments_with_values=arguments_with_values,
|
785
|
+
repeat_count=repeat_count
|
798
786
|
)
|
799
787
|
return tool_name, error_message
|
800
788
|
|
@@ -850,46 +838,19 @@ class Agent(BaseModel):
|
|
850
838
|
f"... content was truncated full content available by interpolation in variable {variable_name}"
|
851
839
|
)
|
852
840
|
|
853
|
-
|
854
|
-
|
855
|
-
|
856
|
-
|
857
|
-
|
858
|
-
|
859
|
-
|
860
|
-
|
861
|
-
|
862
|
-
|
863
|
-
|
864
|
-
|
865
|
-
|
866
|
-
"## Response Requirements\n"
|
867
|
-
"Provide TWO markdown-formatted XML blocks:\n"
|
868
|
-
"1. Your analysis of the progression resulting from the execution of the tool in <thinking> tags, don't include <context_analysis/>\n"
|
869
|
-
"2. Your tool execution plan in <tool_name> tags\n\n"
|
870
|
-
"## Last executed action result\n"
|
871
|
-
f"Last executed tool {last_executed_tool} Execution Result:\n"
|
872
|
-
f"\n<{variable_name}>\n{response_display}\n</{variable_name}>\n"
|
873
|
-
"## Response Format\n"
|
874
|
-
"```xml\n"
|
875
|
-
"<thinking>\n"
|
876
|
-
"[Detailed analysis of progress, and reasoning for next step]\n"
|
877
|
-
"</thinking>\n"
|
878
|
-
"```\n"
|
879
|
-
"```xml\n"
|
880
|
-
"<action>\n"
|
881
|
-
"<selected_tool_name>\n"
|
882
|
-
"[Precise instruction for tool execution]\n"
|
883
|
-
"</selected_tool_name>\n"
|
884
|
-
"</action>\n"
|
885
|
-
"```\n\n"
|
886
|
-
"⚠️ Important:\n"
|
887
|
-
"- Respond ONLY with the two XML blocks\n"
|
888
|
-
"- No additional commentary\n"
|
889
|
-
"- If previous step failed, revise approach\n"
|
890
|
-
"- Use interpolated variables ($variable_name$) where required in tool calls, to minimize token usage, if possible\n"
|
891
|
-
"- strictly follow the required arguments for each tool as defined in system prompt\n"
|
892
|
-
"- Utilize <action><task_complete><answer>...</answer></task_complete><action> to indicate task completion, display the result or if the task is deemed unfeasible."
|
841
|
+
tools_prompt = self._get_tools_names_prompt()
|
842
|
+
variables_prompt = self._get_variable_prompt()
|
843
|
+
|
844
|
+
formatted_response = self._render_template(
|
845
|
+
'observation_response_format.j2',
|
846
|
+
iteration=iteration,
|
847
|
+
max_iterations=self.max_iterations,
|
848
|
+
task_to_solve_summary=self.task_to_solve_summary,
|
849
|
+
tools_prompt=tools_prompt,
|
850
|
+
variables_prompt=variables_prompt,
|
851
|
+
last_executed_tool=last_executed_tool,
|
852
|
+
variable_name=variable_name,
|
853
|
+
response_display=response_display
|
893
854
|
)
|
894
855
|
|
895
856
|
return formatted_response
|
@@ -903,16 +864,14 @@ class Agent(BaseModel):
|
|
903
864
|
Returns:
|
904
865
|
The formatted task prompt
|
905
866
|
"""
|
906
|
-
|
907
|
-
|
908
|
-
|
909
|
-
|
910
|
-
|
911
|
-
|
912
|
-
|
913
|
-
|
914
|
-
"-----------------------------\n"
|
915
|
-
f"{self._get_variable_prompt()}\n"
|
867
|
+
tools_prompt = self._get_tools_names_prompt()
|
868
|
+
variables_prompt = self._get_variable_prompt()
|
869
|
+
|
870
|
+
prompt_task = self._render_template(
|
871
|
+
'task_prompt.j2',
|
872
|
+
task=task,
|
873
|
+
tools_prompt=tools_prompt,
|
874
|
+
variables_prompt=variables_prompt
|
916
875
|
)
|
917
876
|
return prompt_task
|
918
877
|
|
@@ -922,21 +881,8 @@ class Agent(BaseModel):
|
|
922
881
|
Returns:
|
923
882
|
Formatted tools prompt
|
924
883
|
"""
|
925
|
-
|
926
|
-
|
927
|
-
"\n"
|
928
|
-
f"{', '.join(self.tools.tool_names())}\n\n"
|
929
|
-
"Instructions:\n"
|
930
|
-
"\n"
|
931
|
-
"1. Select ONE tool per message\n"
|
932
|
-
"2. You will receive the tool's output in the next user response\n"
|
933
|
-
"3. Choose the most appropriate tool for each step\n"
|
934
|
-
"4. If it's not asked to write on files, don't use write_file tool\n"
|
935
|
-
"5. If files are written, then use tool to display the prepared download link\n"
|
936
|
-
"6. Give the final full answer using all the variables\n"
|
937
|
-
"7. Use task_complete tool to confirm task completion with the full content of the final answer\n"
|
938
|
-
)
|
939
|
-
return prompt_use_tools
|
884
|
+
tool_names = ', '.join(self.tools.tool_names())
|
885
|
+
return self._render_template('tools_prompt.j2', tool_names=tool_names)
|
940
886
|
|
941
887
|
def _get_variable_prompt(self) -> str:
|
942
888
|
"""Construct a prompt that explains how to use variables.
|
@@ -944,17 +890,8 @@ class Agent(BaseModel):
|
|
944
890
|
Returns:
|
945
891
|
Formatted variables prompt
|
946
892
|
"""
|
947
|
-
|
948
|
-
|
949
|
-
"Example: <write_file><file_path>/path/to/file.txt</file_path><content>$var1$</content></write_file>\n"
|
950
|
-
"\n"
|
951
|
-
"Available variables:\n"
|
952
|
-
"\n"
|
953
|
-
f"{', '.join(self.variable_store.keys())}\n"
|
954
|
-
if len(self.variable_store.keys()) > 0
|
955
|
-
else "None\n"
|
956
|
-
)
|
957
|
-
return prompt_use_variables
|
893
|
+
variable_names = ', '.join(self.variable_store.keys()) if len(self.variable_store.keys()) > 0 else "None"
|
894
|
+
return self._render_template('variables_prompt.j2', variable_names=variable_names)
|
958
895
|
|
959
896
|
def _calculate_context_occupancy(self) -> float:
|
960
897
|
"""Calculate the number of tokens in percentages for prompt and completion.
|
@@ -1063,4 +1000,31 @@ class Agent(BaseModel):
|
|
1063
1000
|
tools_markdown=self.tools.to_markdown(),
|
1064
1001
|
system_prompt=self.config.system_prompt,
|
1065
1002
|
)
|
1066
|
-
logger.debug(f"Set {len(tools)} tools")
|
1003
|
+
logger.debug(f"Set {len(tools)} tools")
|
1004
|
+
|
1005
|
+
def _render_template(self, template_name: str, **kwargs) -> str:
|
1006
|
+
"""Render a Jinja2 template with the provided variables.
|
1007
|
+
|
1008
|
+
Args:
|
1009
|
+
template_name: Name of the template file (without directory path)
|
1010
|
+
**kwargs: Variables to pass to the template
|
1011
|
+
|
1012
|
+
Returns:
|
1013
|
+
str: The rendered template
|
1014
|
+
"""
|
1015
|
+
try:
|
1016
|
+
# Get the directory where this file is located
|
1017
|
+
current_dir = Path(os.path.dirname(os.path.abspath(__file__)))
|
1018
|
+
|
1019
|
+
# Set up Jinja2 environment
|
1020
|
+
template_dir = current_dir / 'prompts'
|
1021
|
+
env = Environment(loader=FileSystemLoader(template_dir))
|
1022
|
+
|
1023
|
+
# Load the template
|
1024
|
+
template = env.get_template(template_name)
|
1025
|
+
|
1026
|
+
# Render the template with the provided variables
|
1027
|
+
return template.render(**kwargs)
|
1028
|
+
except Exception as e:
|
1029
|
+
logger.error(f"Error rendering template {template_name}: {str(e)}")
|
1030
|
+
raise
|
@@ -1,7 +1,19 @@
|
|
1
1
|
import functools
|
2
2
|
|
3
|
-
|
3
|
+
# litellm will be imported lazily when needed
|
4
|
+
_litellm = None
|
4
5
|
|
6
|
+
def _get_litellm():
|
7
|
+
"""Lazy load litellm module.
|
8
|
+
|
9
|
+
Returns:
|
10
|
+
The litellm module
|
11
|
+
"""
|
12
|
+
global _litellm
|
13
|
+
if _litellm is None:
|
14
|
+
import litellm
|
15
|
+
_litellm = litellm
|
16
|
+
return _litellm
|
5
17
|
|
6
18
|
@functools.lru_cache(maxsize=32)
|
7
19
|
def litellm_get_model_info(model_name: str) -> dict | None:
|
@@ -16,6 +28,7 @@ def litellm_get_model_info(model_name: str) -> dict | None:
|
|
16
28
|
Raises:
|
17
29
|
ValueError: If model info cannot be found after prefix fallbacks
|
18
30
|
"""
|
31
|
+
litellm = _get_litellm()
|
19
32
|
tried_models = [model_name]
|
20
33
|
|
21
34
|
while True:
|
@@ -37,7 +50,6 @@ def litellm_get_model_info(model_name: str) -> dict | None:
|
|
37
50
|
|
38
51
|
return None
|
39
52
|
|
40
|
-
|
41
53
|
def litellm_get_model_max_input_tokens(model_name: str) -> int | None:
|
42
54
|
"""Get maximum input tokens for a model using litellm.
|
43
55
|
|
@@ -53,7 +65,6 @@ def litellm_get_model_max_input_tokens(model_name: str) -> int | None:
|
|
53
65
|
except Exception:
|
54
66
|
return 8192 # Default for many modern models
|
55
67
|
|
56
|
-
|
57
68
|
def litellm_get_model_max_output_tokens(model_name: str) -> int | None:
|
58
69
|
"""Get maximum output tokens for a model using litellm.
|
59
70
|
|
@@ -67,4 +78,4 @@ def litellm_get_model_max_output_tokens(model_name: str) -> int | None:
|
|
67
78
|
info = litellm_get_model_info(model_name)
|
68
79
|
return info.get("max_output_tokens", 4096)
|
69
80
|
except Exception:
|
70
|
-
return 4096 # Conservative default
|
81
|
+
return 4096 # Conservative default
|
@@ -0,0 +1,16 @@
|
|
1
|
+
You are an AI assistant tasked with summarizing a conversation history.
|
2
|
+
|
3
|
+
Create a concise summary that captures the essential information from the conversation, focusing on:
|
4
|
+
1. The main task or problem being solved
|
5
|
+
2. Key information discovered or shared
|
6
|
+
3. Important decisions made
|
7
|
+
4. Current status or progress
|
8
|
+
|
9
|
+
Guidelines:
|
10
|
+
- Be factual and objective
|
11
|
+
- Preserve critical details and context
|
12
|
+
- Focus on information that would be needed to continue the task
|
13
|
+
- Aim for a summary that is about 20% of the original length
|
14
|
+
|
15
|
+
Conversation History:
|
16
|
+
{{ conversation_history }}
|
@@ -0,0 +1,55 @@
|
|
1
|
+
# Analysis and Next Action Decision Point
|
2
|
+
|
3
|
+
📊 Progress: Iteration {{ iteration }}/{{ max_iterations }}
|
4
|
+
|
5
|
+
## Global Task summary:
|
6
|
+
```
|
7
|
+
|
8
|
+
{{ task_to_solve_summary }}```
|
9
|
+
|
10
|
+
## Available Resources
|
11
|
+
🛠️ Tools:
|
12
|
+
{{ tools_prompt }}
|
13
|
+
|
14
|
+
📦 Variables:
|
15
|
+
{{ variables_prompt }}
|
16
|
+
|
17
|
+
## Your Task
|
18
|
+
1. Analyze the execution result and progress, formalize if the current step is solved according to the task.
|
19
|
+
2. Determine the most effective next step
|
20
|
+
3. Select exactly ONE tool from the available list
|
21
|
+
4. Utilize variable interpolation where needed
|
22
|
+
|
23
|
+
## Response Requirements
|
24
|
+
Provide TWO markdown-formatted XML blocks:
|
25
|
+
1. Your analysis of the progression resulting from the execution of the tool in <thinking> tags, don't include <context_analysis/>
|
26
|
+
2. Your tool execution plan in <tool_name> tags
|
27
|
+
|
28
|
+
## Last executed action result
|
29
|
+
Last executed tool {{ last_executed_tool }} Execution Result:
|
30
|
+
|
31
|
+
<{{ variable_name }}>
|
32
|
+
{{ response_display }}
|
33
|
+
</{{ variable_name }}>
|
34
|
+
|
35
|
+
## Response Format
|
36
|
+
```xml
|
37
|
+
<thinking>
|
38
|
+
[Detailed analysis of progress, and reasoning for next step]
|
39
|
+
</thinking>
|
40
|
+
```
|
41
|
+
```xml
|
42
|
+
<action>
|
43
|
+
<selected_tool_name>
|
44
|
+
[Precise instruction for tool execution]
|
45
|
+
</selected_tool_name>
|
46
|
+
</action>
|
47
|
+
```
|
48
|
+
|
49
|
+
⚠️ Important:
|
50
|
+
- Respond ONLY with the two XML blocks
|
51
|
+
- No additional commentary
|
52
|
+
- If previous step failed, revise approach
|
53
|
+
- Use interpolated variables ($variable_name$) where required in tool calls, to minimize token usage, if possible
|
54
|
+
- strictly follow the required arguments for each tool as defined in system prompt
|
55
|
+
- Utilize <action><task_complete><answer>...</answer></task_complete><action> to indicate task completion, display the result or if the task is deemed unfeasible.
|
@@ -0,0 +1,10 @@
|
|
1
|
+
Error: Detected repeated identical tool call pattern.
|
2
|
+
Tool: {{ tool_name }}
|
3
|
+
Arguments: {{ arguments_with_values }}
|
4
|
+
Repeated {{ repeat_count }} times
|
5
|
+
|
6
|
+
PLEASE:
|
7
|
+
1. Review your previous steps
|
8
|
+
2. Consider a different approach
|
9
|
+
3. Use a different tool or modify the arguments
|
10
|
+
4. Ensure you're making progress towards the goal
|
@@ -0,0 +1,90 @@
|
|
1
|
+
### Agent Identity: QuantaLogic {{ version }}
|
2
|
+
Expert ReAct AI Agent implementing OODA (Observe-Orient-Decide-Act) loop with advanced problem-solving capabilities.
|
3
|
+
|
4
|
+
### Domain Expertise
|
5
|
+
{{ expertise }}
|
6
|
+
|
7
|
+
### Input Protocol
|
8
|
+
Task Format: <task>task_description</task>
|
9
|
+
|
10
|
+
### Cognitive Framework
|
11
|
+
1. 🔍 OBSERVE: Gather and process information
|
12
|
+
2. 🧭 ORIENT: Analyze context and evaluate options
|
13
|
+
3. 🎯 DECIDE: Select optimal action path
|
14
|
+
4. ⚡ ACT: Execute precise tool operations
|
15
|
+
|
16
|
+
### Response Schema [MANDATORY TWO-BLOCK FORMAT]
|
17
|
+
|
18
|
+
1. 🧠 Analysis Block:
|
19
|
+
```xml
|
20
|
+
<thinking>
|
21
|
+
<!-- COGNITIVE PROCESSING MATRIX -->
|
22
|
+
|
23
|
+
<!-- INITIAL TASK ANALYSIS - INCLUDE ONLY IF NO MESSAGE HISTORY EXISTS -->
|
24
|
+
<context_analysis when="no_history">
|
25
|
+
• 📋 Task Decomposition based on task and history: Steps, Dependencies, Constraints
|
26
|
+
• 🎯 Success Metrics: Quantifiable Outcomes
|
27
|
+
• 🛠️ Resource Requirements: Tools, Data, Variables
|
28
|
+
• ⚠️ Risk Assessment: Potential Failures, Mitigations
|
29
|
+
</context_analysis>
|
30
|
+
|
31
|
+
<!-- ALWAYS INCLUDE FOR ONGOING OPERATIONS -->
|
32
|
+
<execution_analysis>
|
33
|
+
<!-- ONGOING OPERATIONS -->
|
34
|
+
• 🔄 Analyze Last Operation Results: Result, Impact, Effectiveness
|
35
|
+
• 📊 Progress Map: Completed%, Remaining%, Blockers
|
36
|
+
• 💾 Variable State: $var: short description of the content of each variable.
|
37
|
+
• 📈 Performance Metrics: Speed, Quality, Resource Usage
|
38
|
+
</execution_analysis>
|
39
|
+
|
40
|
+
<decision_matrix>
|
41
|
+
<!-- ACTION PLANNING -->
|
42
|
+
• 🎯 Next Action: Tool Selection + Rationale
|
43
|
+
• 📥 Input Parameters: Values + Variable Interpolation
|
44
|
+
• 🔄 Fallback Strategy: Alternative Approaches
|
45
|
+
• ✅ Exit Criteria: Completion Conditions
|
46
|
+
</decision_matrix>
|
47
|
+
|
48
|
+
<memory_pad>
|
49
|
+
<!-- OPERATIONAL NOTES -->
|
50
|
+
• 📝 Key Observations
|
51
|
+
• ⚡ Quick Access Data
|
52
|
+
</memory_pad>
|
53
|
+
</thinking>
|
54
|
+
```
|
55
|
+
|
56
|
+
2. ⚡ Action Block:
|
57
|
+
```xml
|
58
|
+
<action>
|
59
|
+
<tool_name>
|
60
|
+
<!-- PRECISE TOOL EXECUTION -->
|
61
|
+
<param1>value1</param1> <!-- Use $var$ for variable interpolation -->
|
62
|
+
<param2>value2</param2> <!-- Keep parameters minimal but sufficient -->
|
63
|
+
</tool_name>
|
64
|
+
</action>
|
65
|
+
```
|
66
|
+
|
67
|
+
### Example Usage
|
68
|
+
|
69
|
+
✅ Completion:
|
70
|
+
```xml
|
71
|
+
<action>
|
72
|
+
<task_complete>
|
73
|
+
<r>$final_output$</r>
|
74
|
+
</task_complete>
|
75
|
+
</action>
|
76
|
+
```
|
77
|
+
|
78
|
+
### Operational Parameters
|
79
|
+
🛠️ Tools: {{ tools }}
|
80
|
+
🌐 Environment: {{ environment }}
|
81
|
+
|
82
|
+
### Execution Guidelines
|
83
|
+
1. 🎯 Maintain laser focus on task objectives
|
84
|
+
2. 📊 Use data-driven decision making
|
85
|
+
3. 🔄 Implement feedback loops for continuous optimization
|
86
|
+
4. ⚡ Maximize efficiency through variable interpolation
|
87
|
+
5. 🔍 Monitor and validate each action's impact
|
88
|
+
6. 🛑 Fail fast and adapt when encountering blockers
|
89
|
+
7. ✅ Verify completion criteria rigorously
|
90
|
+
8. ✅ Return complete, full and usable results.
|
@@ -0,0 +1,13 @@
|
|
1
|
+
To accomplish this task, you have access to these tools:
|
2
|
+
|
3
|
+
{{ tool_names }}
|
4
|
+
|
5
|
+
Instructions:
|
6
|
+
|
7
|
+
1. Select ONE tool per message
|
8
|
+
2. You will receive the tool's output in the next user response
|
9
|
+
3. Choose the most appropriate tool for each step
|
10
|
+
4. If it's not asked to write on files, don't use write_file tool
|
11
|
+
5. If files are written, then use tool to display the prepared download link
|
12
|
+
6. Give the final full answer using all the variables
|
13
|
+
7. Use task_complete tool to confirm task completion with the full content of the final answer
|
quantalogic/prompts.py
CHANGED
@@ -1,98 +1,38 @@
|
|
1
|
-
|
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 -->
|
1
|
+
import os
|
2
|
+
from pathlib import Path
|
28
3
|
|
29
|
-
|
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>
|
4
|
+
from jinja2 import Environment, FileSystemLoader
|
36
5
|
|
37
|
-
|
38
|
-
<execution_analysis>
|
39
|
-
<!-- ONGOING OPERATIONS -->
|
40
|
-
• 🔄 Analyze Last Operation Results: Result, Impact, Effectiveness
|
41
|
-
• 📊 Progress Map: Completed%, Remaining%, Blockers
|
42
|
-
• 💾 Variable State: $var: short description of the content of each variable.
|
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
|
-
### Example Usage
|
74
|
-
|
75
|
-
✅ Completion:
|
76
|
-
```xml
|
77
|
-
<action>
|
78
|
-
<task_complete>
|
79
|
-
<result>$final_output$</result>
|
80
|
-
</task_complete>
|
81
|
-
</action>
|
82
|
-
```
|
83
|
-
|
84
|
-
### Operational Parameters
|
85
|
-
🛠️ Tools: {tools}
|
86
|
-
🌐 Environment: {environment}
|
6
|
+
from quantalogic.version import get_version
|
87
7
|
|
88
|
-
### Execution Guidelines
|
89
|
-
1. 🎯 Maintain laser focus on task objectives
|
90
|
-
2. 📊 Use data-driven decision making
|
91
|
-
3. 🔄 Implement feedback loops for continuous optimization
|
92
|
-
4. ⚡ Maximize efficiency through variable interpolation
|
93
|
-
5. 🔍 Monitor and validate each action's impact
|
94
|
-
6. 🛑 Fail fast and adapt when encountering blockers
|
95
|
-
7. ✅ Verify completion criteria rigorously
|
96
|
-
8. ✅ Return complete, full and usable results.
|
97
8
|
|
98
|
-
""
|
9
|
+
def system_prompt(tools: str, environment: str, expertise: str = ""):
|
10
|
+
"""System prompt for the ReAct chatbot with enhanced cognitive architecture.
|
11
|
+
|
12
|
+
Uses a Jinja2 template from the prompts directory.
|
13
|
+
|
14
|
+
Args:
|
15
|
+
tools: Available tools for the agent
|
16
|
+
environment: Environment information
|
17
|
+
expertise: Domain expertise information
|
18
|
+
|
19
|
+
Returns:
|
20
|
+
str: The rendered system prompt
|
21
|
+
"""
|
22
|
+
# Get the directory where this file is located
|
23
|
+
current_dir = Path(os.path.dirname(os.path.abspath(__file__)))
|
24
|
+
|
25
|
+
# Set up Jinja2 environment
|
26
|
+
template_dir = current_dir / 'prompts'
|
27
|
+
env = Environment(loader=FileSystemLoader(template_dir))
|
28
|
+
|
29
|
+
# Load the template
|
30
|
+
template = env.get_template('system_prompt.j2')
|
31
|
+
|
32
|
+
# Render the template with the provided variables
|
33
|
+
return template.render(
|
34
|
+
version=get_version(),
|
35
|
+
tools=tools,
|
36
|
+
environment=environment,
|
37
|
+
expertise=expertise
|
38
|
+
)
|
quantalogic/quantlitellm.py
CHANGED
@@ -38,7 +38,10 @@ PROVIDERS = {
|
|
38
38
|
env_var="DASHSCOPE_API_KEY",
|
39
39
|
),
|
40
40
|
"nvidia": ModelProviderConfig(
|
41
|
-
prefix="nvidia/",
|
41
|
+
prefix="nvidia/",
|
42
|
+
provider="openai",
|
43
|
+
base_url="https://integrate.api.nvidia.com/v1",
|
44
|
+
env_var="NVIDIA_API_KEY",
|
42
45
|
),
|
43
46
|
"ovh": ModelProviderConfig(
|
44
47
|
prefix="ovh/",
|
@@ -160,4 +163,4 @@ def get_model_max_output_tokens(model_name: str) -> int | None:
|
|
160
163
|
|
161
164
|
def get_model_info(model_name: str) -> dict | None:
|
162
165
|
"""Get model information for a given model name."""
|
163
|
-
return model_info.get(model_name, None)
|
166
|
+
return model_info.get(model_name, None)
|
@@ -1,5 +1,5 @@
|
|
1
1
|
quantalogic/__init__.py,sha256=BcM0DKB86DijMFtht9YTBdWyzh81zU7E5fhNLFiP260,869
|
2
|
-
quantalogic/agent.py,sha256=
|
2
|
+
quantalogic/agent.py,sha256=4XKUVAW4tnNwmdcwWbz9HjWe5CRWeouaC7Xlq-7CSHU,41129
|
3
3
|
quantalogic/agent_config.py,sha256=fPyMfm77BzimyfyFkTzb2ZdyZtGlr2fq5aTRETu77Vs,8202
|
4
4
|
quantalogic/agent_factory.py,sha256=LO0qsFtHxU7lcEi8dn-nDHhkh6Dl8Is6sP_3f1ap_Vg,6251
|
5
5
|
quantalogic/coding_agent.py,sha256=A-firiPWQjMC56B329Ne606_v2GsoF5-nxcuz3rVbYM,5496
|
@@ -23,10 +23,18 @@ quantalogic/main.py,sha256=jVw-s-ZUyX4krq3rzFn84-i6Qw2tplTx_QmsKG03m8I,9591
|
|
23
23
|
quantalogic/memory.py,sha256=zbtRuM05jaS2lJll-92dt5JfYVLERnF_m_9xqp2x-k0,6304
|
24
24
|
quantalogic/model_info.py,sha256=j7QqvjEFQDGpDOgQs8uTkVyI3a50Oa_nrsQjyxizTLc,272
|
25
25
|
quantalogic/model_info_list.py,sha256=Xeeb7QS4xEpe9ke7Guh0CxEx-Hl59U4kC-qzVts-eAU,2437
|
26
|
-
quantalogic/model_info_litellm.py,sha256=
|
26
|
+
quantalogic/model_info_litellm.py,sha256=Uoo8ZATjqH6POnTE3Ee3kfHfFllPYp8LkvJwlJjFZH8,2089
|
27
27
|
quantalogic/model_names.py,sha256=UZlz25zG9B2dpfwdw_e1Gw5qFsKQ7iME9FJh9Ts4u6s,938
|
28
|
-
quantalogic/prompts.
|
29
|
-
quantalogic/
|
28
|
+
quantalogic/prompts/memory_compaction_prompt.j2,sha256=Xsy9XKN7zxL4wNnNjWWlUjYjmtktgtee5dDG4dSvRW8,569
|
29
|
+
quantalogic/prompts/observation_response_format.j2,sha256=lvyveAJbXbc94aIvHgppKyaD9Tf7X5bCTGWjh51BDjI,1655
|
30
|
+
quantalogic/prompts/repeated_tool_call_error.j2,sha256=IRENR3a3D28Dtys-kGDP-x_uSkJnxeQZ5-jYHWv_3G4,319
|
31
|
+
quantalogic/prompts/system_prompt.j2,sha256=L2yBvUhCnKs25VJ4FuC_9sRyR4biVxbiHGvDVMJUclE,2767
|
32
|
+
quantalogic/prompts/task_prompt.j2,sha256=IhNK8l0WOe_0OaoPW62miwPjXoxGc3Q1o39Pt_CPy-I,179
|
33
|
+
quantalogic/prompts/task_summary_prompt.j2,sha256=fcjV96nqi6jsfR8l6uyep20rCaOi-zOReKmvoAnwz7c,205
|
34
|
+
quantalogic/prompts/tools_prompt.j2,sha256=6kHmyDFmDAZJy01dybJ-ZqnHouwjiHrxM8OEtXLN35o,528
|
35
|
+
quantalogic/prompts/variables_prompt.j2,sha256=N3OsMbzy3PfEUqYZVF_34wVidhh2ghVToSgdRCv2qgM,231
|
36
|
+
quantalogic/prompts.py,sha256=bSaODtMUhPeIMt4BsOdjA6-9Efadu8LH6msdGnbLvxE,1112
|
37
|
+
quantalogic/quantlitellm.py,sha256=nf-awyOxP0ANoAPGHNvHfdLu8gNn65L39gl7x4saIQc,5550
|
30
38
|
quantalogic/search_agent.py,sha256=tr0cwscJ4wu_G1aumjFyvGHQ0eQv5OL5sxj17s6Ocls,2470
|
31
39
|
quantalogic/server/__init__.py,sha256=8sz_PYAUCrkM6JM5EAUeIzNM4NPW6j6UT72JVkc21WQ,91
|
32
40
|
quantalogic/server/agent_server.py,sha256=VXaaWqReUSZOCX7CaKS14jria8yZn1kLEc52E2hV7ZA,22510
|
@@ -153,8 +161,8 @@ quantalogic/version_check.py,sha256=JyQFTNMDWtpHCLnN-BiakzB2cyXf6kUFsTjvmSruZi4,
|
|
153
161
|
quantalogic/welcome_message.py,sha256=o4tHdgabNuIV9kbIDPgS3_2yzJhayK30oKad2UouYDc,3020
|
154
162
|
quantalogic/xml_parser.py,sha256=AKuMdJC3QAX3Z_tErHVlZ-msjPemWaZUFiTwkHz76jg,11614
|
155
163
|
quantalogic/xml_tool_parser.py,sha256=Vz4LEgDbelJynD1siLOVkJ3gLlfHsUk65_gCwbYJyGc,3784
|
156
|
-
quantalogic-0.50.
|
157
|
-
quantalogic-0.50.
|
158
|
-
quantalogic-0.50.
|
159
|
-
quantalogic-0.50.
|
160
|
-
quantalogic-0.50.
|
164
|
+
quantalogic-0.50.29.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
165
|
+
quantalogic-0.50.29.dist-info/METADATA,sha256=tqXwFAeuCEdNr3gA2-rqG_xUk8nEh1QtbQ7A_5p4GKs,23848
|
166
|
+
quantalogic-0.50.29.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
|
167
|
+
quantalogic-0.50.29.dist-info/entry_points.txt,sha256=h74O_Q3qBRCrDR99qvwB4BpBGzASPUIjCfxHq6Qnups,183
|
168
|
+
quantalogic-0.50.29.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|