grasp_agents 0.1.5__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/agent_message.py +28 -0
- grasp_agents/agent_message_pool.py +94 -0
- grasp_agents/base_agent.py +72 -0
- grasp_agents/cloud_llm.py +353 -0
- grasp_agents/comm_agent.py +230 -0
- grasp_agents/costs_dict.yaml +122 -0
- grasp_agents/data_retrieval/__init__.py +7 -0
- grasp_agents/data_retrieval/rate_limiter_chunked.py +195 -0
- grasp_agents/data_retrieval/types.py +57 -0
- grasp_agents/data_retrieval/utils.py +57 -0
- grasp_agents/grasp_logging.py +36 -0
- grasp_agents/http_client.py +24 -0
- grasp_agents/llm.py +106 -0
- grasp_agents/llm_agent.py +361 -0
- grasp_agents/llm_agent_state.py +73 -0
- grasp_agents/memory.py +150 -0
- grasp_agents/openai/__init__.py +83 -0
- grasp_agents/openai/completion_converters.py +49 -0
- grasp_agents/openai/content_converters.py +80 -0
- grasp_agents/openai/converters.py +170 -0
- grasp_agents/openai/message_converters.py +155 -0
- grasp_agents/openai/openai_llm.py +179 -0
- grasp_agents/openai/tool_converters.py +37 -0
- grasp_agents/printer.py +156 -0
- grasp_agents/prompt_builder.py +204 -0
- grasp_agents/run_context.py +90 -0
- grasp_agents/tool_orchestrator.py +181 -0
- grasp_agents/typing/__init__.py +0 -0
- grasp_agents/typing/completion.py +30 -0
- grasp_agents/typing/content.py +116 -0
- grasp_agents/typing/converters.py +118 -0
- grasp_agents/typing/io.py +32 -0
- grasp_agents/typing/message.py +130 -0
- grasp_agents/typing/tool.py +52 -0
- grasp_agents/usage_tracker.py +99 -0
- grasp_agents/utils.py +151 -0
- grasp_agents/workflow/__init__.py +0 -0
- grasp_agents/workflow/looped_agent.py +113 -0
- grasp_agents/workflow/sequential_agent.py +57 -0
- grasp_agents/workflow/workflow_agent.py +69 -0
- grasp_agents-0.1.5.dist-info/METADATA +14 -0
- grasp_agents-0.1.5.dist-info/RECORD +44 -0
- grasp_agents-0.1.5.dist-info/WHEEL +4 -0
- grasp_agents-0.1.5.dist-info/licenses/LICENSE +21 -0
@@ -0,0 +1,99 @@
|
|
1
|
+
import logging
|
2
|
+
from collections.abc import Sequence
|
3
|
+
from pathlib import Path
|
4
|
+
from typing import Any, TypeAlias
|
5
|
+
|
6
|
+
import yaml
|
7
|
+
from pydantic import BaseModel, Field
|
8
|
+
from termcolor import colored
|
9
|
+
|
10
|
+
from .typing.message import AssistantMessage, Message, Usage
|
11
|
+
|
12
|
+
logger = logging.getLogger(__name__)
|
13
|
+
|
14
|
+
|
15
|
+
COSTS_DICT_PATH: Path = Path(__file__).parent / "costs_dict.yaml"
|
16
|
+
|
17
|
+
ModelCostsDict: TypeAlias = dict[str, float]
|
18
|
+
CostsDict: TypeAlias = dict[str, ModelCostsDict]
|
19
|
+
|
20
|
+
|
21
|
+
class UsageTracker(BaseModel):
|
22
|
+
source_id: str
|
23
|
+
costs_dict_path: str | Path = COSTS_DICT_PATH
|
24
|
+
costs_dict: CostsDict | None = None
|
25
|
+
total_usage: Usage = Field(default_factory=Usage)
|
26
|
+
|
27
|
+
def __init__(self, **kwargs: Any) -> None:
|
28
|
+
super().__init__(**kwargs)
|
29
|
+
self.costs_dict = self.load_costs_dict()
|
30
|
+
|
31
|
+
def load_costs_dict(self) -> CostsDict | None:
|
32
|
+
try:
|
33
|
+
with Path(self.costs_dict_path).open() as f:
|
34
|
+
return yaml.safe_load(f)["costs"]
|
35
|
+
except Exception:
|
36
|
+
logger.info(f"Failed to load cost dictionary from {self.costs_dict_path}")
|
37
|
+
return None
|
38
|
+
|
39
|
+
def _add_cost_to_usage(
|
40
|
+
self, usage: Usage, model_costs_dict: ModelCostsDict
|
41
|
+
) -> None:
|
42
|
+
in_rate = model_costs_dict["input"]
|
43
|
+
out_rate = model_costs_dict["output"]
|
44
|
+
cached_discount = model_costs_dict.get("cached_discount")
|
45
|
+
input_cost = in_rate * usage.input_tokens
|
46
|
+
output_cost = out_rate * usage.output_tokens
|
47
|
+
reasoning_cost = (
|
48
|
+
out_rate * usage.reasoning_tokens
|
49
|
+
if usage.reasoning_tokens is not None
|
50
|
+
else 0.0
|
51
|
+
)
|
52
|
+
cached_cost: float = (
|
53
|
+
cached_discount * in_rate * usage.cached_tokens
|
54
|
+
if (usage.cached_tokens is not None) and (cached_discount is not None)
|
55
|
+
else 0.0
|
56
|
+
)
|
57
|
+
usage.cost = (input_cost + output_cost + reasoning_cost + cached_cost) / 1e6
|
58
|
+
|
59
|
+
def update(
|
60
|
+
self, messages: Sequence[Message], model_name: str | None = None
|
61
|
+
) -> None:
|
62
|
+
if model_name is not None and self.costs_dict is not None:
|
63
|
+
model_costs_dict = self.costs_dict.get(model_name)
|
64
|
+
else:
|
65
|
+
model_costs_dict = None
|
66
|
+
|
67
|
+
for message in messages:
|
68
|
+
if isinstance(message, AssistantMessage) and message.usage is not None:
|
69
|
+
if model_costs_dict is not None:
|
70
|
+
self._add_cost_to_usage(
|
71
|
+
usage=message.usage, model_costs_dict=model_costs_dict
|
72
|
+
)
|
73
|
+
self.total_usage += message.usage
|
74
|
+
|
75
|
+
def reset(self) -> None:
|
76
|
+
self.total_usage = Usage()
|
77
|
+
|
78
|
+
def print_usage(self) -> None:
|
79
|
+
usage = self.total_usage
|
80
|
+
|
81
|
+
logger.debug("\n-------------------")
|
82
|
+
|
83
|
+
token_usage_str = (
|
84
|
+
f"Total {self.source_id} I/O/(R)/(C) tokens: "
|
85
|
+
f"{usage.input_tokens}/{usage.output_tokens}"
|
86
|
+
)
|
87
|
+
if usage.reasoning_tokens is not None:
|
88
|
+
token_usage_str += f"/{usage.reasoning_tokens}"
|
89
|
+
if usage.cached_tokens is not None:
|
90
|
+
token_usage_str += f"/{usage.cached_tokens}"
|
91
|
+
logger.debug(colored(token_usage_str, "light_grey"))
|
92
|
+
|
93
|
+
if usage.cost is not None:
|
94
|
+
logger.debug(
|
95
|
+
colored(
|
96
|
+
f"Total {self.source_id} cost: ${usage.cost:.4f}",
|
97
|
+
"light_grey",
|
98
|
+
)
|
99
|
+
)
|
grasp_agents/utils.py
ADDED
@@ -0,0 +1,151 @@
|
|
1
|
+
import ast
|
2
|
+
import asyncio
|
3
|
+
from datetime import datetime
|
4
|
+
import functools
|
5
|
+
import json
|
6
|
+
import re
|
7
|
+
from collections.abc import Callable, Coroutine
|
8
|
+
from copy import deepcopy
|
9
|
+
from pathlib import Path
|
10
|
+
from typing import Any, TypeVar, cast
|
11
|
+
|
12
|
+
from pydantic import BaseModel, create_model
|
13
|
+
from pydantic.fields import FieldInfo
|
14
|
+
from tqdm.autonotebook import tqdm
|
15
|
+
|
16
|
+
|
17
|
+
def read_contents_from_file(
|
18
|
+
file_path: str | Path,
|
19
|
+
binary_mode: bool = False,
|
20
|
+
) -> str:
|
21
|
+
"""Reads and returns contents of file"""
|
22
|
+
try:
|
23
|
+
if binary_mode:
|
24
|
+
with open(file_path, "rb") as file:
|
25
|
+
return file.read()
|
26
|
+
else:
|
27
|
+
with open(file_path) as file:
|
28
|
+
return file.read()
|
29
|
+
except FileNotFoundError:
|
30
|
+
print(f"File {file_path} not found.")
|
31
|
+
return ""
|
32
|
+
|
33
|
+
|
34
|
+
async def asyncio_gather_with_pbar(
|
35
|
+
*corouts: Coroutine[Any, Any, Any],
|
36
|
+
no_tqdm: bool = False,
|
37
|
+
desc: str | None = None,
|
38
|
+
) -> list[Any]:
|
39
|
+
pbar = tqdm(total=len(corouts), desc=desc, disable=no_tqdm)
|
40
|
+
|
41
|
+
async def run_and_update(coro: Coroutine[Any, Any, Any]) -> Any:
|
42
|
+
result = await coro
|
43
|
+
pbar.update(1)
|
44
|
+
return result
|
45
|
+
|
46
|
+
wrapped_tasks = [run_and_update(c) for c in corouts]
|
47
|
+
results = await asyncio.gather(*wrapped_tasks)
|
48
|
+
pbar.close()
|
49
|
+
|
50
|
+
return results
|
51
|
+
|
52
|
+
|
53
|
+
def get_timestamp() -> str:
|
54
|
+
return datetime.now().strftime("%Y%m%d_%H%M%S")
|
55
|
+
|
56
|
+
|
57
|
+
def read_txt(file_path: str) -> str:
|
58
|
+
return Path(file_path).read_text()
|
59
|
+
|
60
|
+
|
61
|
+
def format_json_string(text: str) -> str:
|
62
|
+
decoder = json.JSONDecoder()
|
63
|
+
text = text.replace("\n", "")
|
64
|
+
length = len(text)
|
65
|
+
i = 0
|
66
|
+
while i < length:
|
67
|
+
ch = text[i]
|
68
|
+
if ch in "{[":
|
69
|
+
try:
|
70
|
+
_, end = decoder.raw_decode(text[i:])
|
71
|
+
return text[i : i + end]
|
72
|
+
except ValueError:
|
73
|
+
pass
|
74
|
+
i += 1
|
75
|
+
|
76
|
+
return ""
|
77
|
+
|
78
|
+
|
79
|
+
def read_json_string(json_str: str) -> dict[str, Any] | list[Any]:
|
80
|
+
try:
|
81
|
+
json_response = ast.literal_eval(json_str)
|
82
|
+
except (ValueError, SyntaxError):
|
83
|
+
try:
|
84
|
+
json_response = json.loads(json_str)
|
85
|
+
except json.JSONDecodeError as exc:
|
86
|
+
raise ValueError(
|
87
|
+
"Invalid JSON - Both ast.literal_eval and json.loads "
|
88
|
+
f"failed to parse the following response:\n{json_str}"
|
89
|
+
) from exc
|
90
|
+
|
91
|
+
return json_response # type: ignore
|
92
|
+
|
93
|
+
|
94
|
+
def extract_json(json_str: str) -> dict[str, Any] | list[Any]:
|
95
|
+
return read_json_string(format_json_string(json_str))
|
96
|
+
|
97
|
+
|
98
|
+
def extract_xml_list(text: str) -> list[str]:
|
99
|
+
pattern = re.compile(r"<(chunk_\d+)>(.*?)</\1>", re.DOTALL)
|
100
|
+
|
101
|
+
chunks: list[str] = []
|
102
|
+
for match in pattern.finditer(text):
|
103
|
+
content = match.group(2).strip()
|
104
|
+
chunks.append(content)
|
105
|
+
return chunks
|
106
|
+
|
107
|
+
|
108
|
+
def get_prompt(prompt_text: str | None, prompt_path: str | Path | None) -> str | None:
|
109
|
+
if prompt_text is None:
|
110
|
+
prompt = (
|
111
|
+
read_contents_from_file(prompt_path) if prompt_path is not None else None
|
112
|
+
)
|
113
|
+
else:
|
114
|
+
prompt = prompt_text
|
115
|
+
|
116
|
+
return prompt
|
117
|
+
|
118
|
+
|
119
|
+
def merge_pydantic_models(*models: type[BaseModel]) -> type[BaseModel]:
|
120
|
+
fields_dict: dict[str, FieldInfo] = {}
|
121
|
+
for model in models:
|
122
|
+
for field_name, field_info in model.model_fields.items():
|
123
|
+
if field_name in fields_dict:
|
124
|
+
raise ValueError(
|
125
|
+
f"Field conflict detected: '{field_name}' exists in multiple models"
|
126
|
+
)
|
127
|
+
fields_dict[field_name] = field_info
|
128
|
+
|
129
|
+
return create_model("MergedModel", __module__=__name__, **fields_dict) # type: ignore
|
130
|
+
|
131
|
+
|
132
|
+
def filter_fields(data: dict[str, Any], model: type[BaseModel]) -> dict[str, Any]:
|
133
|
+
return {key: data[key] for key in model.model_fields if key in data}
|
134
|
+
|
135
|
+
|
136
|
+
T = TypeVar("T", bound=Callable[..., Any])
|
137
|
+
|
138
|
+
|
139
|
+
def forbid_state_change(method: T) -> T:
|
140
|
+
@functools.wraps(method)
|
141
|
+
def wrapper(self: Any, *args: Any, **kwargs: Any) -> Any:
|
142
|
+
before = deepcopy(self.__dict__)
|
143
|
+
result = method(self, *args, **kwargs)
|
144
|
+
after = self.__dict__
|
145
|
+
if before != after:
|
146
|
+
raise RuntimeError(
|
147
|
+
f"Method '{method.__name__}' modified the instance state."
|
148
|
+
)
|
149
|
+
return result
|
150
|
+
|
151
|
+
return cast("T", wrapper)
|
File without changes
|
@@ -0,0 +1,113 @@
|
|
1
|
+
from collections.abc import Sequence
|
2
|
+
from logging import getLogger
|
3
|
+
from typing import Any, 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, AgentPayload, AgentState, InT, OutT
|
9
|
+
from .workflow_agent import WorkflowAgent
|
10
|
+
|
11
|
+
logger = getLogger(__name__)
|
12
|
+
|
13
|
+
_EH_OutT = TypeVar("_EH_OutT", bound=AgentPayload, contravariant=True) # noqa: PLC0105
|
14
|
+
|
15
|
+
|
16
|
+
class WorkflowLoopExitHandler(Protocol[_EH_OutT, CtxT]):
|
17
|
+
def __call__(
|
18
|
+
self,
|
19
|
+
output_message: AgentMessage[_EH_OutT, AgentState],
|
20
|
+
ctx: RunContextWrapper[CtxT] | None,
|
21
|
+
**kwargs: Any,
|
22
|
+
) -> bool: ...
|
23
|
+
|
24
|
+
|
25
|
+
class LoopedWorkflowAgent(WorkflowAgent[InT, OutT, CtxT], Generic[InT, OutT, CtxT]):
|
26
|
+
def __init__(
|
27
|
+
self,
|
28
|
+
agent_id: AgentID,
|
29
|
+
subagents: Sequence[
|
30
|
+
CommunicatingAgent[AgentPayload, AgentPayload, AgentState, CtxT]
|
31
|
+
],
|
32
|
+
exit_agent: CommunicatingAgent[AgentPayload, OutT, AgentState, CtxT],
|
33
|
+
message_pool: AgentMessagePool[CtxT] | None = None,
|
34
|
+
recipient_ids: list[AgentID] | None = None,
|
35
|
+
dynamic_routing: bool = False,
|
36
|
+
max_iterations: int = 10,
|
37
|
+
**kwargs: Any, # noqa: ARG002
|
38
|
+
) -> None:
|
39
|
+
super().__init__(
|
40
|
+
subagents=subagents,
|
41
|
+
agent_id=agent_id,
|
42
|
+
start_agent=subagents[0],
|
43
|
+
end_agent=exit_agent,
|
44
|
+
message_pool=message_pool,
|
45
|
+
recipient_ids=recipient_ids,
|
46
|
+
dynamic_routing=dynamic_routing,
|
47
|
+
)
|
48
|
+
|
49
|
+
self._max_iterations = max_iterations
|
50
|
+
|
51
|
+
self._workflow_loop_exit_impl: WorkflowLoopExitHandler[OutT, CtxT] | None = None
|
52
|
+
|
53
|
+
@property
|
54
|
+
def max_iterations(self) -> int:
|
55
|
+
return self._max_iterations
|
56
|
+
|
57
|
+
def workflow_loop_exit_handler(
|
58
|
+
self, func: WorkflowLoopExitHandler[OutT, CtxT]
|
59
|
+
) -> WorkflowLoopExitHandler[OutT, CtxT]:
|
60
|
+
self._workflow_loop_exit_impl = func
|
61
|
+
|
62
|
+
return func
|
63
|
+
|
64
|
+
def _workflow_loop_exit(
|
65
|
+
self,
|
66
|
+
output_message: AgentMessage[OutT, AgentState],
|
67
|
+
ctx: RunContextWrapper[CtxT] | None,
|
68
|
+
**kwargs: Any,
|
69
|
+
) -> bool:
|
70
|
+
if self._workflow_loop_exit_impl:
|
71
|
+
return self._workflow_loop_exit_impl(output_message, ctx=ctx, **kwargs)
|
72
|
+
|
73
|
+
return False
|
74
|
+
|
75
|
+
@final
|
76
|
+
async def run(
|
77
|
+
self,
|
78
|
+
inp_items: Any | None = None,
|
79
|
+
*,
|
80
|
+
ctx: RunContextWrapper[CtxT] | None = None,
|
81
|
+
rcv_message: AgentMessage[InT, AgentState] | None = None,
|
82
|
+
entry_point: bool = False,
|
83
|
+
forbid_state_change: bool = False,
|
84
|
+
**kwargs: Any,
|
85
|
+
) -> AgentMessage[OutT, AgentState]:
|
86
|
+
agent_message = rcv_message
|
87
|
+
num_iterations = 0
|
88
|
+
exit_message: AgentMessage[OutT, AgentState] | None = None
|
89
|
+
|
90
|
+
while True:
|
91
|
+
for subagent in self.subagents:
|
92
|
+
agent_message = await subagent.run(
|
93
|
+
inp_items=inp_items,
|
94
|
+
rcv_message=agent_message,
|
95
|
+
entry_point=entry_point,
|
96
|
+
forbid_state_change=forbid_state_change,
|
97
|
+
ctx=ctx,
|
98
|
+
**kwargs,
|
99
|
+
)
|
100
|
+
|
101
|
+
if subagent is self._end_agent:
|
102
|
+
num_iterations += 1
|
103
|
+
exit_message = cast("AgentMessage[OutT, AgentState]", agent_message)
|
104
|
+
if self._workflow_loop_exit(exit_message, ctx=ctx):
|
105
|
+
return exit_message
|
106
|
+
if num_iterations >= self._max_iterations:
|
107
|
+
logger.info(
|
108
|
+
f"Max iterations reached ({self._max_iterations}). Exiting loop."
|
109
|
+
)
|
110
|
+
return exit_message
|
111
|
+
|
112
|
+
inp_items = None
|
113
|
+
entry_point = False
|
@@ -0,0 +1,57 @@
|
|
1
|
+
from collections.abc import Sequence
|
2
|
+
from typing import Any, 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, AgentPayload, AgentState, InT, OutT
|
8
|
+
from .workflow_agent import WorkflowAgent
|
9
|
+
|
10
|
+
|
11
|
+
class SequentialWorkflowAgent(WorkflowAgent[InT, OutT, CtxT], Generic[InT, OutT, CtxT]):
|
12
|
+
def __init__(
|
13
|
+
self,
|
14
|
+
agent_id: AgentID,
|
15
|
+
subagents: Sequence[
|
16
|
+
CommunicatingAgent[AgentPayload, AgentPayload, AgentState, CtxT]
|
17
|
+
],
|
18
|
+
message_pool: AgentMessagePool[CtxT] | None = None,
|
19
|
+
recipient_ids: list[AgentID] | None = None,
|
20
|
+
dynamic_routing: bool = False,
|
21
|
+
**kwargs: Any, # noqa: ARG002
|
22
|
+
) -> None:
|
23
|
+
super().__init__(
|
24
|
+
subagents=subagents,
|
25
|
+
start_agent=subagents[0],
|
26
|
+
end_agent=subagents[-1], # type: ignore[assignment]
|
27
|
+
agent_id=agent_id,
|
28
|
+
message_pool=message_pool,
|
29
|
+
recipient_ids=recipient_ids,
|
30
|
+
dynamic_routing=dynamic_routing,
|
31
|
+
)
|
32
|
+
|
33
|
+
@final
|
34
|
+
async def run(
|
35
|
+
self,
|
36
|
+
inp_items: Any | None = None,
|
37
|
+
*,
|
38
|
+
ctx: RunContextWrapper[CtxT] | None = None,
|
39
|
+
rcv_message: AgentMessage[InT, AgentState] | None = None,
|
40
|
+
entry_point: bool = False,
|
41
|
+
forbid_state_change: bool = False,
|
42
|
+
**kwargs: Any,
|
43
|
+
) -> AgentMessage[OutT, AgentState]:
|
44
|
+
agent_message = rcv_message
|
45
|
+
for subagent in self.subagents:
|
46
|
+
agent_message = await subagent.run(
|
47
|
+
inp_items=inp_items,
|
48
|
+
rcv_message=agent_message,
|
49
|
+
entry_point=entry_point,
|
50
|
+
forbid_state_change=forbid_state_change,
|
51
|
+
ctx=ctx,
|
52
|
+
**kwargs,
|
53
|
+
)
|
54
|
+
inp_items = None
|
55
|
+
entry_point = False
|
56
|
+
|
57
|
+
return cast("AgentMessage[OutT, AgentState]", agent_message)
|
@@ -0,0 +1,69 @@
|
|
1
|
+
from abc import ABC, abstractmethod
|
2
|
+
from collections.abc import Sequence
|
3
|
+
from typing import Any, 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, AgentPayload, AgentState, InT, OutT
|
9
|
+
|
10
|
+
|
11
|
+
class WorkflowAgent(
|
12
|
+
CommunicatingAgent[InT, OutT, AgentState, CtxT],
|
13
|
+
ABC,
|
14
|
+
Generic[InT, OutT, CtxT],
|
15
|
+
):
|
16
|
+
def __init__(
|
17
|
+
self,
|
18
|
+
agent_id: AgentID,
|
19
|
+
subagents: Sequence[
|
20
|
+
CommunicatingAgent[AgentPayload, AgentPayload, AgentState, CtxT]
|
21
|
+
],
|
22
|
+
start_agent: CommunicatingAgent[InT, AgentPayload, AgentState, CtxT],
|
23
|
+
end_agent: CommunicatingAgent[AgentPayload, OutT, AgentState, CtxT],
|
24
|
+
message_pool: AgentMessagePool[CtxT] | None = None,
|
25
|
+
recipient_ids: list[AgentID] | None = None,
|
26
|
+
dynamic_routing: bool = False,
|
27
|
+
**kwargs: Any, # noqa: ARG002
|
28
|
+
) -> None:
|
29
|
+
if not subagents:
|
30
|
+
raise ValueError("At least one step is required")
|
31
|
+
|
32
|
+
self.subagents = subagents
|
33
|
+
|
34
|
+
self._start_agent = start_agent
|
35
|
+
self._end_agent = end_agent
|
36
|
+
|
37
|
+
super().__init__(
|
38
|
+
agent_id=agent_id,
|
39
|
+
out_schema=end_agent.out_schema,
|
40
|
+
rcv_args_schema=start_agent.rcv_args_schema,
|
41
|
+
message_pool=message_pool,
|
42
|
+
recipient_ids=recipient_ids,
|
43
|
+
dynamic_routing=dynamic_routing,
|
44
|
+
)
|
45
|
+
for subagent in subagents:
|
46
|
+
assert not subagent.recipient_ids, (
|
47
|
+
"Subagents must not have recipient_ids set."
|
48
|
+
)
|
49
|
+
|
50
|
+
@property
|
51
|
+
def start_agent(self) -> CommunicatingAgent[InT, AgentPayload, AgentState, CtxT]:
|
52
|
+
return self._start_agent
|
53
|
+
|
54
|
+
@property
|
55
|
+
def end_agent(self) -> CommunicatingAgent[AgentPayload, OutT, AgentState, CtxT]:
|
56
|
+
return self._end_agent
|
57
|
+
|
58
|
+
@abstractmethod
|
59
|
+
async def run(
|
60
|
+
self,
|
61
|
+
inp_items: Any | None = None,
|
62
|
+
*,
|
63
|
+
ctx: RunContextWrapper[CtxT] | None = None,
|
64
|
+
rcv_message: AgentMessage[InT, AgentState] | None = None,
|
65
|
+
entry_point: bool = False,
|
66
|
+
forbid_state_change: bool = False,
|
67
|
+
**generation_kwargs: Any,
|
68
|
+
) -> AgentMessage[OutT, AgentState]:
|
69
|
+
pass
|
@@ -0,0 +1,14 @@
|
|
1
|
+
Metadata-Version: 2.4
|
2
|
+
Name: grasp_agents
|
3
|
+
Version: 0.1.5
|
4
|
+
Summary: Add your description here
|
5
|
+
License-File: LICENSE
|
6
|
+
Requires-Python: <3.12,>=3.11.4
|
7
|
+
Requires-Dist: httpx<1,>=0.27.0
|
8
|
+
Requires-Dist: openai<2,>=1.68.2
|
9
|
+
Requires-Dist: tenacity>=9.1.2
|
10
|
+
Requires-Dist: termcolor<3,>=2.4.0
|
11
|
+
Requires-Dist: tqdm<5,>=4.66.2
|
12
|
+
Description-Content-Type: text/markdown
|
13
|
+
|
14
|
+
# grasp-agents
|
@@ -0,0 +1,44 @@
|
|
1
|
+
grasp_agents/agent_message.py,sha256=atYrmIVT-1wkLUM79YnqcRVy_J7Vwsj-9KCXFEoI0tc,944
|
2
|
+
grasp_agents/agent_message_pool.py,sha256=4O4xz-aZ_I5m3iLAUiMAQcVn5AGRP4daUM8XME03Xsw,3250
|
3
|
+
grasp_agents/base_agent.py,sha256=Zf7lL-0iYse1hKTfgWYCCO8Va-8wKliougW6Nmd2RG4,1876
|
4
|
+
grasp_agents/cloud_llm.py,sha256=V1TN_xGTQ1uN4RVn_6bfYBEjnhxRCBHac60FFtCSawI,11677
|
5
|
+
grasp_agents/comm_agent.py,sha256=x1x6lE23F4iitofKlDgmXTT-aNt6L-sR8wC5L9DRCag,7748
|
6
|
+
grasp_agents/costs_dict.yaml,sha256=EW6XxRXLZobMwQEEiUNYALbDzfbZFb2zEVCaTSAqYjw,2334
|
7
|
+
grasp_agents/grasp_logging.py,sha256=H1GYhXdQvVkmauFDZ-KDwvVmPQHZUUm9sRqX_ObK2xI,1111
|
8
|
+
grasp_agents/http_client.py,sha256=KZva2MjJjuI5ohUeU8RdTAImUnQYaqBrV2jDH8smbJw,738
|
9
|
+
grasp_agents/llm.py,sha256=fks_mGkg2vgPGsJGr6rD6mN-IMgbYab_nA2qj3A3ADQ,2987
|
10
|
+
grasp_agents/llm_agent.py,sha256=9Z8qxOM4Y7oTBEi53zt8BqmAJIBqtwCGNxUfru458Xk,11997
|
11
|
+
grasp_agents/llm_agent_state.py,sha256=91K1-8Uodbe-t_I6nu0xBzHfQjssZYCHjMuDbu5aCr0,2327
|
12
|
+
grasp_agents/memory.py,sha256=7YkZKQHuXAfQlGqLoXdt6YZmgSj3EWVtT72s_v84ixc,5808
|
13
|
+
grasp_agents/printer.py,sha256=Jk6OJExio53gbKBod5Dd8Y3CWYrVb4K5q4UJ8i9cQvo,5024
|
14
|
+
grasp_agents/prompt_builder.py,sha256=rYVIY4adJwBitjrTYvpEh5x8C7cLbIiXxT1F-vQuvEM,7393
|
15
|
+
grasp_agents/run_context.py,sha256=hyETO3-p0azPFws75kX6rrUDLf58Ar6jmyt6TQ5Po78,2589
|
16
|
+
grasp_agents/tool_orchestrator.py,sha256=d7gOVqcki3qNC_UFvAyLO8iirGwrfzs50bQQrUF-43E,5513
|
17
|
+
grasp_agents/usage_tracker.py,sha256=5YuN6hpg6HASdg-hOylgWzhCiORmDMnZuQtbISfhm_4,3378
|
18
|
+
grasp_agents/utils.py,sha256=9newohaDSRuoUwSdrlox8RX3bI40MRTJyjT2S1MZzmE,4246
|
19
|
+
grasp_agents/data_retrieval/__init__.py,sha256=KRgtF_E7R3YfA2cpYcFcZ7wycV0pWVJ0xRQC7YhiIEQ,158
|
20
|
+
grasp_agents/data_retrieval/rate_limiter_chunked.py,sha256=NPqYrWwKTx1lim_zlhWar5wDwFz1cA-b6JOzT10kOtE,5843
|
21
|
+
grasp_agents/data_retrieval/types.py,sha256=JbLYJC-gmzcHH_4-YNTz9IcIwVpcpDyDGvljxNznf5k,1389
|
22
|
+
grasp_agents/data_retrieval/utils.py,sha256=D3Bkq6-9gF7ubearjZwZaTt_u2-sM3JDlGQD9HmJ3rQ,1917
|
23
|
+
grasp_agents/openai/__init__.py,sha256=qN8HMAatSJKOsA6v-JwakMYguwkswCVHqrmK1gFy9wI,3096
|
24
|
+
grasp_agents/openai/completion_converters.py,sha256=YvborvhN3_tACBBKXfOkx2NsTo6vqvNoPse_PqOSKUo,1774
|
25
|
+
grasp_agents/openai/content_converters.py,sha256=6GI0D7xJalzsiawAJOyCUzTJTo0NQdpv87YKmfN0LYQ,2631
|
26
|
+
grasp_agents/openai/converters.py,sha256=7O_K4MAW1CxwrF0vnA_MhrqwSeBx5eri8zADr-rzNuM,5346
|
27
|
+
grasp_agents/openai/message_converters.py,sha256=IJwt7nd_YRe_Cw0mk8Szi6_Ys30KVgCFSFv_pp60SQk,4714
|
28
|
+
grasp_agents/openai/openai_llm.py,sha256=A7ubei4pCR0g3mUk-0k-Anu5KBPmvNJnI3FSgIuKggk,6212
|
29
|
+
grasp_agents/openai/tool_converters.py,sha256=MKprfNMorVNNUVorFe77yWNSOcYtMauUJtpXpeF4AH4,1033
|
30
|
+
grasp_agents/typing/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
31
|
+
grasp_agents/typing/completion.py,sha256=_KDLx3Gtz7o-pEZrvAFgCZwDmkr2oQkxrL-2LSXHHsw,657
|
32
|
+
grasp_agents/typing/content.py,sha256=13nLNZqZgtpo9sM0vCRQmZ4bQjjZqUSElMQOwjL7bO8,3651
|
33
|
+
grasp_agents/typing/converters.py,sha256=VM_kVEf11qYzTg_3Z9Tbu8o-xndt3Cb90BjE3Daehes,3117
|
34
|
+
grasp_agents/typing/io.py,sha256=w2J71_-AaRFh1F3OEPXzAeMyHOKgG4l34A_scqU4GCg,813
|
35
|
+
grasp_agents/typing/message.py,sha256=1-QF14NZcPcDive_oVM6u12QHlt8q7NHuCY4kuFULbY,3725
|
36
|
+
grasp_agents/typing/tool.py,sha256=rLw8W8RIGQ5Hk9B0Yk9I8dN3wU2-D1lL54z_qiOlPRQ,1362
|
37
|
+
grasp_agents/workflow/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
38
|
+
grasp_agents/workflow/looped_agent.py,sha256=YBOgOIvy3_NwKvEoGgzQJ2fY9SNG66MQk6obSBGWvCc,3896
|
39
|
+
grasp_agents/workflow/sequential_agent.py,sha256=yDt2nA-b1leVByD8jsKrWD6bHe0o9z33jrOJGOLwbyk,2004
|
40
|
+
grasp_agents/workflow/workflow_agent.py,sha256=9U94IQ39Vb1W_5u8aoqHb65ikdarEhEJkexDz8xwHD4,2294
|
41
|
+
grasp_agents-0.1.5.dist-info/METADATA,sha256=3AG9RAi-4U0LzWtpcvZFzK5eBGYVRfARDyRQMDtculM,362
|
42
|
+
grasp_agents-0.1.5.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
43
|
+
grasp_agents-0.1.5.dist-info/licenses/LICENSE,sha256=GRDob7--af0SOT8BRgu7Ds1NqhunPyxGjyETcCk-o7s,1062
|
44
|
+
grasp_agents-0.1.5.dist-info/RECORD,,
|
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2025 Grasp
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|