grasp_agents 0.2.1__py3-none-any.whl → 0.2.2__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/__init__.py +38 -0
- grasp_agents/llm_agent.py +4 -4
- grasp_agents/openai/__init__.py +4 -0
- grasp_agents/openai/openai_llm.py +1 -2
- grasp_agents/prompt_builder.py +2 -2
- grasp_agents/workflow/looped_agent.py +14 -14
- grasp_agents/workflow/sequential_agent.py +5 -5
- grasp_agents/workflow/workflow_agent.py +9 -11
- {grasp_agents-0.2.1.dist-info → grasp_agents-0.2.2.dist-info}/METADATA +1 -1
- {grasp_agents-0.2.1.dist-info → grasp_agents-0.2.2.dist-info}/RECORD +12 -11
- {grasp_agents-0.2.1.dist-info → grasp_agents-0.2.2.dist-info}/WHEEL +0 -0
- {grasp_agents-0.2.1.dist-info → grasp_agents-0.2.2.dist-info}/licenses/LICENSE.md +0 -0
grasp_agents/__init__.py
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
# pyright: reportUnusedImport=false
|
2
|
+
|
3
|
+
|
4
|
+
from .agent_message import AgentMessage
|
5
|
+
from .base_agent import BaseAgent
|
6
|
+
from .comm_agent import CommunicatingAgent
|
7
|
+
from .llm import LLM, LLMSettings
|
8
|
+
from .llm_agent import LLMAgent
|
9
|
+
from .run_context import RunArgs, RunContextWrapper
|
10
|
+
from .typing.completion import Completion
|
11
|
+
from .typing.content import Content, ImageData
|
12
|
+
from .typing.io import AgentID, AgentState, LLMFormattedArgs, LLMPrompt, LLMPromptArgs
|
13
|
+
from .typing.message import AssistantMessage, Conversation, SystemMessage, UserMessage
|
14
|
+
from .typing.tool import BaseTool
|
15
|
+
|
16
|
+
__all__ = [
|
17
|
+
"LLM",
|
18
|
+
"AgentID",
|
19
|
+
"AgentMessage",
|
20
|
+
"AgentState",
|
21
|
+
"AssistantMessage",
|
22
|
+
"BaseAgent",
|
23
|
+
"BaseTool",
|
24
|
+
"CommunicatingAgent",
|
25
|
+
"Completion",
|
26
|
+
"Content",
|
27
|
+
"Conversation",
|
28
|
+
"ImageData",
|
29
|
+
"LLMAgent",
|
30
|
+
"LLMFormattedArgs",
|
31
|
+
"LLMPrompt",
|
32
|
+
"LLMPromptArgs",
|
33
|
+
"LLMSettings",
|
34
|
+
"RunArgs",
|
35
|
+
"RunContextWrapper",
|
36
|
+
"SystemMessage",
|
37
|
+
"UserMessage",
|
38
|
+
]
|
grasp_agents/llm_agent.py
CHANGED
@@ -395,9 +395,9 @@ class LLMAgent(
|
|
395
395
|
self._tool_orchestrator.manage_agent_state_impl = self._manage_agent_state
|
396
396
|
|
397
397
|
if (
|
398
|
-
cur_cls.
|
398
|
+
cur_cls._exit_tool_call_loop is not base_cls._exit_tool_call_loop # noqa: SLF001
|
399
399
|
):
|
400
|
-
self._tool_orchestrator.exit_tool_call_loop_impl = self.
|
400
|
+
self._tool_orchestrator.exit_tool_call_loop_impl = self._exit_tool_call_loop
|
401
401
|
|
402
402
|
self._parse_output_impl: ParseOutputHandler[InT, OutT, CtxT] | None = None
|
403
403
|
|
@@ -414,9 +414,9 @@ class LLMAgent(
|
|
414
414
|
|
415
415
|
def _format_inp_args(
|
416
416
|
self,
|
417
|
+
*,
|
417
418
|
usr_args: LLMPromptArgs,
|
418
419
|
rcv_args: InT,
|
419
|
-
*,
|
420
420
|
batch_idx: int = 0,
|
421
421
|
ctx: RunContextWrapper[CtxT] | None = None,
|
422
422
|
) -> LLMFormattedArgs:
|
@@ -436,7 +436,7 @@ class LLMAgent(
|
|
436
436
|
"LLMAgent._set_agent_state_handler must be overridden by a subclass"
|
437
437
|
)
|
438
438
|
|
439
|
-
def
|
439
|
+
def _exit_tool_call_loop(
|
440
440
|
self,
|
441
441
|
conversation: Conversation,
|
442
442
|
*,
|
grasp_agents/openai/__init__.py
CHANGED
@@ -81,3 +81,7 @@ from openai.types.shared_params.response_format_json_schema import (
|
|
81
81
|
from openai.types.shared_params.response_format_text import (
|
82
82
|
ResponseFormatText,
|
83
83
|
)
|
84
|
+
|
85
|
+
from .openai_llm import OpenAILLM, OpenAILLMSettings
|
86
|
+
|
87
|
+
__all__ = ["OpenAILLM", "OpenAILLMSettings"]
|
@@ -3,10 +3,9 @@ from collections.abc import Iterable
|
|
3
3
|
from copy import deepcopy
|
4
4
|
from typing import Any, Literal
|
5
5
|
|
6
|
-
from pydantic import BaseModel
|
7
|
-
|
8
6
|
from openai import AsyncOpenAI
|
9
7
|
from openai._types import NOT_GIVEN # type: ignore[import]
|
8
|
+
from pydantic import BaseModel
|
10
9
|
|
11
10
|
from ..cloud_llm import APIProvider, CloudLLM, CloudLLMSettings
|
12
11
|
from ..http_client import AsyncHTTPClientParams
|
grasp_agents/prompt_builder.py
CHANGED
@@ -33,9 +33,9 @@ class FormatSystemArgsHandler(Protocol[CtxT]):
|
|
33
33
|
class FormatInputArgsHandler(Protocol[InT, CtxT]):
|
34
34
|
def __call__(
|
35
35
|
self,
|
36
|
+
*,
|
36
37
|
usr_args: LLMPromptArgs,
|
37
38
|
rcv_args: InT,
|
38
|
-
*,
|
39
39
|
batch_idx: int,
|
40
40
|
ctx: RunContextWrapper[CtxT] | None,
|
41
41
|
) -> LLMFormattedArgs: ...
|
@@ -77,9 +77,9 @@ class PromptBuilder(AutoInstanceAttributesMixin, Generic[InT, CtxT]):
|
|
77
77
|
|
78
78
|
def _format_inp_args(
|
79
79
|
self,
|
80
|
+
*,
|
80
81
|
usr_args: LLMPromptArgs,
|
81
82
|
rcv_args: InT,
|
82
|
-
*,
|
83
83
|
batch_idx: int = 0,
|
84
84
|
ctx: RunContextWrapper[CtxT] | None = None,
|
85
85
|
) -> LLMFormattedArgs:
|
@@ -13,10 +13,10 @@ logger = getLogger(__name__)
|
|
13
13
|
_EH_OutT = TypeVar("_EH_OutT", contravariant=True) # noqa: PLC0105
|
14
14
|
|
15
15
|
|
16
|
-
class
|
16
|
+
class ExitWorkflowLoopHandler(Protocol[_EH_OutT, CtxT]):
|
17
17
|
def __call__(
|
18
18
|
self,
|
19
|
-
output_message: AgentMessage[_EH_OutT,
|
19
|
+
output_message: AgentMessage[_EH_OutT, Any],
|
20
20
|
ctx: RunContextWrapper[CtxT] | None,
|
21
21
|
**kwargs: Any,
|
22
22
|
) -> bool: ...
|
@@ -31,8 +31,8 @@ class LoopedWorkflowAgent(WorkflowAgent[InT, OutT, CtxT], Generic[InT, OutT, Ctx
|
|
31
31
|
def __init__(
|
32
32
|
self,
|
33
33
|
agent_id: AgentID,
|
34
|
-
subagents: Sequence[CommunicatingAgent[Any, Any,
|
35
|
-
exit_agent: CommunicatingAgent[Any, OutT,
|
34
|
+
subagents: Sequence[CommunicatingAgent[Any, Any, Any, CtxT]],
|
35
|
+
exit_agent: CommunicatingAgent[Any, OutT, Any, CtxT],
|
36
36
|
message_pool: AgentMessagePool[CtxT] | None = None,
|
37
37
|
recipient_ids: list[AgentID] | None = None,
|
38
38
|
dynamic_routing: bool = False,
|
@@ -51,27 +51,27 @@ class LoopedWorkflowAgent(WorkflowAgent[InT, OutT, CtxT], Generic[InT, OutT, Ctx
|
|
51
51
|
|
52
52
|
self._max_iterations = max_iterations
|
53
53
|
|
54
|
-
self.
|
54
|
+
self._exit_workflow_loop_impl: ExitWorkflowLoopHandler[OutT, CtxT] | None = None
|
55
55
|
|
56
56
|
@property
|
57
57
|
def max_iterations(self) -> int:
|
58
58
|
return self._max_iterations
|
59
59
|
|
60
|
-
def
|
61
|
-
self, func:
|
62
|
-
) ->
|
63
|
-
self.
|
60
|
+
def exit_workflow_loop_handler(
|
61
|
+
self, func: ExitWorkflowLoopHandler[OutT, CtxT]
|
62
|
+
) -> ExitWorkflowLoopHandler[OutT, CtxT]:
|
63
|
+
self._exit_workflow_loop_impl = func
|
64
64
|
|
65
65
|
return func
|
66
66
|
|
67
67
|
def _exit_workflow_loop(
|
68
68
|
self,
|
69
|
-
output_message: AgentMessage[OutT,
|
69
|
+
output_message: AgentMessage[OutT, Any],
|
70
70
|
ctx: RunContextWrapper[CtxT] | None,
|
71
71
|
**kwargs: Any,
|
72
72
|
) -> bool:
|
73
|
-
if self.
|
74
|
-
return self.
|
73
|
+
if self._exit_workflow_loop_impl:
|
74
|
+
return self._exit_workflow_loop_impl(output_message, ctx=ctx, **kwargs)
|
75
75
|
|
76
76
|
return False
|
77
77
|
|
@@ -80,15 +80,15 @@ class LoopedWorkflowAgent(WorkflowAgent[InT, OutT, CtxT], Generic[InT, OutT, Ctx
|
|
80
80
|
self,
|
81
81
|
inp_items: Any | None = None,
|
82
82
|
*,
|
83
|
+
rcv_message: AgentMessage[InT, Any] | None = None,
|
83
84
|
ctx: RunContextWrapper[CtxT] | None = None,
|
84
|
-
rcv_message: AgentMessage[InT, AgentState] | None = None,
|
85
85
|
entry_point: bool = False,
|
86
86
|
forbid_state_change: bool = False,
|
87
87
|
**kwargs: Any,
|
88
88
|
) -> AgentMessage[OutT, AgentState]:
|
89
89
|
agent_message = rcv_message
|
90
90
|
num_iterations = 0
|
91
|
-
exit_message: AgentMessage[OutT,
|
91
|
+
exit_message: AgentMessage[OutT, Any] | None = None
|
92
92
|
|
93
93
|
while True:
|
94
94
|
for subagent in self.subagents:
|
@@ -4,7 +4,7 @@ from typing import Any, ClassVar, Generic, cast, final
|
|
4
4
|
from ..agent_message_pool import AgentMessage, AgentMessagePool
|
5
5
|
from ..comm_agent import CommunicatingAgent
|
6
6
|
from ..run_context import CtxT, RunContextWrapper
|
7
|
-
from ..typing.io import AgentID,
|
7
|
+
from ..typing.io import AgentID, InT, OutT
|
8
8
|
from .workflow_agent import WorkflowAgent
|
9
9
|
|
10
10
|
|
@@ -17,7 +17,7 @@ class SequentialWorkflowAgent(WorkflowAgent[InT, OutT, CtxT], Generic[InT, OutT,
|
|
17
17
|
def __init__(
|
18
18
|
self,
|
19
19
|
agent_id: AgentID,
|
20
|
-
subagents: Sequence[CommunicatingAgent[Any, Any,
|
20
|
+
subagents: Sequence[CommunicatingAgent[Any, Any, Any, CtxT]],
|
21
21
|
message_pool: AgentMessagePool[CtxT] | None = None,
|
22
22
|
recipient_ids: list[AgentID] | None = None,
|
23
23
|
dynamic_routing: bool = False,
|
@@ -38,12 +38,12 @@ class SequentialWorkflowAgent(WorkflowAgent[InT, OutT, CtxT], Generic[InT, OutT,
|
|
38
38
|
self,
|
39
39
|
inp_items: Any | None = None,
|
40
40
|
*,
|
41
|
+
rcv_message: AgentMessage[InT, Any] | None = None,
|
41
42
|
ctx: RunContextWrapper[CtxT] | None = None,
|
42
|
-
rcv_message: AgentMessage[InT, AgentState] | None = None,
|
43
43
|
entry_point: bool = False,
|
44
44
|
forbid_state_change: bool = False,
|
45
45
|
**kwargs: Any,
|
46
|
-
) -> AgentMessage[OutT,
|
46
|
+
) -> AgentMessage[OutT, Any]:
|
47
47
|
agent_message = rcv_message
|
48
48
|
for subagent in self.subagents:
|
49
49
|
agent_message = await subagent.run(
|
@@ -57,4 +57,4 @@ class SequentialWorkflowAgent(WorkflowAgent[InT, OutT, CtxT], Generic[InT, OutT,
|
|
57
57
|
inp_items = None
|
58
58
|
entry_point = False
|
59
59
|
|
60
|
-
return cast("AgentMessage[OutT,
|
60
|
+
return cast("AgentMessage[OutT, Any]", agent_message)
|
@@ -5,13 +5,11 @@ from typing import Any, ClassVar, Generic
|
|
5
5
|
from ..agent_message_pool import AgentMessage, AgentMessagePool
|
6
6
|
from ..comm_agent import CommunicatingAgent
|
7
7
|
from ..run_context import CtxT, RunContextWrapper
|
8
|
-
from ..typing.io import AgentID,
|
8
|
+
from ..typing.io import AgentID, InT, OutT
|
9
9
|
|
10
10
|
|
11
11
|
class WorkflowAgent(
|
12
|
-
CommunicatingAgent[InT, OutT,
|
13
|
-
ABC,
|
14
|
-
Generic[InT, OutT, CtxT],
|
12
|
+
CommunicatingAgent[InT, OutT, Any, CtxT], ABC, Generic[InT, OutT, CtxT]
|
15
13
|
):
|
16
14
|
_generic_arg_to_instance_attr_map: ClassVar[dict[int, str]] = {
|
17
15
|
0: "_in_type",
|
@@ -21,9 +19,9 @@ class WorkflowAgent(
|
|
21
19
|
def __init__(
|
22
20
|
self,
|
23
21
|
agent_id: AgentID,
|
24
|
-
subagents: Sequence[CommunicatingAgent[Any, Any,
|
25
|
-
start_agent: CommunicatingAgent[InT, Any,
|
26
|
-
end_agent: CommunicatingAgent[Any, OutT,
|
22
|
+
subagents: Sequence[CommunicatingAgent[Any, Any, Any, CtxT]],
|
23
|
+
start_agent: CommunicatingAgent[InT, Any, Any, CtxT],
|
24
|
+
end_agent: CommunicatingAgent[Any, OutT, Any, CtxT],
|
27
25
|
message_pool: AgentMessagePool[CtxT] | None = None,
|
28
26
|
recipient_ids: list[AgentID] | None = None,
|
29
27
|
dynamic_routing: bool = False,
|
@@ -53,11 +51,11 @@ class WorkflowAgent(
|
|
53
51
|
)
|
54
52
|
|
55
53
|
@property
|
56
|
-
def start_agent(self) -> CommunicatingAgent[InT, Any,
|
54
|
+
def start_agent(self) -> CommunicatingAgent[InT, Any, Any, CtxT]:
|
57
55
|
return self._start_agent
|
58
56
|
|
59
57
|
@property
|
60
|
-
def end_agent(self) -> CommunicatingAgent[Any, OutT,
|
58
|
+
def end_agent(self) -> CommunicatingAgent[Any, OutT, Any, CtxT]:
|
61
59
|
return self._end_agent
|
62
60
|
|
63
61
|
@abstractmethod
|
@@ -65,10 +63,10 @@ class WorkflowAgent(
|
|
65
63
|
self,
|
66
64
|
inp_items: Any | None = None,
|
67
65
|
*,
|
66
|
+
rcv_message: AgentMessage[InT, Any] | None = None,
|
68
67
|
ctx: RunContextWrapper[CtxT] | None = None,
|
69
|
-
rcv_message: AgentMessage[InT, AgentState] | None = None,
|
70
68
|
entry_point: bool = False,
|
71
69
|
forbid_state_change: bool = False,
|
72
70
|
**generation_kwargs: Any,
|
73
|
-
) -> AgentMessage[OutT,
|
71
|
+
) -> AgentMessage[OutT, Any]:
|
74
72
|
pass
|
@@ -1,3 +1,4 @@
|
|
1
|
+
grasp_agents/__init__.py,sha256=WPNUUFbucwli6oWIwxbckz0zpY4W2LnND0o7melYZOw,979
|
1
2
|
grasp_agents/agent_message.py,sha256=eJV5n44t8EIE6M3jl48Ld7pmaW9dDhBX_FWm_u9yGWE,877
|
2
3
|
grasp_agents/agent_message_pool.py,sha256=OKTXNEo9LAJTQJkzxmJ3TQgWw7WJKOzrKCJjeHpln6o,3158
|
3
4
|
grasp_agents/base_agent.py,sha256=BOLYxS_cSisOR4qupUYIVn2FW15svit3jbNNfjw_cT8,1347
|
@@ -8,21 +9,21 @@ grasp_agents/generics_utils.py,sha256=kw4Odte6Nvl4c9U7-mKPgXCavWZXo009zYDHAA0BR3
|
|
8
9
|
grasp_agents/grasp_logging.py,sha256=H1GYhXdQvVkmauFDZ-KDwvVmPQHZUUm9sRqX_ObK2xI,1111
|
9
10
|
grasp_agents/http_client.py,sha256=KZva2MjJjuI5ohUeU8RdTAImUnQYaqBrV2jDH8smbJw,738
|
10
11
|
grasp_agents/llm.py,sha256=n67lXbB8spr_i3Xz0Plw7oeykfjQmVHHkSiveqBB5Lw,3150
|
11
|
-
grasp_agents/llm_agent.py,sha256=
|
12
|
+
grasp_agents/llm_agent.py,sha256=Lx6L9ahe9WYnzKpCc-XaIyNw73U2YHtTb6OhFGUv9mU,14989
|
12
13
|
grasp_agents/llm_agent_state.py,sha256=lLdYni2f3TA5zJLf_jqR5DSWqVI_zP2YfNrwEGqZnvg,2402
|
13
14
|
grasp_agents/memory.py,sha256=X1YtVX8XxP5KnGPMW8BqjID8QK4hTG2obxoyhnnZ4pU,5575
|
14
15
|
grasp_agents/printer.py,sha256=Jk6OJExio53gbKBod5Dd8Y3CWYrVb4K5q4UJ8i9cQvo,5024
|
15
|
-
grasp_agents/prompt_builder.py,sha256=
|
16
|
+
grasp_agents/prompt_builder.py,sha256=wb7V8JXjD3IeD3l24HItUkvGmVE4e0PUzu8IT_9rgko,8208
|
16
17
|
grasp_agents/run_context.py,sha256=M4w_HXl5aiz-18CDlfNCRNZm3m5UIQMrjKkhurFTtkY,2229
|
17
18
|
grasp_agents/tool_orchestrator.py,sha256=--E-ue7Z8nK6NwqGbWeCQWfTjWIbPxEe5X54bjPe62M,6107
|
18
19
|
grasp_agents/usage_tracker.py,sha256=5YuN6hpg6HASdg-hOylgWzhCiORmDMnZuQtbISfhm_4,3378
|
19
20
|
grasp_agents/utils.py,sha256=gKUtJ6__HB7yHBUPWY5tkdSAfgj3_R3--s2J5B5fBPE,5739
|
20
|
-
grasp_agents/openai/__init__.py,sha256=
|
21
|
+
grasp_agents/openai/__init__.py,sha256=P7oa4tdJ2JKJv16frRi1C09FnrMayuOYomu5l95uayE,3196
|
21
22
|
grasp_agents/openai/completion_converters.py,sha256=lX9h1kaGAo5ttsl-4V7l4x8IpjxJaJJtyU2cKu3-EOc,1871
|
22
23
|
grasp_agents/openai/content_converters.py,sha256=6GI0D7xJalzsiawAJOyCUzTJTo0NQdpv87YKmfN0LYQ,2631
|
23
24
|
grasp_agents/openai/converters.py,sha256=DBXBxow9oRG6pc8inpZBLiuUqHzVfpscmHFpN9bAdvc,5276
|
24
25
|
grasp_agents/openai/message_converters.py,sha256=KjF6FbXzwlWdM-1YT3cswUV-74sjiwOhLFPMY4sJ5Xk,4593
|
25
|
-
grasp_agents/openai/openai_llm.py,sha256=
|
26
|
+
grasp_agents/openai/openai_llm.py,sha256=93dSQXed9yqMIVLKJoHp5rauin7xAc-8Aokf1vFJSho,6131
|
26
27
|
grasp_agents/openai/tool_converters.py,sha256=KhWRETkjhjocISUo_HBZ8QfBiyTOoC5WurPNAR4BYxc,1027
|
27
28
|
grasp_agents/rate_limiting/__init__.py,sha256=KRgtF_E7R3YfA2cpYcFcZ7wycV0pWVJ0xRQC7YhiIEQ,158
|
28
29
|
grasp_agents/rate_limiting/rate_limiter_chunked.py,sha256=BPgkUXvhmZhTpZs2T6uujNFuxH_kYHiISuf6_-eNhUc,5544
|
@@ -36,10 +37,10 @@ grasp_agents/typing/io.py,sha256=uxSvbD05UK5nIhPfDvXIoGuU6xRMW4USZq_4IgBeGCY,609
|
|
36
37
|
grasp_agents/typing/message.py,sha256=XgPjXeh47e2GG1AYslhxaNw1Ax6Ozatga_7X2SFFKMA,3826
|
37
38
|
grasp_agents/typing/tool.py,sha256=e0pTMnRcpMpGNVQ8muE9wnh7LdIgh92AqXDo9hMDxf0,1960
|
38
39
|
grasp_agents/workflow/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
39
|
-
grasp_agents/workflow/looped_agent.py,sha256=
|
40
|
-
grasp_agents/workflow/sequential_agent.py,sha256=
|
41
|
-
grasp_agents/workflow/workflow_agent.py,sha256=
|
42
|
-
grasp_agents-0.2.
|
43
|
-
grasp_agents-0.2.
|
44
|
-
grasp_agents-0.2.
|
45
|
-
grasp_agents-0.2.
|
40
|
+
grasp_agents/workflow/looped_agent.py,sha256=VU1Gst_qacU6TrJ0PcwHYOUgRkdR3NdiXm7KoD3U0vw,3903
|
41
|
+
grasp_agents/workflow/sequential_agent.py,sha256=4aFLZDJk4A1_0I0mvISIqyO8Nlz5Q5rT7Ig5Zy80cHg,2014
|
42
|
+
grasp_agents/workflow/workflow_agent.py,sha256=FzTil10WXzOIHzum-yo2mEETfjoY9RMXUycZhlLNqkw,2383
|
43
|
+
grasp_agents-0.2.2.dist-info/METADATA,sha256=ejV2_4MaH9s2zh6HgVcHpae9HP9FzZo8eXZ8xRrEdPY,6889
|
44
|
+
grasp_agents-0.2.2.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
45
|
+
grasp_agents-0.2.2.dist-info/licenses/LICENSE.md,sha256=-nNNdWqGB8gJ2O-peFQ2Irshv5tW5pHKyTcYkwvH7CE,1201
|
46
|
+
grasp_agents-0.2.2.dist-info/RECORD,,
|
File without changes
|
File without changes
|