quantalogic 0.30.6__py3-none-any.whl → 0.30.8__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 CHANGED
@@ -559,20 +559,24 @@ class Agent(BaseModel):
559
559
  key: self._interpolate_variables(value) for key, value in arguments_with_values.items()
560
560
  }
561
561
 
562
- # Convert arguments to correct types
563
- try:
564
- converted_args = self.tools._convert_kwargs_types(tool_name, **arguments_with_values_interpolated)
565
- except ValueError as e:
566
- logger.error(f"Type conversion failed: {str(e)}")
567
- return "", f"Error: Type conversion failed for tool '{tool_name}': {str(e)}"
562
+ arguments_with_values_interpolated = arguments_with_values_interpolated
568
563
 
569
564
  # test if tool need variables in context
570
565
  if tool.need_variables:
571
566
  # Inject variables into the tool if needed
572
- converted_args["variables"] = self.variable_store
567
+ arguments_with_values_interpolated["variables"] = self.variable_store
573
568
  if tool.need_caller_context_memory:
574
569
  # Inject caller context into the tool if needed
575
- converted_args["caller_context_memory"] = self.memory.memory
570
+ arguments_with_values_interpolated["caller_context_memory"] = self.memory.memory
571
+
572
+ try:
573
+ # Convert arguments to proper types
574
+ converted_args = self.tools.validate_and_convert_arguments(
575
+ tool_name,
576
+ arguments_with_values_interpolated
577
+ )
578
+ except ValueError as e:
579
+ return "", f"Argument Error: {str(e)}"
576
580
 
577
581
  # Add injectable variables
578
582
  injectable_properties = tool.get_injectable_properties_in_execution()
@@ -67,49 +67,60 @@ class ToolManager(BaseModel):
67
67
  index += 1
68
68
  return markdown
69
69
 
70
- def _convert_kwargs_types(self, tool_name: str, **kwargs) -> dict:
71
- """Convert kwargs values to their expected types based on tool definition.
70
+
71
+
72
+ def validate_and_convert_arguments(self, tool_name: str, provided_args: dict) -> dict:
73
+ """Validates and converts arguments based on tool definition.
72
74
 
73
75
  Args:
74
- tool_name: Name of the tool to get argument types from
75
- **kwargs: Input arguments to convert
76
+ tool_name: Name of the tool to validate against
77
+ provided_args: Dictionary of arguments to validate
76
78
 
77
79
  Returns:
78
- Dictionary of converted arguments
80
+ Dictionary of converted arguments with proper types
79
81
 
80
82
  Raises:
