quantalogic 0.50.25__py3-none-any.whl → 0.50.28__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/__init__.py +2 -0
- quantalogic/agent.py +62 -96
- quantalogic/model_info_litellm.py +15 -4
- 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.25.dist-info → quantalogic-0.50.28.dist-info}/METADATA +1 -1
- {quantalogic-0.50.25.dist-info → quantalogic-0.50.28.dist-info}/RECORD +17 -10
- {quantalogic-0.50.25.dist-info → quantalogic-0.50.28.dist-info}/LICENSE +0 -0
- {quantalogic-0.50.25.dist-info → quantalogic-0.50.28.dist-info}/WHEEL +0 -0
- {quantalogic-0.50.25.dist-info → quantalogic-0.50.28.dist-info}/entry_points.txt +0 -0
quantalogic/__init__.py
CHANGED
@@ -14,6 +14,7 @@ warnings.filterwarnings(
|
|
14
14
|
from .agent import Agent # noqa: E402
|
15
15
|
from .console_print_events import console_print_events # noqa: E402
|
16
16
|
from .console_print_token import console_print_token # noqa: E402
|
17
|
+
from .create_custom_agent import create_custom_agent # noqa: E402
|
17
18
|
from .event_emitter import EventEmitter # noqa: E402
|
18
19
|
from .memory import AgentMemory, VariableMemory # noqa: E402
|
19
20
|
|
@@ -24,4 +25,5 @@ __all__ = [
|
|
24
25
|
"VariableMemory",
|
25
26
|
"console_print_events",
|
26
27
|
"console_print_token",
|
28
|
+
"create_custom_agent"
|
27
29
|
]
|
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
|
|
@@ -620,15 +623,7 @@ class Agent(BaseModel):
|
|
620
623
|
if len(content) < 1024 * 4:
|
621
624
|
return content
|
622
625
|
|
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
|
-
)
|
626
|
+
prompt = self._render_template('task_summary_prompt.j2', content=content)
|
632
627
|
result = await self.model.async_generate(prompt=prompt)
|
633
628
|
logger.debug(f"Generated summary: {result.response}")
|
634
629
|
return result.response.strip() + "\n🚨 The FULL task is in <task> tag in the previous messages.\n"
|
@@ -785,16 +780,11 @@ class Agent(BaseModel):
|
|
785
780
|
Tuple of (executed_tool_name, error_message)
|
786
781
|
"""
|
787
782
|
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"
|
783
|
+
error_message = self._render_template(
|
784
|
+
'repeated_tool_call_error.j2',
|
785
|
+
tool_name=tool_name,
|
786
|
+
arguments_with_values=arguments_with_values,
|
787
|
+
repeat_count=repeat_count
|
798
788
|
)
|
799
789
|
return tool_name, error_message
|
800
790
|
|
@@ -850,46 +840,19 @@ class Agent(BaseModel):
|
|
850
840
|
f"... content was truncated full content available by interpolation in variable {variable_name}"
|
851
841
|
)
|
852
842
|
|
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."
|
843
|
+
tools_prompt = self._get_tools_names_prompt()
|
844
|
+
variables_prompt = self._get_variable_prompt()
|
845
|
+
|
846
|
+
formatted_response = self._render_template(
|
847
|
+
'observation_response_format.j2',
|
848
|
+
iteration=iteration,
|
849
|
+
max_iterations=self.max_iterations,
|
850
|
+
task_to_solve_summary=self.task_to_solve_summary,
|
851
|
+
tools_prompt=tools_prompt,
|
852
|
+
variables_prompt=variables_prompt,
|
853
|
+
last_executed_tool=last_executed_tool,
|
854
|
+
variable_name=variable_name,
|
855
|
+
response_display=response_display
|
893
856
|
)
|
894
857
|
|
895
858
|
return formatted_response
|
@@ -903,16 +866,14 @@ class Agent(BaseModel):
|
|
903
866
|
Returns:
|
904
867
|
The formatted task prompt
|
905
868
|
"""
|
906
|
-
|
907
|
-
|
908
|
-
|
909
|
-
|
910
|
-
|
911
|
-
|
912
|
-
|
913
|
-
|
914
|
-
"-----------------------------\n"
|
915
|
-
f"{self._get_variable_prompt()}\n"
|
869
|
+
tools_prompt = self._get_tools_names_prompt()
|
870
|
+
variables_prompt = self._get_variable_prompt()
|
871
|
+
|
872
|
+
prompt_task = self._render_template(
|
873
|
+
'task_prompt.j2',
|
874
|
+
task=task,
|
875
|
+
tools_prompt=tools_prompt,
|
876
|
+
variables_prompt=variables_prompt
|
916
877
|
)
|
917
878
|
return prompt_task
|
918
879
|
|
@@ -922,21 +883,8 @@ class Agent(BaseModel):
|
|
922
883
|
Returns:
|
923
884
|
Formatted tools prompt
|
924
885
|
"""
|
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
|
886
|
+
tool_names = ', '.join(self.tools.tool_names())
|
887
|
+
return self._render_template('tools_prompt.j2', tool_names=tool_names)
|
940
888
|
|
941
889
|
def _get_variable_prompt(self) -> str:
|
942
890
|
"""Construct a prompt that explains how to use variables.
|
@@ -944,17 +892,8 @@ class Agent(BaseModel):
|
|
944
892
|
Returns:
|
945
893
|
Formatted variables prompt
|
946
894
|
"""
|
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
|
895
|
+
variable_names = ', '.join(self.variable_store.keys()) if len(self.variable_store.keys()) > 0 else "None"
|
896
|
+
return self._render_template('variables_prompt.j2', variable_names=variable_names)
|
958
897
|
|
959
898
|
def _calculate_context_occupancy(self) -> float:
|
960
899
|
"""Calculate the number of tokens in percentages for prompt and completion.
|
@@ -1063,4 +1002,31 @@ class Agent(BaseModel):
|
|
1063
1002
|
tools_markdown=self.tools.to_markdown(),
|
1064
1003
|
system_prompt=self.config.system_prompt,
|
1065
1004
|
)
|
1066
|
-
logger.debug(f"Set {len(tools)} tools")
|
1005
|
+
logger.debug(f"Set {len(tools)} tools")
|
1006
|
+
|
1007
|
+
def _render_template(self, template_name: str, **kwargs) -> str:
|
1008
|
+
"""Render a Jinja2 template with the provided variables.
|
1009
|
+
|
1010
|
+
Args:
|
1011
|
+
template_name: Name of the template file (without directory path)
|
1012
|
+
**kwargs: Variables to pass to the template
|
1013
|
+
|
1014
|
+
Returns:
|
1015
|
+
str: The rendered template
|
1016
|
+
"""
|
1017
|
+
try:
|
1018
|
+
# Get the directory where this file is located
|
1019
|
+
current_dir = Path(os.path.dirname(os.path.abspath(__file__)))
|
1020
|
+
|
1021
|
+
# Set up Jinja2 environment
|
1022
|
+
template_dir = current_dir / 'prompts'
|
1023
|
+
env = Environment(loader=FileSystemLoader(template_dir))
|
1024
|
+
|
1025
|
+
# Load the template
|
1026
|
+
template = env.get_template(template_name)
|
1027
|
+
|
1028
|
+
# Render the template with the provided variables
|
1029
|
+
return template.render(**kwargs)
|
1030
|
+
except Exception as e:
|
1031
|
+
logger.error(f"Error rendering template {template_name}: {str(e)}")
|
1032
|
+
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,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
|
-
quantalogic/__init__.py,sha256=
|
2
|
-
quantalogic/agent.py,sha256=
|
1
|
+
quantalogic/__init__.py,sha256=BcM0DKB86DijMFtht9YTBdWyzh81zU7E5fhNLFiP260,869
|
2
|
+
quantalogic/agent.py,sha256=E-nrxTByIjflFmG3Jlm0CnbsoCappxK5E52WR_zamsQ,41069
|
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,17 @@ 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/observation_response_format.j2,sha256=lvyveAJbXbc94aIvHgppKyaD9Tf7X5bCTGWjh51BDjI,1655
|
29
|
+
quantalogic/prompts/repeated_tool_call_error.j2,sha256=IRENR3a3D28Dtys-kGDP-x_uSkJnxeQZ5-jYHWv_3G4,319
|
30
|
+
quantalogic/prompts/system_prompt.j2,sha256=L2yBvUhCnKs25VJ4FuC_9sRyR4biVxbiHGvDVMJUclE,2767
|
31
|
+
quantalogic/prompts/task_prompt.j2,sha256=IhNK8l0WOe_0OaoPW62miwPjXoxGc3Q1o39Pt_CPy-I,179
|
32
|
+
quantalogic/prompts/task_summary_prompt.j2,sha256=fcjV96nqi6jsfR8l6uyep20rCaOi-zOReKmvoAnwz7c,205
|
33
|
+
quantalogic/prompts/tools_prompt.j2,sha256=6kHmyDFmDAZJy01dybJ-ZqnHouwjiHrxM8OEtXLN35o,528
|
34
|
+
quantalogic/prompts/variables_prompt.j2,sha256=N3OsMbzy3PfEUqYZVF_34wVidhh2ghVToSgdRCv2qgM,231
|
35
|
+
quantalogic/prompts.py,sha256=bSaODtMUhPeIMt4BsOdjA6-9Efadu8LH6msdGnbLvxE,1112
|
36
|
+
quantalogic/quantlitellm.py,sha256=nf-awyOxP0ANoAPGHNvHfdLu8gNn65L39gl7x4saIQc,5550
|
30
37
|
quantalogic/search_agent.py,sha256=tr0cwscJ4wu_G1aumjFyvGHQ0eQv5OL5sxj17s6Ocls,2470
|
31
38
|
quantalogic/server/__init__.py,sha256=8sz_PYAUCrkM6JM5EAUeIzNM4NPW6j6UT72JVkc21WQ,91
|
32
39
|
quantalogic/server/agent_server.py,sha256=VXaaWqReUSZOCX7CaKS14jria8yZn1kLEc52E2hV7ZA,22510
|
@@ -153,8 +160,8 @@ quantalogic/version_check.py,sha256=JyQFTNMDWtpHCLnN-BiakzB2cyXf6kUFsTjvmSruZi4,
|
|
153
160
|
quantalogic/welcome_message.py,sha256=o4tHdgabNuIV9kbIDPgS3_2yzJhayK30oKad2UouYDc,3020
|
154
161
|
quantalogic/xml_parser.py,sha256=AKuMdJC3QAX3Z_tErHVlZ-msjPemWaZUFiTwkHz76jg,11614
|
155
162
|
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.
|
163
|
+
quantalogic-0.50.28.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
164
|
+
quantalogic-0.50.28.dist-info/METADATA,sha256=mXLhuL7i-3L5xqASbs5o_NVNlLjU942d1j4oKIV8l40,23848
|
165
|
+
quantalogic-0.50.28.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
|
166
|
+
quantalogic-0.50.28.dist-info/entry_points.txt,sha256=h74O_Q3qBRCrDR99qvwB4BpBGzASPUIjCfxHq6Qnups,183
|
167
|
+
quantalogic-0.50.28.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|