grasp_agents 0.2.10__py3-none-any.whl → 0.3.1__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 +15 -14
- grasp_agents/cloud_llm.py +118 -131
- grasp_agents/comm_processor.py +201 -0
- grasp_agents/generics_utils.py +15 -7
- grasp_agents/llm.py +60 -31
- grasp_agents/llm_agent.py +229 -278
- grasp_agents/llm_agent_memory.py +58 -0
- grasp_agents/llm_policy_executor.py +482 -0
- grasp_agents/memory.py +20 -134
- grasp_agents/message_history.py +140 -0
- grasp_agents/openai/__init__.py +54 -36
- grasp_agents/openai/completion_chunk_converters.py +78 -0
- grasp_agents/openai/completion_converters.py +53 -30
- grasp_agents/openai/content_converters.py +13 -14
- grasp_agents/openai/converters.py +44 -68
- grasp_agents/openai/message_converters.py +58 -72
- grasp_agents/openai/openai_llm.py +101 -42
- grasp_agents/openai/tool_converters.py +24 -19
- grasp_agents/packet.py +24 -0
- grasp_agents/packet_pool.py +91 -0
- grasp_agents/printer.py +29 -15
- grasp_agents/processor.py +194 -0
- grasp_agents/prompt_builder.py +173 -176
- grasp_agents/run_context.py +21 -41
- grasp_agents/typing/completion.py +58 -12
- grasp_agents/typing/completion_chunk.py +173 -0
- grasp_agents/typing/converters.py +8 -12
- grasp_agents/typing/events.py +86 -0
- grasp_agents/typing/io.py +4 -13
- grasp_agents/typing/message.py +12 -50
- grasp_agents/typing/tool.py +52 -26
- grasp_agents/usage_tracker.py +6 -6
- grasp_agents/utils.py +3 -3
- grasp_agents/workflow/looped_workflow.py +132 -0
- grasp_agents/workflow/parallel_processor.py +95 -0
- grasp_agents/workflow/sequential_workflow.py +66 -0
- grasp_agents/workflow/workflow_processor.py +78 -0
- {grasp_agents-0.2.10.dist-info → grasp_agents-0.3.1.dist-info}/METADATA +41 -50
- grasp_agents-0.3.1.dist-info/RECORD +51 -0
- grasp_agents/agent_message.py +0 -27
- grasp_agents/agent_message_pool.py +0 -92
- grasp_agents/base_agent.py +0 -51
- grasp_agents/comm_agent.py +0 -217
- grasp_agents/llm_agent_state.py +0 -79
- grasp_agents/tool_orchestrator.py +0 -203
- grasp_agents/workflow/looped_agent.py +0 -120
- grasp_agents/workflow/sequential_agent.py +0 -63
- grasp_agents/workflow/workflow_agent.py +0 -73
- grasp_agents-0.2.10.dist-info/RECORD +0 -46
- {grasp_agents-0.2.10.dist-info → grasp_agents-0.3.1.dist-info}/WHEEL +0 -0
- {grasp_agents-0.2.10.dist-info → grasp_agents-0.3.1.dist-info}/licenses/LICENSE.md +0 -0
@@ -1,120 +0,0 @@
|
|
1
|
-
from collections.abc import Sequence
|
2
|
-
from logging import getLogger
|
3
|
-
from typing import Any, ClassVar, Generic, Protocol, TypeVar, cast, final
|
4
|
-
|
5
|
-
from ..agent_message_pool import AgentMessage, AgentMessagePool
|
6
|
-
from ..comm_agent import CommunicatingAgent
|
7
|
-
from ..run_context import CtxT, RunContextWrapper
|
8
|
-
from ..typing.io import AgentID, AgentState, InT, OutT
|
9
|
-
from .workflow_agent import WorkflowAgent
|
10
|
-
|
11
|
-
logger = getLogger(__name__)
|
12
|
-
|
13
|
-
_EH_OutT = TypeVar("_EH_OutT", contravariant=True) # noqa: PLC0105
|
14
|
-
|
15
|
-
|
16
|
-
class ExitWorkflowLoopHandler(Protocol[_EH_OutT, CtxT]):
|
17
|
-
def __call__(
|
18
|
-
self,
|
19
|
-
output_message: AgentMessage[_EH_OutT, Any],
|
20
|
-
ctx: RunContextWrapper[CtxT] | None,
|
21
|
-
**kwargs: Any,
|
22
|
-
) -> bool: ...
|
23
|
-
|
24
|
-
|
25
|
-
class LoopedWorkflowAgent(WorkflowAgent[InT, OutT, CtxT], Generic[InT, OutT, CtxT]):
|
26
|
-
_generic_arg_to_instance_attr_map: ClassVar[dict[int, str]] = {
|
27
|
-
0: "_in_type",
|
28
|
-
1: "_out_type",
|
29
|
-
}
|
30
|
-
|
31
|
-
def __init__(
|
32
|
-
self,
|
33
|
-
agent_id: AgentID,
|
34
|
-
subagents: Sequence[CommunicatingAgent[Any, Any, Any, CtxT]],
|
35
|
-
exit_agent: CommunicatingAgent[Any, OutT, Any, CtxT],
|
36
|
-
message_pool: AgentMessagePool[CtxT] | None = None,
|
37
|
-
recipient_ids: list[AgentID] | None = None,
|
38
|
-
dynamic_routing: bool = False,
|
39
|
-
max_iterations: int = 10,
|
40
|
-
**kwargs: Any, # noqa: ARG002
|
41
|
-
) -> None:
|
42
|
-
super().__init__(
|
43
|
-
subagents=subagents,
|
44
|
-
agent_id=agent_id,
|
45
|
-
start_agent=subagents[0],
|
46
|
-
end_agent=exit_agent,
|
47
|
-
message_pool=message_pool,
|
48
|
-
recipient_ids=recipient_ids,
|
49
|
-
dynamic_routing=dynamic_routing,
|
50
|
-
)
|
51
|
-
|
52
|
-
self._max_iterations = max_iterations
|
53
|
-
|
54
|
-
self._exit_workflow_loop_impl: ExitWorkflowLoopHandler[OutT, CtxT] | None = None
|
55
|
-
|
56
|
-
@property
|
57
|
-
def max_iterations(self) -> int:
|
58
|
-
return self._max_iterations
|
59
|
-
|
60
|
-
def exit_workflow_loop_handler(
|
61
|
-
self, func: ExitWorkflowLoopHandler[OutT, CtxT]
|
62
|
-
) -> ExitWorkflowLoopHandler[OutT, CtxT]:
|
63
|
-
self._exit_workflow_loop_impl = func
|
64
|
-
|
65
|
-
return func
|
66
|
-
|
67
|
-
def _exit_workflow_loop(
|
68
|
-
self,
|
69
|
-
output_message: AgentMessage[OutT, Any],
|
70
|
-
*,
|
71
|
-
ctx: RunContextWrapper[CtxT] | None = None,
|
72
|
-
**kwargs: Any,
|
73
|
-
) -> bool:
|
74
|
-
if self._exit_workflow_loop_impl:
|
75
|
-
return self._exit_workflow_loop_impl(output_message, ctx=ctx, **kwargs)
|
76
|
-
|
77
|
-
return False
|
78
|
-
|
79
|
-
@final
|
80
|
-
async def run(
|
81
|
-
self,
|
82
|
-
chat_inputs: Any | None = None,
|
83
|
-
*,
|
84
|
-
in_args: InT | Sequence[InT] | None = None,
|
85
|
-
in_message: AgentMessage[InT, Any] | None = None,
|
86
|
-
ctx: RunContextWrapper[CtxT] | None = None,
|
87
|
-
entry_point: bool = False,
|
88
|
-
forbid_state_change: bool = False,
|
89
|
-
**kwargs: Any,
|
90
|
-
) -> AgentMessage[OutT, AgentState]:
|
91
|
-
agent_message = in_message
|
92
|
-
num_iterations = 0
|
93
|
-
exit_message: AgentMessage[OutT, Any] | None = None
|
94
|
-
|
95
|
-
while True:
|
96
|
-
for subagent in self.subagents:
|
97
|
-
agent_message = await subagent.run(
|
98
|
-
chat_inputs=chat_inputs,
|
99
|
-
in_args=in_args,
|
100
|
-
in_message=agent_message,
|
101
|
-
entry_point=entry_point,
|
102
|
-
forbid_state_change=forbid_state_change,
|
103
|
-
ctx=ctx,
|
104
|
-
**kwargs,
|
105
|
-
)
|
106
|
-
|
107
|
-
if subagent is self._end_agent:
|
108
|
-
num_iterations += 1
|
109
|
-
exit_message = cast("AgentMessage[OutT, AgentState]", agent_message)
|
110
|
-
if self._exit_workflow_loop(exit_message, ctx=ctx):
|
111
|
-
return exit_message
|
112
|
-
if num_iterations >= self._max_iterations:
|
113
|
-
logger.info(
|
114
|
-
f"Max iterations reached ({self._max_iterations}). Exiting loop."
|
115
|
-
)
|
116
|
-
return exit_message
|
117
|
-
|
118
|
-
chat_inputs = None
|
119
|
-
in_args = None
|
120
|
-
entry_point = False
|
@@ -1,63 +0,0 @@
|
|
1
|
-
from collections.abc import Sequence
|
2
|
-
from typing import Any, ClassVar, Generic, cast, final
|
3
|
-
|
4
|
-
from ..agent_message_pool import AgentMessage, AgentMessagePool
|
5
|
-
from ..comm_agent import CommunicatingAgent
|
6
|
-
from ..run_context import CtxT, RunContextWrapper
|
7
|
-
from ..typing.io import AgentID, InT, OutT
|
8
|
-
from .workflow_agent import WorkflowAgent
|
9
|
-
|
10
|
-
|
11
|
-
class SequentialWorkflowAgent(WorkflowAgent[InT, OutT, CtxT], Generic[InT, OutT, CtxT]):
|
12
|
-
_generic_arg_to_instance_attr_map: ClassVar[dict[int, str]] = {
|
13
|
-
0: "_in_type",
|
14
|
-
1: "_out_type",
|
15
|
-
}
|
16
|
-
|
17
|
-
def __init__(
|
18
|
-
self,
|
19
|
-
agent_id: AgentID,
|
20
|
-
subagents: Sequence[CommunicatingAgent[Any, Any, Any, CtxT]],
|
21
|
-
message_pool: AgentMessagePool[CtxT] | None = None,
|
22
|
-
recipient_ids: list[AgentID] | None = None,
|
23
|
-
dynamic_routing: bool = False,
|
24
|
-
**kwargs: Any, # noqa: ARG002
|
25
|
-
) -> None:
|
26
|
-
super().__init__(
|
27
|
-
subagents=subagents,
|
28
|
-
start_agent=subagents[0],
|
29
|
-
end_agent=subagents[-1],
|
30
|
-
agent_id=agent_id,
|
31
|
-
message_pool=message_pool,
|
32
|
-
recipient_ids=recipient_ids,
|
33
|
-
dynamic_routing=dynamic_routing,
|
34
|
-
)
|
35
|
-
|
36
|
-
@final
|
37
|
-
async def run(
|
38
|
-
self,
|
39
|
-
chat_inputs: Any | None = None,
|
40
|
-
*,
|
41
|
-
in_args: InT | Sequence[InT] | None = None,
|
42
|
-
in_message: AgentMessage[InT, Any] | None = None,
|
43
|
-
ctx: RunContextWrapper[CtxT] | None = None,
|
44
|
-
entry_point: bool = False,
|
45
|
-
forbid_state_change: bool = False,
|
46
|
-
**kwargs: Any,
|
47
|
-
) -> AgentMessage[OutT, Any]:
|
48
|
-
agent_message = in_message
|
49
|
-
for subagent in self.subagents:
|
50
|
-
agent_message = await subagent.run(
|
51
|
-
chat_inputs=chat_inputs,
|
52
|
-
in_args=in_args,
|
53
|
-
in_message=agent_message,
|
54
|
-
entry_point=entry_point,
|
55
|
-
forbid_state_change=forbid_state_change,
|
56
|
-
ctx=ctx,
|
57
|
-
**kwargs,
|
58
|
-
)
|
59
|
-
chat_inputs = None
|
60
|
-
in_args = None
|
61
|
-
entry_point = False
|
62
|
-
|
63
|
-
return cast("AgentMessage[OutT, Any]", agent_message)
|
@@ -1,73 +0,0 @@
|
|
1
|
-
from abc import ABC, abstractmethod
|
2
|
-
from collections.abc import Sequence
|
3
|
-
from typing import Any, ClassVar, Generic
|
4
|
-
|
5
|
-
from ..agent_message_pool import AgentMessage, AgentMessagePool
|
6
|
-
from ..comm_agent import CommunicatingAgent
|
7
|
-
from ..run_context import CtxT, RunContextWrapper
|
8
|
-
from ..typing.io import AgentID, InT, OutT
|
9
|
-
|
10
|
-
|
11
|
-
class WorkflowAgent(
|
12
|
-
CommunicatingAgent[InT, OutT, Any, CtxT], ABC, Generic[InT, OutT, CtxT]
|
13
|
-
):
|
14
|
-
_generic_arg_to_instance_attr_map: ClassVar[dict[int, str]] = {
|
15
|
-
0: "_in_type",
|
16
|
-
1: "_out_type",
|
17
|
-
}
|
18
|
-
|
19
|
-
def __init__(
|
20
|
-
self,
|
21
|
-
agent_id: AgentID,
|
22
|
-
subagents: Sequence[CommunicatingAgent[Any, Any, Any, CtxT]],
|
23
|
-
start_agent: CommunicatingAgent[InT, Any, Any, CtxT],
|
24
|
-
end_agent: CommunicatingAgent[Any, OutT, Any, CtxT],
|
25
|
-
message_pool: AgentMessagePool[CtxT] | None = None,
|
26
|
-
recipient_ids: list[AgentID] | None = None,
|
27
|
-
dynamic_routing: bool = False,
|
28
|
-
**kwargs: Any, # noqa: ARG002
|
29
|
-
) -> None:
|
30
|
-
if not subagents:
|
31
|
-
raise ValueError("At least one step is required")
|
32
|
-
if start_agent not in subagents:
|
33
|
-
raise ValueError("Start agent must be in the subagents list")
|
34
|
-
if end_agent not in subagents:
|
35
|
-
raise ValueError("End agent must be in the subagents list")
|
36
|
-
|
37
|
-
self.subagents = subagents
|
38
|
-
|
39
|
-
self._start_agent = start_agent
|
40
|
-
self._end_agent = end_agent
|
41
|
-
|
42
|
-
super().__init__(
|
43
|
-
agent_id=agent_id,
|
44
|
-
message_pool=message_pool,
|
45
|
-
recipient_ids=recipient_ids,
|
46
|
-
dynamic_routing=dynamic_routing,
|
47
|
-
)
|
48
|
-
for subagent in subagents:
|
49
|
-
assert not subagent.recipient_ids, (
|
50
|
-
"Subagents must not have recipient_ids set."
|
51
|
-
)
|
52
|
-
|
53
|
-
@property
|
54
|
-
def start_agent(self) -> CommunicatingAgent[InT, Any, Any, CtxT]:
|
55
|
-
return self._start_agent
|
56
|
-
|
57
|
-
@property
|
58
|
-
def end_agent(self) -> CommunicatingAgent[Any, OutT, Any, CtxT]:
|
59
|
-
return self._end_agent
|
60
|
-
|
61
|
-
@abstractmethod
|
62
|
-
async def run(
|
63
|
-
self,
|
64
|
-
chat_inputs: Any | None = None,
|
65
|
-
*,
|
66
|
-
in_args: InT | Sequence[InT] | None = None,
|
67
|
-
in_message: AgentMessage[InT, Any] | None = None,
|
68
|
-
ctx: RunContextWrapper[CtxT] | None = None,
|
69
|
-
entry_point: bool = False,
|
70
|
-
forbid_state_change: bool = False,
|
71
|
-
**generation_kwargs: Any,
|
72
|
-
) -> AgentMessage[OutT, Any]:
|
73
|
-
pass
|
@@ -1,46 +0,0 @@
|
|
1
|
-
grasp_agents/__init__.py,sha256=WPNUUFbucwli6oWIwxbckz0zpY4W2LnND0o7melYZOw,979
|
2
|
-
grasp_agents/agent_message.py,sha256=eJV5n44t8EIE6M3jl48Ld7pmaW9dDhBX_FWm_u9yGWE,877
|
3
|
-
grasp_agents/agent_message_pool.py,sha256=OKTXNEo9LAJTQJkzxmJ3TQgWw7WJKOzrKCJjeHpln6o,3158
|
4
|
-
grasp_agents/base_agent.py,sha256=6WHBS17KqbiCVSREOiIJXlHfNrYb0AKvs0dEShogQGE,1363
|
5
|
-
grasp_agents/cloud_llm.py,sha256=QqfnqLtInbekeT8R-sWMTrPiMwazyPaGoQ9K2wuh6gE,13336
|
6
|
-
grasp_agents/comm_agent.py,sha256=U2R942X5yjPr27j9soUdueXtAzvduI7iON9QgoSDBAo,7271
|
7
|
-
grasp_agents/costs_dict.yaml,sha256=2MFNWtkv5W5WSCcv1Cj13B1iQLVv5Ot9pS_KW2Gu2DA,2510
|
8
|
-
grasp_agents/generics_utils.py,sha256=kw4Odte6Nvl4c9U7-mKPgXCavWZXo009zYDHAA0BR3g,6234
|
9
|
-
grasp_agents/grasp_logging.py,sha256=H1GYhXdQvVkmauFDZ-KDwvVmPQHZUUm9sRqX_ObK2xI,1111
|
10
|
-
grasp_agents/http_client.py,sha256=KZva2MjJjuI5ohUeU8RdTAImUnQYaqBrV2jDH8smbJw,738
|
11
|
-
grasp_agents/llm.py,sha256=YClNxN9GUGaFHXhTU72z1AqW_Y726OC7kyVRYCnfhZ8,3682
|
12
|
-
grasp_agents/llm_agent.py,sha256=trKvxIS5z9GYusB9zNRv_75trGP1NwzdvK2_-rElYnE,16102
|
13
|
-
grasp_agents/llm_agent_state.py,sha256=L54zUW5nAT-ubvEB7XNAQ84ExOgRlUFzc-Q49mUXUT0,2390
|
14
|
-
grasp_agents/memory.py,sha256=X1YtVX8XxP5KnGPMW8BqjID8QK4hTG2obxoyhnnZ4pU,5575
|
15
|
-
grasp_agents/printer.py,sha256=ZENcTITCcgSizvcUXnIQiFl_NcVHg-801Z-sbT0D8rg,5030
|
16
|
-
grasp_agents/prompt_builder.py,sha256=uN21GAYdmbNiIkv60Rs_ixJyybR1JWR0lsOM9HVkiLE,8411
|
17
|
-
grasp_agents/run_context.py,sha256=4v6IcddHSWUAMYX8M9hQRXNMfPf7gUv45nn_Fb5lLaI,2233
|
18
|
-
grasp_agents/tool_orchestrator.py,sha256=XgKCOytPs4y4SBpS5i4eogCB428XaDnNIB3VxzJC_k0,6095
|
19
|
-
grasp_agents/usage_tracker.py,sha256=4gy0XtfIBAjQHblEFpQuPelmxMGDvE7vw4c8Ccr1msk,3471
|
20
|
-
grasp_agents/utils.py,sha256=KzoInW0sq-pwwUtgjtYMW8b0ivBH6MR0Zxv6Kqq3k3M,4510
|
21
|
-
grasp_agents/openai/__init__.py,sha256=P7oa4tdJ2JKJv16frRi1C09FnrMayuOYomu5l95uayE,3196
|
22
|
-
grasp_agents/openai/completion_converters.py,sha256=gt06DO2jrMsgJGHPIhoTHeM3R0yHqUjS0_VfaC6Xu4I,2146
|
23
|
-
grasp_agents/openai/content_converters.py,sha256=6GI0D7xJalzsiawAJOyCUzTJTo0NQdpv87YKmfN0LYQ,2631
|
24
|
-
grasp_agents/openai/converters.py,sha256=DBXBxow9oRG6pc8inpZBLiuUqHzVfpscmHFpN9bAdvc,5276
|
25
|
-
grasp_agents/openai/message_converters.py,sha256=Gol5lFDu3eSagDsvWi_ql0QYcAT3-_5YCbU75xwuBK0,4823
|
26
|
-
grasp_agents/openai/openai_llm.py,sha256=JZdM0YerpDJW1IX7BW8lawgGdUHUW1ka4JSEqKxXuUQ,6075
|
27
|
-
grasp_agents/openai/tool_converters.py,sha256=72DmyNW9WylesRH-m5fi7H2Wu1U9gUXqMQ-UdX_M7mU,1068
|
28
|
-
grasp_agents/rate_limiting/__init__.py,sha256=KRgtF_E7R3YfA2cpYcFcZ7wycV0pWVJ0xRQC7YhiIEQ,158
|
29
|
-
grasp_agents/rate_limiting/rate_limiter_chunked.py,sha256=BPgkUXvhmZhTpZs2T6uujNFuxH_kYHiISuf6_-eNhUc,5544
|
30
|
-
grasp_agents/rate_limiting/types.py,sha256=PbnNhEAcYedQdIpPJWud8HUVcxa_xZS2RDZu4c5jr40,1003
|
31
|
-
grasp_agents/rate_limiting/utils.py,sha256=oEDWDNHYMUdxOOG49PlAJochkZq8nnVBCo6JxPc1iSo,2007
|
32
|
-
grasp_agents/typing/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
33
|
-
grasp_agents/typing/completion.py,sha256=_KDLx3Gtz7o-pEZrvAFgCZwDmkr2oQkxrL-2LSXHHsw,657
|
34
|
-
grasp_agents/typing/content.py,sha256=VdnHdW8PHDCtX_ffvcwQz-7ypPUQNSGqHa3txFE_72Y,3676
|
35
|
-
grasp_agents/typing/converters.py,sha256=yORIljRsVoKz7oj38pHLD6luIelM1RcYL_PqG_D4nWM,3086
|
36
|
-
grasp_agents/typing/io.py,sha256=uxSvbD05UK5nIhPfDvXIoGuU6xRMW4USZq_4IgBeGCY,609
|
37
|
-
grasp_agents/typing/message.py,sha256=DC24XMcUPG1MHDNZKT67yKWyaMTQNF5B0yDiUg8b54Q,3833
|
38
|
-
grasp_agents/typing/tool.py,sha256=e0pTMnRcpMpGNVQ8muE9wnh7LdIgh92AqXDo9hMDxf0,1960
|
39
|
-
grasp_agents/workflow/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
40
|
-
grasp_agents/workflow/looped_agent.py,sha256=5tvlkPyhPdNGVSEaxTNPX0QQfPwP01OpZrvmv4bWXsA,4046
|
41
|
-
grasp_agents/workflow/sequential_agent.py,sha256=SbeAKHCbhMy-2CmQWs1f5VMSRj88MLiAQc76g_ivGvA,2131
|
42
|
-
grasp_agents/workflow/workflow_agent.py,sha256=E6jzfFmdUfCoYehH9ZsAa_MTICjEaP4NGwNxhc3NR_E,2436
|
43
|
-
grasp_agents-0.2.10.dist-info/METADATA,sha256=lBHs7V6zm6E63yspRA9OOHS80M7hCtyVxuCNkaNce5Y,7188
|
44
|
-
grasp_agents-0.2.10.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
45
|
-
grasp_agents-0.2.10.dist-info/licenses/LICENSE.md,sha256=-nNNdWqGB8gJ2O-peFQ2Irshv5tW5pHKyTcYkwvH7CE,1201
|
46
|
-
grasp_agents-0.2.10.dist-info/RECORD,,
|
File without changes
|
File without changes
|