81
- ValueError: If type conversion fails for a required argument
83
+ ValueError: For missing/invalid arguments or conversion errors
82
84
  """
83
- tool = self.tools[tool_name]
84
- converted = {}
85
-
86
- for arg_name, arg_value in kwargs.items():
87
- # Find the corresponding argument definition
88
- arg = next((a for a in tool.arguments if a.name == arg_name), None)
89
-
90
- if arg is None:
91
- logger.warning(f"Argument '{arg_name}' not found in tool definition")
92
- converted[arg_name] = arg_value
93
- continue
94
-
95
- try:
96
- if arg.arg_type == "int":
97
- converted[arg_name] = int(arg_value)
98
- elif arg.arg_type == "float":
99
- converted[arg_name] = float(arg_value)
100
- elif arg.arg_type == "boolean":
101
- val = str(arg_value).lower()
102
- converted[arg_name] = val in ("true", "1", "yes", "y")
103
- else: # string
104
- converted[arg_name] = str(arg_value)
105
- except (ValueError, TypeError) as e:
106
- if arg.required:
85
+ tool = self.get(tool_name)
86
+ converted_args = {}
87
+ type_conversion = {
88
+ "string": lambda x: str(x),
89
+ "int": lambda x: int(x),
90
+ "float": lambda x: float(x),
91
+ "bool": lambda x: str(x).lower() in ['true', '1', 'yes']
92
+ }
93
+
94
+ for arg_def in tool.arguments:
95
+ arg_name = arg_def.name
96
+ arg_type = arg_def.arg_type
97
+ required = arg_def.required
98
+ default = getattr(arg_def, 'default', None)
99
+
100
+ # Handle missing arguments
101
+ if arg_name not in provided_args:
102
+ if required:
103
+ raise ValueError(f"Missing required argument: {arg_name}")
104
+ if default is None:
105
+ continue # Skip optional args with no default
106
+ provided_args[arg_name] = default
107
+
108
+ # Type conversion
109
+ value = provided_args[arg_name]
110
+ if arg_type in type_conversion:
111
+ try:
112
+ converted = type_conversion[arg_type](value)
113
+ except (ValueError, TypeError) as e:
107
114
  raise ValueError(
108
- f"Failed to convert required argument '{arg_name}' to {arg.arg_type}: {str(e)}"
115
+ f"Invalid value '{value}' for {arg_name} ({arg_type}): {str(e)}"
109
116
  )
110
- logger.warning(f"Failed to convert optional argument '{arg_name}': {str(e)}")
111
- converted[arg_name] = arg_value
112
-
117
+ converted_args[arg_name] = converted
118
+ else:
119
+ converted_args[arg_name] = value # Unknown type, pass through
113
120
 
114
-
115
- return converted
121
+ # Validate extra arguments
122
+ extra_args = set(provided_args.keys()) - {a.name for a in tool.arguments}
123
+ if extra_args:
124
+ raise ValueError(f"Unexpected arguments: {', '.join(extra_args)}")
125
+
126
+ return converted_args
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: quantalogic
3
- Version: 0.30.6
3
+ Version: 0.30.8
4
4
  Summary: QuantaLogic ReAct Agents
5
5
  Author: Raphaël MANSUY
6
6
  Author-email: raphael.mansuy@gmail.com
@@ -1,5 +1,5 @@
1
1
  quantalogic/__init__.py,sha256=kX0c_xmD9OslWnAE92YHMGuD7xZcTo8ZOF_5R64HKps,784
2
- quantalogic/agent.py,sha256=bmqHR0XzkzmUCDYVh0EklPMtvxRt8UpDdutArqKi4XA,31219
2
+ quantalogic/agent.py,sha256=Ue8qV0jkD5i7ownIuYQJ1ljIqYYc-rQ2-3cv6Cuo9Y4,31309
3
3
  quantalogic/agent_config.py,sha256=9sjDnCPlAqVM45oguB_D509WSCaXZmuaVUtLcOvDlPg,7572
4
4
  quantalogic/agent_factory.py,sha256=ODVGuGtugSzmSdP6jiWlT8WyC5onANc6BIs83FC90Bg,3782
5
5
  quantalogic/coding_agent.py,sha256=Z7ik6LUvLKDnaW9Ax1iZGC7p1WMnlYEUIlE5lkBP414,4975
@@ -25,7 +25,7 @@ quantalogic/server/static/js/quantalogic.js,sha256=x7TrlZGR1Y0WLK2DWl1xY847BhEWM
25
25
  quantalogic/server/templates/index.html,sha256=nDnXJoQEm1vXbhXtgaYk0G5VXj0wwzE6KrqEDhHFpj4,7773
26
26
  quantalogic/task_file_reader.py,sha256=AMIJoeVY9Hhu0dBJ-C5EyaOFsXLkhn2oBhVs-WTnnLk,1460
27
27
  quantalogic/task_runner.py,sha256=FtxfZs2dxdsSZoiW92K3dpfegFe0dyKx9ZP5CCyEAzo,9965
28
- quantalogic/tool_manager.py,sha256=G-vXDKgU1todhM1I1GHUrOfdBqnHDZvRIcExwaU7RcY,4293
28
+ quantalogic/tool_manager.py,sha256=LUdzKIQn2W8ieCDG5EX0LdjzcwCOvSuiHnsXgddukc4,4599
29
29
  quantalogic/tools/__init__.py,sha256=pTirT5UBynuTkAzFYebu7ttGAMP3_A0idFvDp6lGZJQ,2146
30
30
  quantalogic/tools/agent_tool.py,sha256=MXCXxWHRch7VK4UWhtRP1jeI8Np9Ne2CUGo8vm1oZiM,3064
31
31
  quantalogic/tools/dalle_e.py,sha256=nur2kl6DKjaWWaHcmF_y9vS5bvty2fW8hQfdgf5KWfs,10948
@@ -85,8 +85,8 @@ quantalogic/version_check.py,sha256=cttR1lR3OienGLl7NrK1Te1fhDkqSjCci7HC1vFUTSY,
85
85
  quantalogic/welcome_message.py,sha256=IXMhem8h7srzNUwvw8G_lmEkHU8PFfote021E_BXmVk,3039
86
86
  quantalogic/xml_parser.py,sha256=uMLQNHTRCg116FwcjRoquZmSwVtE4LEH-6V2E3RD-dA,11466
87
87
  quantalogic/xml_tool_parser.py,sha256=Vz4LEgDbelJynD1siLOVkJ3gLlfHsUk65_gCwbYJyGc,3784
88
- quantalogic-0.30.6.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
89
- quantalogic-0.30.6.dist-info/METADATA,sha256=Hfc9KLBE3r0KUwXfpEb25KCN3zWI-Fb9D6gRnt5xDHU,21722
90
- quantalogic-0.30.6.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
91
- quantalogic-0.30.6.dist-info/entry_points.txt,sha256=h74O_Q3qBRCrDR99qvwB4BpBGzASPUIjCfxHq6Qnups,183
92
- quantalogic-0.30.6.dist-info/RECORD,,
88
+ quantalogic-0.30.8.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
89
+ quantalogic-0.30.8.dist-info/METADATA,sha256=IAlgxZjaFHCms34IQMC-mYWFbB4yh7pfJ0OMuxTQngE,21722
90
+ quantalogic-0.30.8.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
91
+ quantalogic-0.30.8.dist-info/entry_points.txt,sha256=h74O_Q3qBRCrDR99qvwB4BpBGzASPUIjCfxHq6Qnups,183
92
+ quantalogic-0.30.8.dist-info/RECORD,,