grasp_agents 0.3.6__py3-none-any.whl → 0.3.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.
grasp_agents/llm_agent.py CHANGED
@@ -175,10 +175,12 @@ class LLMAgent(
175
175
 
176
176
  # 2. Set agent memory
177
177
 
178
+ system_message: SystemMessage | None = None
178
179
  _memory = self.memory.model_copy(deep=True)
179
- prev_message_hist_length = len(_memory.message_history)
180
180
  if self._reset_memory_on_run or _memory.is_empty:
181
181
  _memory.reset(formatted_sys_prompt)
182
+ if formatted_sys_prompt is not None:
183
+ system_message = _memory.message_history[0][0] # type: ignore[assignment]
182
184
  elif self._set_memory_impl:
183
185
  _memory = self._set_memory_impl(
184
186
  prev_memory=_memory,
@@ -195,16 +197,6 @@ class LLMAgent(
195
197
  if user_message_batch:
196
198
  _memory.update(message_batch=user_message_batch)
197
199
 
198
- # 4. Extract system message if it was added
199
-
200
- system_message: SystemMessage | None = None
201
- if (
202
- len(_memory.message_history) == 1
203
- and prev_message_hist_length == 0
204
- and isinstance(_memory.message_history[0][0], SystemMessage)
205
- ):
206
- system_message = _memory.message_history[0][0]
207
-
208
200
  return system_message, user_message_batch, _memory
209
201
 
210
202
  def _extract_outputs(
@@ -165,7 +165,7 @@ class PromptBuilder(AutoInstanceAttributesMixin, Generic[InT_contra, CtxT]):
165
165
  if in_args is not None:
166
166
  val_in_args = self._in_args_type_adapter.validate_python(in_args)
167
167
  if isinstance(val_in_args, BaseModel):
168
- _, has_image = self._format_pydantic_prompt_args(val_in_args)
168
+ has_image = self._has_image_data(val_in_args)
169
169
  if has_image and self.in_prompt_template is None:
170
170
  raise TypeError(
171
171
  "BaseModel input arguments contain ImageData, but input prompt "
@@ -179,22 +179,27 @@ class PromptBuilder(AutoInstanceAttributesMixin, Generic[InT_contra, CtxT]):
179
179
 
180
180
  return val_in_args, val_usr_args
181
181
 
182
+ @staticmethod
183
+ def _has_image_data(inp: BaseModel) -> bool:
184
+ contains_image_data = False
185
+ for field in type(inp).model_fields:
186
+ if isinstance(getattr(inp, field), ImageData):
187
+ contains_image_data = True
188
+
189
+ return contains_image_data
190
+
182
191
  @staticmethod
183
192
  def _format_pydantic_prompt_args(
184
193
  inp: BaseModel,
185
- ) -> tuple[dict[str, PromptArgumentType], bool]:
194
+ ) -> dict[str, PromptArgumentType]:
186
195
  formatted_args: dict[str, PromptArgumentType] = {}
187
- contains_image_data = False
188
196
  for field in type(inp).model_fields:
189
197
  if field == "selected_recipients":
190
198
  continue
191
199
 
192
200
  val = getattr(inp, field)
193
- if isinstance(val, (int, str, bool)):
194
- formatted_args[field] = val
195
- elif isinstance(val, ImageData):
201
+ if isinstance(val, (int, str, bool, ImageData)):
196
202
  formatted_args[field] = val
197
- contains_image_data = True
198
203
  elif isinstance(val, BaseModel):
199
204
  formatted_args[field] = val.model_dump_json(indent=2, warnings="error")
200
205
  else:
@@ -203,20 +208,18 @@ class PromptBuilder(AutoInstanceAttributesMixin, Generic[InT_contra, CtxT]):
203
208
  "int, str, bool, BaseModel, or ImageData."
204
209
  )
205
210
 
206
- return formatted_args, contains_image_data
211
+ return formatted_args
207
212
 
208
213
  def _combine_args(
209
214
  self, *, in_args: InT_contra | None, usr_args: LLMPromptArgs | None
210
215
  ) -> Mapping[str, PromptArgumentType] | str:
211
- fmt_usr_args, _ = (
212
- self._format_pydantic_prompt_args(usr_args) if usr_args else ({}, False)
213
- )
216
+ fmt_usr_args = self._format_pydantic_prompt_args(usr_args) if usr_args else {}
214
217
 
215
218
  if in_args is None:
216
219
  return fmt_usr_args
217
220
 
218
221
  if isinstance(in_args, BaseModel):
219
- fmt_in_args, _ = self._format_pydantic_prompt_args(in_args)
222
+ fmt_in_args = self._format_pydantic_prompt_args(in_args)
220
223
  return fmt_in_args | fmt_usr_args
221
224
 
222
225
  combined_args_str = self._in_args_type_adapter.dump_json(
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: grasp_agents
3
- Version: 0.3.6
3
+ Version: 0.3.8
4
4
  Summary: Grasp Agents Library
5
5
  License-File: LICENSE.md
6
6
  Requires-Python: <4,>=3.11.4
@@ -6,7 +6,7 @@ grasp_agents/generics_utils.py,sha256=5Pw3I9dlnKC2VGqYKC4ZZUO3Z_vTNT-NPFovNfPkl6
6
6
  grasp_agents/grasp_logging.py,sha256=H1GYhXdQvVkmauFDZ-KDwvVmPQHZUUm9sRqX_ObK2xI,1111
7
7
  grasp_agents/http_client.py,sha256=KZva2MjJjuI5ohUeU8RdTAImUnQYaqBrV2jDH8smbJw,738
8
8
  grasp_agents/llm.py,sha256=vVjELab9l0mK9bjO-IJebmmXUyUiws2fNjbXVQQNRvs,5392
9
- grasp_agents/llm_agent.py,sha256=_Fb3PAfw5okbsybz-BsUkd4kN8K9D5Sjw3HCbDHJFGk,14697
9
+ grasp_agents/llm_agent.py,sha256=EM_1h1O8Gvs5RbQiEV3KT52ADpPDSpvToBLRn0MRUu0,14471
10
10
  grasp_agents/llm_agent_memory.py,sha256=kD_UIF8xVgbSgW6xN87TzkdQcbTWLB-C5ZQu1_2HLx8,1770
11
11
  grasp_agents/llm_policy_executor.py,sha256=PVNuAejt3S-aSGsT7HvgYHyX_cZQSvrt1aUGPdkXtE4,17847
12
12
  grasp_agents/memory.py,sha256=gPkVIIF6dI_xXzarIAw9kSEnSJcfW_teUsWA2JAih94,671
@@ -15,7 +15,7 @@ grasp_agents/packet.py,sha256=PZ1EpclniAoLk7z4ieZbWzgYH3JSRgnlTe_WfbJYG_4,707
15
15
  grasp_agents/packet_pool.py,sha256=9umHbi5FwuUYYhhodSR-Z-fRR6OYiZyYEzq5d4nZFK4,3036
16
16
  grasp_agents/printer.py,sha256=M-gkLrZMg0ll9T1MRmKOQbp65niFB5ZiZbm-tUT_EYw,5464
17
17
  grasp_agents/processor.py,sha256=Atd_iTQNd3Nudb4mHqt3a5AQ31QUgpbrt1Fhn1sgpSk,6708
18
- grasp_agents/prompt_builder.py,sha256=1o7eMO4FxqRrrXFCj7aQKIajty6jZbBVaUZv7qOMIoY,8414
18
+ grasp_agents/prompt_builder.py,sha256=URMT4X8sNhdMPnkJK0YAF0i2xqBpK2-WlBlkmpVGe_Y,8455
19
19
  grasp_agents/run_context.py,sha256=9CidWWCKJ8umlhkRGtg_P3JQsRpH0K3_vhUjgVon4Wk,1597
20
20
  grasp_agents/usage_tracker.py,sha256=SPwv6RpdoHRuMIKE2hCAWAvDbtR3uXuhr2jpHQuKWhI,3438
21
21
  grasp_agents/utils.py,sha256=WNA5b0IkAsth0XKHEjgTY3PIHdw5L3vEsYPkyDGw8Mw,4741
@@ -45,7 +45,7 @@ grasp_agents/workflow/looped_workflow.py,sha256=QqXclXYxsW6C8Rxkf3dRaMHi-DfCvCbj
45
45
  grasp_agents/workflow/parallel_processor.py,sha256=Xyzs2UR_mRe2GFgzzadHOhqgMu3rFjd3GUjvmZimt_k,3505
46
46
  grasp_agents/workflow/sequential_workflow.py,sha256=Pl7jl9ZVDu-rC5UMfympEaQN8iG3kZurVF5eIPG62XA,2130
47
47
  grasp_agents/workflow/workflow_processor.py,sha256=2-iaDIlgNXgj-ClGbiE3fYfSv-N_qRC49Gf_dF6M_40,2640
48
- grasp_agents-0.3.6.dist-info/METADATA,sha256=kwdiPSqyVZ1B3kjjQFbyDDzdm0eokb6k0krwHqZWQ0s,6806
49
- grasp_agents-0.3.6.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
50
- grasp_agents-0.3.6.dist-info/licenses/LICENSE.md,sha256=-nNNdWqGB8gJ2O-peFQ2Irshv5tW5pHKyTcYkwvH7CE,1201
51
- grasp_agents-0.3.6.dist-info/RECORD,,
48
+ grasp_agents-0.3.8.dist-info/METADATA,sha256=wDMEIbN27VM13L1TQ94oXOFZMVM4Dd2pQkXsif2MQEo,6806
49
+ grasp_agents-0.3.8.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
50
+ grasp_agents-0.3.8.dist-info/licenses/LICENSE.md,sha256=-nNNdWqGB8gJ2O-peFQ2Irshv5tW5pHKyTcYkwvH7CE,1201
51
+ grasp_agents-0.3.8.dist-info/RECORD,,