grasp_agents 0.3.1__tar.gz → 0.3.3__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.
- {grasp_agents-0.3.1 → grasp_agents-0.3.3}/PKG-INFO +1 -1
- {grasp_agents-0.3.1 → grasp_agents-0.3.3}/pyproject.toml +1 -1
- {grasp_agents-0.3.1 → grasp_agents-0.3.3}/src/grasp_agents/llm_agent.py +21 -23
- {grasp_agents-0.3.1 → grasp_agents-0.3.3}/src/grasp_agents/llm_policy_executor.py +12 -10
- {grasp_agents-0.3.1 → grasp_agents-0.3.3}/src/grasp_agents/processor.py +1 -2
- {grasp_agents-0.3.1 → grasp_agents-0.3.3}/src/grasp_agents/prompt_builder.py +11 -11
- {grasp_agents-0.3.1 → grasp_agents-0.3.3}/src/grasp_agents/utils.py +3 -0
- {grasp_agents-0.3.1 → grasp_agents-0.3.3}/.gitignore +0 -0
- {grasp_agents-0.3.1 → grasp_agents-0.3.3}/LICENSE.md +0 -0
- {grasp_agents-0.3.1 → grasp_agents-0.3.3}/README.md +0 -0
- {grasp_agents-0.3.1 → grasp_agents-0.3.3}/src/grasp_agents/__init__.py +0 -0
- {grasp_agents-0.3.1 → grasp_agents-0.3.3}/src/grasp_agents/cloud_llm.py +0 -0
- {grasp_agents-0.3.1 → grasp_agents-0.3.3}/src/grasp_agents/comm_processor.py +0 -0
- {grasp_agents-0.3.1 → grasp_agents-0.3.3}/src/grasp_agents/costs_dict.yaml +0 -0
- {grasp_agents-0.3.1 → grasp_agents-0.3.3}/src/grasp_agents/generics_utils.py +0 -0
- {grasp_agents-0.3.1 → grasp_agents-0.3.3}/src/grasp_agents/grasp_logging.py +0 -0
- {grasp_agents-0.3.1 → grasp_agents-0.3.3}/src/grasp_agents/http_client.py +0 -0
- {grasp_agents-0.3.1 → grasp_agents-0.3.3}/src/grasp_agents/llm.py +0 -0
- {grasp_agents-0.3.1 → grasp_agents-0.3.3}/src/grasp_agents/llm_agent_memory.py +0 -0
- {grasp_agents-0.3.1 → grasp_agents-0.3.3}/src/grasp_agents/memory.py +0 -0
- {grasp_agents-0.3.1 → grasp_agents-0.3.3}/src/grasp_agents/message_history.py +0 -0
- {grasp_agents-0.3.1 → grasp_agents-0.3.3}/src/grasp_agents/openai/__init__.py +0 -0
- {grasp_agents-0.3.1 → grasp_agents-0.3.3}/src/grasp_agents/openai/completion_chunk_converters.py +0 -0
- {grasp_agents-0.3.1 → grasp_agents-0.3.3}/src/grasp_agents/openai/completion_converters.py +0 -0
- {grasp_agents-0.3.1 → grasp_agents-0.3.3}/src/grasp_agents/openai/content_converters.py +0 -0
- {grasp_agents-0.3.1 → grasp_agents-0.3.3}/src/grasp_agents/openai/converters.py +0 -0
- {grasp_agents-0.3.1 → grasp_agents-0.3.3}/src/grasp_agents/openai/message_converters.py +0 -0
- {grasp_agents-0.3.1 → grasp_agents-0.3.3}/src/grasp_agents/openai/openai_llm.py +0 -0
- {grasp_agents-0.3.1 → grasp_agents-0.3.3}/src/grasp_agents/openai/tool_converters.py +0 -0
- {grasp_agents-0.3.1 → grasp_agents-0.3.3}/src/grasp_agents/packet.py +0 -0
- {grasp_agents-0.3.1 → grasp_agents-0.3.3}/src/grasp_agents/packet_pool.py +0 -0
- {grasp_agents-0.3.1 → grasp_agents-0.3.3}/src/grasp_agents/printer.py +0 -0
- {grasp_agents-0.3.1 → grasp_agents-0.3.3}/src/grasp_agents/rate_limiting/__init__.py +0 -0
- {grasp_agents-0.3.1 → grasp_agents-0.3.3}/src/grasp_agents/rate_limiting/rate_limiter_chunked.py +0 -0
- {grasp_agents-0.3.1 → grasp_agents-0.3.3}/src/grasp_agents/rate_limiting/types.py +0 -0
- {grasp_agents-0.3.1 → grasp_agents-0.3.3}/src/grasp_agents/rate_limiting/utils.py +0 -0
- {grasp_agents-0.3.1 → grasp_agents-0.3.3}/src/grasp_agents/run_context.py +0 -0
- {grasp_agents-0.3.1 → grasp_agents-0.3.3}/src/grasp_agents/typing/__init__.py +0 -0
- {grasp_agents-0.3.1 → grasp_agents-0.3.3}/src/grasp_agents/typing/completion.py +0 -0
- {grasp_agents-0.3.1 → grasp_agents-0.3.3}/src/grasp_agents/typing/completion_chunk.py +0 -0
- {grasp_agents-0.3.1 → grasp_agents-0.3.3}/src/grasp_agents/typing/content.py +0 -0
- {grasp_agents-0.3.1 → grasp_agents-0.3.3}/src/grasp_agents/typing/converters.py +0 -0
- {grasp_agents-0.3.1 → grasp_agents-0.3.3}/src/grasp_agents/typing/events.py +0 -0
- {grasp_agents-0.3.1 → grasp_agents-0.3.3}/src/grasp_agents/typing/io.py +0 -0
- {grasp_agents-0.3.1 → grasp_agents-0.3.3}/src/grasp_agents/typing/message.py +0 -0
- {grasp_agents-0.3.1 → grasp_agents-0.3.3}/src/grasp_agents/typing/tool.py +0 -0
- {grasp_agents-0.3.1 → grasp_agents-0.3.3}/src/grasp_agents/usage_tracker.py +0 -0
- {grasp_agents-0.3.1 → grasp_agents-0.3.3}/src/grasp_agents/workflow/__init__.py +0 -0
- {grasp_agents-0.3.1 → grasp_agents-0.3.3}/src/grasp_agents/workflow/looped_workflow.py +0 -0
- {grasp_agents-0.3.1 → grasp_agents-0.3.3}/src/grasp_agents/workflow/parallel_processor.py +0 -0
- {grasp_agents-0.3.1 → grasp_agents-0.3.3}/src/grasp_agents/workflow/sequential_workflow.py +0 -0
- {grasp_agents-0.3.1 → grasp_agents-0.3.3}/src/grasp_agents/workflow/workflow_processor.py +0 -0
@@ -192,7 +192,7 @@ class LLMAgent(
|
|
192
192
|
|
193
193
|
# 1. Make system prompt (can be None)
|
194
194
|
|
195
|
-
formatted_sys_prompt = self._prompt_builder.
|
195
|
+
formatted_sys_prompt = self._prompt_builder.make_system_prompt(
|
196
196
|
sys_args=sys_args, ctx=ctx
|
197
197
|
)
|
198
198
|
|
@@ -313,17 +313,17 @@ class LLMAgent(
|
|
313
313
|
|
314
314
|
# -- Decorators for custom implementations --
|
315
315
|
|
316
|
-
def
|
316
|
+
def make_system_prompt(
|
317
317
|
self, func: MakeSystemPromptHandler[CtxT]
|
318
318
|
) -> MakeSystemPromptHandler[CtxT]:
|
319
|
-
self._prompt_builder.
|
319
|
+
self._prompt_builder.make_system_prompt_impl = func
|
320
320
|
|
321
321
|
return func
|
322
322
|
|
323
|
-
def
|
323
|
+
def make_input_content(
|
324
324
|
self, func: MakeInputContentHandler[InT_contra, CtxT]
|
325
325
|
) -> MakeInputContentHandler[InT_contra, CtxT]:
|
326
|
-
self._prompt_builder.
|
326
|
+
self._prompt_builder.make_input_content_impl = func
|
327
327
|
|
328
328
|
return func
|
329
329
|
|
@@ -359,30 +359,28 @@ class LLMAgent(
|
|
359
359
|
cur_cls = type(self)
|
360
360
|
base_cls = LLMAgent[Any, Any, Any]
|
361
361
|
|
362
|
-
if cur_cls.
|
363
|
-
self._prompt_builder.
|
362
|
+
if cur_cls._make_system_prompt is not base_cls._make_system_prompt: # noqa: SLF001
|
363
|
+
self._prompt_builder.make_system_prompt_impl = self._make_system_prompt
|
364
364
|
|
365
|
-
if cur_cls.
|
366
|
-
self._prompt_builder.
|
365
|
+
if cur_cls._make_input_content is not base_cls._make_input_content: # noqa: SLF001
|
366
|
+
self._prompt_builder.make_input_content_impl = self._make_input_content
|
367
367
|
|
368
|
-
if cur_cls.
|
369
|
-
self._set_memory_impl = self.
|
368
|
+
if cur_cls._set_memory is not base_cls._set_memory: # noqa: SLF001
|
369
|
+
self._set_memory_impl = self._set_memory
|
370
370
|
|
371
|
-
if cur_cls.
|
372
|
-
self._policy_executor.manage_memory_impl = self.
|
371
|
+
if cur_cls._manage_memory is not base_cls._manage_memory: # noqa: SLF001
|
372
|
+
self._policy_executor.manage_memory_impl = self._manage_memory
|
373
373
|
|
374
374
|
if (
|
375
|
-
cur_cls.
|
375
|
+
cur_cls._exit_tool_call_loop is not base_cls._exit_tool_call_loop # noqa: SLF001
|
376
376
|
):
|
377
|
-
self._policy_executor.exit_tool_call_loop_impl =
|
378
|
-
self._exit_tool_call_loop_fn
|
379
|
-
)
|
377
|
+
self._policy_executor.exit_tool_call_loop_impl = self._exit_tool_call_loop
|
380
378
|
|
381
379
|
self._parse_output_impl: (
|
382
380
|
ParseOutputHandler[InT_contra, OutT_co, CtxT] | None
|
383
381
|
) = None
|
384
382
|
|
385
|
-
def
|
383
|
+
def _make_system_prompt(
|
386
384
|
self, sys_args: LLMPromptArgs | None, *, ctx: RunContext[CtxT] | None = None
|
387
385
|
) -> str:
|
388
386
|
raise NotImplementedError(
|
@@ -390,7 +388,7 @@ class LLMAgent(
|
|
390
388
|
"if it's intended to be used as the system arguments formatter."
|
391
389
|
)
|
392
390
|
|
393
|
-
def
|
391
|
+
def _make_input_content(
|
394
392
|
self,
|
395
393
|
*,
|
396
394
|
in_args: InT_contra | None = None,
|
@@ -402,10 +400,10 @@ class LLMAgent(
|
|
402
400
|
"LLMAgent._format_in_args must be overridden by a subclass"
|
403
401
|
)
|
404
402
|
|
405
|
-
def
|
403
|
+
def _set_memory(
|
406
404
|
self,
|
407
405
|
prev_memory: LLMAgentMemory,
|
408
|
-
in_args:
|
406
|
+
in_args: Sequence[InT_contra] | None = None,
|
409
407
|
sys_prompt: LLMPrompt | None = None,
|
410
408
|
ctx: RunContext[Any] | None = None,
|
411
409
|
) -> LLMAgentMemory:
|
@@ -413,7 +411,7 @@ class LLMAgent(
|
|
413
411
|
"LLMAgent._set_memory must be overridden by a subclass"
|
414
412
|
)
|
415
413
|
|
416
|
-
def
|
414
|
+
def _exit_tool_call_loop(
|
417
415
|
self,
|
418
416
|
conversation: Messages,
|
419
417
|
*,
|
@@ -424,7 +422,7 @@ class LLMAgent(
|
|
424
422
|
"LLMAgent._exit_tool_call_loop must be overridden by a subclass"
|
425
423
|
)
|
426
424
|
|
427
|
-
def
|
425
|
+
def _manage_memory(
|
428
426
|
self,
|
429
427
|
memory: LLMAgentMemory,
|
430
428
|
*,
|
@@ -28,6 +28,9 @@ from .typing.tool import BaseTool, NamedToolChoice, ToolCall, ToolChoice
|
|
28
28
|
logger = getLogger(__name__)
|
29
29
|
|
30
30
|
|
31
|
+
FINAL_ANSWER_TOOL_NAME = "final_answer"
|
32
|
+
|
33
|
+
|
31
34
|
_FinalAnswerT = TypeVar("_FinalAnswerT")
|
32
35
|
|
33
36
|
|
@@ -102,7 +105,7 @@ class LLMPolicyExecutor(AutoInstanceAttributesMixin, Generic[_FinalAnswerT, CtxT
|
|
102
105
|
def max_turns(self) -> int:
|
103
106
|
return self._max_turns
|
104
107
|
|
105
|
-
def
|
108
|
+
def _exit_tool_call_loop(
|
106
109
|
self,
|
107
110
|
conversation: Messages,
|
108
111
|
*,
|
@@ -119,7 +122,7 @@ class LLMPolicyExecutor(AutoInstanceAttributesMixin, Generic[_FinalAnswerT, CtxT
|
|
119
122
|
|
120
123
|
return not bool(conversation[-1].tool_calls)
|
121
124
|
|
122
|
-
def
|
125
|
+
def _manage_memory(
|
123
126
|
self,
|
124
127
|
memory: LLMAgentMemory,
|
125
128
|
*,
|
@@ -318,7 +321,7 @@ class LLMPolicyExecutor(AutoInstanceAttributesMixin, Generic[_FinalAnswerT, CtxT
|
|
318
321
|
|
319
322
|
# When final_answer_tool_name is None, we use exit_tool_call_loop_impl
|
320
323
|
# to determine whether to exit the loop.
|
321
|
-
if self._final_answer_tool_name is None and self.
|
324
|
+
if self._final_answer_tool_name is None and self._exit_tool_call_loop(
|
322
325
|
conversation, ctx=ctx, num_turns=turns
|
323
326
|
):
|
324
327
|
return gen_message
|
@@ -353,7 +356,7 @@ class LLMPolicyExecutor(AutoInstanceAttributesMixin, Generic[_FinalAnswerT, CtxT
|
|
353
356
|
await self.call_tools(gen_message.tool_calls, memory=memory, ctx=ctx)
|
354
357
|
|
355
358
|
# Apply the memory management function if provided.
|
356
|
-
self.
|
359
|
+
self._manage_memory(memory, ctx=ctx, num_turns=turns)
|
357
360
|
|
358
361
|
# 4. Generate the next message based on the updated memory.
|
359
362
|
# In ReAct mode, we set tool_choice to "none" if we just called tools,
|
@@ -394,7 +397,7 @@ class LLMPolicyExecutor(AutoInstanceAttributesMixin, Generic[_FinalAnswerT, CtxT
|
|
394
397
|
while True:
|
395
398
|
conversation = memory.message_history.conversations[0]
|
396
399
|
|
397
|
-
if self._final_answer_tool_name is None and self.
|
400
|
+
if self._final_answer_tool_name is None and self._exit_tool_call_loop(
|
398
401
|
conversation, ctx=ctx, num_turns=turns
|
399
402
|
):
|
400
403
|
return
|
@@ -429,7 +432,7 @@ class LLMPolicyExecutor(AutoInstanceAttributesMixin, Generic[_FinalAnswerT, CtxT
|
|
429
432
|
):
|
430
433
|
yield tool_message_event
|
431
434
|
|
432
|
-
self.
|
435
|
+
self._manage_memory(memory, ctx=ctx, num_turns=turns)
|
433
436
|
|
434
437
|
tool_choice = (
|
435
438
|
"none" if (self._react_mode and gen_message.tool_calls) else "required"
|
@@ -458,11 +461,10 @@ class LLMPolicyExecutor(AutoInstanceAttributesMixin, Generic[_FinalAnswerT, CtxT
|
|
458
461
|
)
|
459
462
|
|
460
463
|
class FinalAnswerTool(BaseTool[self._final_answer_type, None, Any]):
|
461
|
-
name: str =
|
464
|
+
name: str = FINAL_ANSWER_TOOL_NAME
|
462
465
|
description: str = (
|
463
|
-
"You must
|
464
|
-
"
|
465
|
-
"Input arguments correspond to the final answer."
|
466
|
+
"You must call this tool to provide the final answer. "
|
467
|
+
"DO NOT output your answer before calling the tool. "
|
466
468
|
)
|
467
469
|
|
468
470
|
async def run(
|
@@ -1,4 +1,4 @@
|
|
1
|
-
from abc import ABC
|
1
|
+
from abc import ABC
|
2
2
|
from collections.abc import AsyncIterator, Sequence
|
3
3
|
from typing import Any, ClassVar, Generic, cast, final
|
4
4
|
|
@@ -20,7 +20,6 @@ class Processor(
|
|
20
20
|
1: "_out_type",
|
21
21
|
}
|
22
22
|
|
23
|
-
@abstractmethod
|
24
23
|
def __init__(self, name: ProcName, **kwargs: Any) -> None:
|
25
24
|
self._in_type: type[InT_contra]
|
26
25
|
self._out_type: type[OutT_co]
|
@@ -53,14 +53,14 @@ class PromptBuilder(AutoInstanceAttributesMixin, Generic[InT_contra, CtxT]):
|
|
53
53
|
self.in_prompt_template = in_prompt_template
|
54
54
|
self.sys_args_schema = sys_args_schema
|
55
55
|
self.usr_args_schema = usr_args_schema
|
56
|
-
self.
|
57
|
-
self.
|
58
|
-
None
|
59
|
-
)
|
56
|
+
self.make_system_prompt_impl: MakeSystemPromptHandler[CtxT] | None = None
|
57
|
+
self.make_input_content_impl: (
|
58
|
+
MakeInputContentHandler[InT_contra, CtxT] | None
|
59
|
+
) = None
|
60
60
|
|
61
61
|
self._in_args_type_adapter: TypeAdapter[InT_contra] = TypeAdapter(self._in_type)
|
62
62
|
|
63
|
-
def
|
63
|
+
def make_system_prompt(
|
64
64
|
self, sys_args: LLMPromptArgs | None = None, ctx: RunContext[CtxT] | None = None
|
65
65
|
) -> str | None:
|
66
66
|
if self.sys_prompt_template is None:
|
@@ -76,8 +76,8 @@ class PromptBuilder(AutoInstanceAttributesMixin, Generic[InT_contra, CtxT]):
|
|
76
76
|
"provided."
|
77
77
|
)
|
78
78
|
|
79
|
-
if self.
|
80
|
-
return self.
|
79
|
+
if self.make_system_prompt_impl:
|
80
|
+
return self.make_system_prompt_impl(sys_args=val_sys_args, ctx=ctx)
|
81
81
|
|
82
82
|
sys_args_dict = (
|
83
83
|
val_sys_args.model_dump(exclude_unset=True) if val_sys_args else {}
|
@@ -85,7 +85,7 @@ class PromptBuilder(AutoInstanceAttributesMixin, Generic[InT_contra, CtxT]):
|
|
85
85
|
|
86
86
|
return self.sys_prompt_template.format(**sys_args_dict)
|
87
87
|
|
88
|
-
def
|
88
|
+
def make_input_content(
|
89
89
|
self,
|
90
90
|
*,
|
91
91
|
in_args: InT_contra | None,
|
@@ -97,8 +97,8 @@ class PromptBuilder(AutoInstanceAttributesMixin, Generic[InT_contra, CtxT]):
|
|
97
97
|
in_args=in_args, usr_args=usr_args
|
98
98
|
)
|
99
99
|
|
100
|
-
if self.
|
101
|
-
return self.
|
100
|
+
if self.make_input_content_impl:
|
101
|
+
return self.make_input_content_impl(
|
102
102
|
in_args=val_in_args, usr_args=val_usr_args, batch_idx=batch_idx, ctx=ctx
|
103
103
|
)
|
104
104
|
|
@@ -126,7 +126,7 @@ class PromptBuilder(AutoInstanceAttributesMixin, Generic[InT_contra, CtxT]):
|
|
126
126
|
return self._usr_messages_from_content_parts(chat_inputs)
|
127
127
|
|
128
128
|
in_content_batch = [
|
129
|
-
self.
|
129
|
+
self.make_input_content(
|
130
130
|
in_args=in_args, usr_args=usr_args, batch_idx=i, ctx=ctx
|
131
131
|
)
|
132
132
|
for i, in_args in enumerate(in_args_batch or [None])
|
@@ -88,6 +88,9 @@ def validate_obj_from_json_or_py_string(
|
|
88
88
|
else:
|
89
89
|
_selected_adapter = adapter
|
90
90
|
|
91
|
+
if _selected_adapter._type is str: # type: ignore[arg-type]
|
92
|
+
return s
|
93
|
+
|
91
94
|
try:
|
92
95
|
if from_substring:
|
93
96
|
parsed = parse_json_or_py_substring(s, return_none_on_failure=True)
|
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
|
{grasp_agents-0.3.1 → grasp_agents-0.3.3}/src/grasp_agents/openai/completion_chunk_converters.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
|
{grasp_agents-0.3.1 → grasp_agents-0.3.3}/src/grasp_agents/rate_limiting/rate_limiter_chunked.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
|