rusticai-testing 0.0.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.
- rusticai_testing-0.0.3/PKG-INFO +37 -0
- rusticai_testing-0.0.3/README.md +17 -0
- rusticai_testing-0.0.3/pyproject.toml +66 -0
- rusticai_testing-0.0.3/src/rustic_ai/testing/__init__.py +0 -0
- rusticai_testing-0.0.3/src/rustic_ai/testing/agent_ext/__init__.py +0 -0
- rusticai_testing-0.0.3/src/rustic_ai/testing/agent_ext/base_test_kvstore.py +323 -0
- rusticai_testing-0.0.3/src/rustic_ai/testing/agents/__init__.py +0 -0
- rusticai_testing-0.0.3/src/rustic_ai/testing/agents/sample_agents.py +70 -0
- rusticai_testing-0.0.3/src/rustic_ai/testing/agents/simple_agent.py +35 -0
- rusticai_testing-0.0.3/src/rustic_ai/testing/execution/__init__.py +0 -0
- rusticai_testing-0.0.3/src/rustic_ai/testing/execution/base_test_integration.py +165 -0
- rusticai_testing-0.0.3/src/rustic_ai/testing/execution/integration_agents.py +63 -0
- rusticai_testing-0.0.3/src/rustic_ai/testing/helpers.py +99 -0
- rusticai_testing-0.0.3/src/rustic_ai/testing/messaging/__init__.py +0 -0
- rusticai_testing-0.0.3/src/rustic_ai/testing/messaging/base_test_backend.py +417 -0
- rusticai_testing-0.0.3/src/rustic_ai/testing/messaging/base_test_messaging.py +417 -0
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: rusticai-testing
|
|
3
|
+
Version: 0.0.3
|
|
4
|
+
Summary: Test Utilities for Rustic AI Framework
|
|
5
|
+
Home-page: https://www.rustic.ai/
|
|
6
|
+
License: Apache-2.0
|
|
7
|
+
Author: Dragonscale Industries Inc.
|
|
8
|
+
Author-email: dev@dragonscale.ai
|
|
9
|
+
Requires-Python: >=3.12,<4.0
|
|
10
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
14
|
+
Requires-Dist: pytest (>=8.3.5,<9.0.0)
|
|
15
|
+
Requires-Dist: rusticai-core (>=0.0.7,<0.1.0)
|
|
16
|
+
Project-URL: Repository, https://github.com/rustic-ai/python-framework
|
|
17
|
+
Project-URL: Rustic AI Core, https://pypi.org/project/rusticai-core/
|
|
18
|
+
Description-Content-Type: text/markdown
|
|
19
|
+
|
|
20
|
+
# Rustic AI Testing
|
|
21
|
+
|
|
22
|
+
Rustic AI Testing is a collection of test utilities that can be leveraged to verify integration with Rustic AI Framework.
|
|
23
|
+
**This should only be used for testing purposes and should not be used in production.**
|
|
24
|
+
|
|
25
|
+
## Installing
|
|
26
|
+
|
|
27
|
+
```shell
|
|
28
|
+
pip install rusticai-testing
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Building from Source
|
|
32
|
+
|
|
33
|
+
```shell
|
|
34
|
+
poetry install --with dev
|
|
35
|
+
poetry build
|
|
36
|
+
```
|
|
37
|
+
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# Rustic AI Testing
|
|
2
|
+
|
|
3
|
+
Rustic AI Testing is a collection of test utilities that can be leveraged to verify integration with Rustic AI Framework.
|
|
4
|
+
**This should only be used for testing purposes and should not be used in production.**
|
|
5
|
+
|
|
6
|
+
## Installing
|
|
7
|
+
|
|
8
|
+
```shell
|
|
9
|
+
pip install rusticai-testing
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
## Building from Source
|
|
13
|
+
|
|
14
|
+
```shell
|
|
15
|
+
poetry install --with dev
|
|
16
|
+
poetry build
|
|
17
|
+
```
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["poetry-core"]
|
|
3
|
+
build-backend = "poetry.core.masonry.api"
|
|
4
|
+
|
|
5
|
+
[tool.poetry]
|
|
6
|
+
name = "rusticai-testing"
|
|
7
|
+
version = "0.0.3"
|
|
8
|
+
description = "Test Utilities for Rustic AI Framework"
|
|
9
|
+
authors = ["Dragonscale Industries Inc. <dev@dragonscale.ai>"]
|
|
10
|
+
license = "Apache-2.0"
|
|
11
|
+
readme = "README.md"
|
|
12
|
+
homepage = "https://www.rustic.ai/"
|
|
13
|
+
repository = "https://github.com/rustic-ai/python-framework"
|
|
14
|
+
packages = [{ include = "rustic_ai", from = "src" }]
|
|
15
|
+
|
|
16
|
+
[tool.poetry.urls]
|
|
17
|
+
"Rustic AI Core" = "https://pypi.org/project/rusticai-core/"
|
|
18
|
+
|
|
19
|
+
[tool.poetry.dependencies]
|
|
20
|
+
python = "^3.12"
|
|
21
|
+
rusticai-core = { version = "0.0.7"}
|
|
22
|
+
pytest = "^8.3.5"
|
|
23
|
+
|
|
24
|
+
[tool.poetry-monorepo.deps]
|
|
25
|
+
|
|
26
|
+
[tool.poetry.group.dev]
|
|
27
|
+
optional = true
|
|
28
|
+
|
|
29
|
+
[tool.poetry.group.dev.dependencies]
|
|
30
|
+
pytest = "^8.3.4"
|
|
31
|
+
black = { version = "^24.2.0", extras = ["jupyter"] }
|
|
32
|
+
flake8 = "^7.1.2"
|
|
33
|
+
tox = "^4.24.1"
|
|
34
|
+
isort = "^6.0.0"
|
|
35
|
+
mypy = "^1.15.0"
|
|
36
|
+
|
|
37
|
+
[tool.black]
|
|
38
|
+
line-length = 120
|
|
39
|
+
target-version = ['py312']
|
|
40
|
+
include = '\.pyi?$'
|
|
41
|
+
exclude = '''
|
|
42
|
+
/(
|
|
43
|
+
\.git
|
|
44
|
+
| \.mypy_cache
|
|
45
|
+
| \.tox
|
|
46
|
+
| \.venv
|
|
47
|
+
| _build
|
|
48
|
+
| buck-out
|
|
49
|
+
| build
|
|
50
|
+
| dist
|
|
51
|
+
)/
|
|
52
|
+
'''
|
|
53
|
+
|
|
54
|
+
[tool.mypy]
|
|
55
|
+
python_version = "3.12"
|
|
56
|
+
ignore_missing_imports = true
|
|
57
|
+
check_untyped_defs = true
|
|
58
|
+
plugins = "pydantic.mypy"
|
|
59
|
+
explicit_package_bases = true
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
[tool.isort]
|
|
63
|
+
profile = "black"
|
|
64
|
+
known_third_party = ["pydantic"]
|
|
65
|
+
known_first_party = ["rustic_ai.core"]
|
|
66
|
+
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,323 @@
|
|
|
1
|
+
import time
|
|
2
|
+
from abc import ABC, abstractmethod
|
|
3
|
+
|
|
4
|
+
import pytest
|
|
5
|
+
from pydantic import BaseModel, JsonValue
|
|
6
|
+
|
|
7
|
+
from rustic_ai.core.agents.testutils.probe_agent import ProbeAgent
|
|
8
|
+
from rustic_ai.core.guild import agent
|
|
9
|
+
from rustic_ai.core.guild.agent import (
|
|
10
|
+
Agent,
|
|
11
|
+
AgentDependency,
|
|
12
|
+
AgentMode,
|
|
13
|
+
AgentType,
|
|
14
|
+
ProcessContext,
|
|
15
|
+
)
|
|
16
|
+
from rustic_ai.core.guild.agent_ext.depends.kvstore.base import BaseKVStore
|
|
17
|
+
from rustic_ai.core.guild.agent_ext.depends.kvstore.in_memory_kvstore import (
|
|
18
|
+
InMemoryKVStoreResolver,
|
|
19
|
+
)
|
|
20
|
+
from rustic_ai.core.guild.builders import AgentBuilder, GuildBuilder
|
|
21
|
+
from rustic_ai.core.guild.dsl import AgentSpec
|
|
22
|
+
from rustic_ai.core.utils.basic_class_utils import get_qualified_class_name
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class KVPut(BaseModel):
|
|
26
|
+
key: str
|
|
27
|
+
value: JsonValue
|
|
28
|
+
in_guild_store: bool = False
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
class KVResponse(BaseModel):
|
|
32
|
+
key: str
|
|
33
|
+
value: JsonValue
|
|
34
|
+
method: str
|
|
35
|
+
guild_store: bool = False
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
class KVGet(BaseModel):
|
|
39
|
+
key: str
|
|
40
|
+
from_guild_store: bool = False
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
class KVDel(BaseModel):
|
|
44
|
+
key: str
|
|
45
|
+
from_guild_store: bool = False
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
class KeyNotFound(BaseModel):
|
|
49
|
+
key: str
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
class KVStoreAgent(Agent):
|
|
53
|
+
"""
|
|
54
|
+
Agent for testing KVStore dependencies
|
|
55
|
+
"""
|
|
56
|
+
|
|
57
|
+
def __init__(self, agent_spec: AgentSpec):
|
|
58
|
+
super().__init__(
|
|
59
|
+
agent_spec,
|
|
60
|
+
agent_type=AgentType.BOT,
|
|
61
|
+
agent_mode=AgentMode.LOCAL,
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
@agent.processor(
|
|
65
|
+
KVPut,
|
|
66
|
+
depends_on=[
|
|
67
|
+
"kvstore",
|
|
68
|
+
AgentDependency(
|
|
69
|
+
dependency_key="kvstore",
|
|
70
|
+
dependency_var="guild_kvstore",
|
|
71
|
+
guild_level=True,
|
|
72
|
+
),
|
|
73
|
+
],
|
|
74
|
+
)
|
|
75
|
+
def store_kv(
|
|
76
|
+
self,
|
|
77
|
+
ctx: ProcessContext[KVPut],
|
|
78
|
+
kvstore: BaseKVStore,
|
|
79
|
+
guild_kvstore: BaseKVStore,
|
|
80
|
+
):
|
|
81
|
+
"""
|
|
82
|
+
Handles messages of type KVPut
|
|
83
|
+
"""
|
|
84
|
+
data: KVPut = ctx.payload
|
|
85
|
+
if data.in_guild_store:
|
|
86
|
+
guild_kvstore.set(data.key, data.value)
|
|
87
|
+
else:
|
|
88
|
+
kvstore.set(data.key, data.value)
|
|
89
|
+
|
|
90
|
+
ctx.send(
|
|
91
|
+
KVResponse(
|
|
92
|
+
key=data.key,
|
|
93
|
+
value=data.value,
|
|
94
|
+
method="PUT",
|
|
95
|
+
guild_store=data.in_guild_store,
|
|
96
|
+
)
|
|
97
|
+
)
|
|
98
|
+
|
|
99
|
+
@agent.processor(
|
|
100
|
+
KVGet,
|
|
101
|
+
depends_on=[
|
|
102
|
+
"kvstore",
|
|
103
|
+
AgentDependency(
|
|
104
|
+
dependency_key="kvstore",
|
|
105
|
+
dependency_var="guild_kvstore",
|
|
106
|
+
guild_level=True,
|
|
107
|
+
),
|
|
108
|
+
],
|
|
109
|
+
)
|
|
110
|
+
def get_kv(
|
|
111
|
+
self,
|
|
112
|
+
ctx: ProcessContext[KVGet],
|
|
113
|
+
kvstore: BaseKVStore,
|
|
114
|
+
guild_kvstore: BaseKVStore,
|
|
115
|
+
):
|
|
116
|
+
"""
|
|
117
|
+
Handles messages of type KVGet
|
|
118
|
+
"""
|
|
119
|
+
data: KVGet = ctx.payload
|
|
120
|
+
if data.from_guild_store:
|
|
121
|
+
value = guild_kvstore.get(data.key)
|
|
122
|
+
else:
|
|
123
|
+
value = kvstore.get(data.key)
|
|
124
|
+
|
|
125
|
+
if value:
|
|
126
|
+
resp = KVResponse(
|
|
127
|
+
key=data.key,
|
|
128
|
+
value=value,
|
|
129
|
+
method="GET",
|
|
130
|
+
guild_store=data.from_guild_store,
|
|
131
|
+
)
|
|
132
|
+
|
|
133
|
+
ctx.send(resp)
|
|
134
|
+
else:
|
|
135
|
+
ctx.send(KeyNotFound(key=data.key))
|
|
136
|
+
|
|
137
|
+
@agent.processor(
|
|
138
|
+
KVDel,
|
|
139
|
+
depends_on=[
|
|
140
|
+
"kvstore",
|
|
141
|
+
AgentDependency(
|
|
142
|
+
dependency_key="kvstore",
|
|
143
|
+
dependency_var="guild_kvstore",
|
|
144
|
+
guild_level=True,
|
|
145
|
+
),
|
|
146
|
+
],
|
|
147
|
+
)
|
|
148
|
+
def del_kv(
|
|
149
|
+
self,
|
|
150
|
+
ctx: ProcessContext[KVDel],
|
|
151
|
+
kvstore: BaseKVStore,
|
|
152
|
+
guild_kvstore: BaseKVStore,
|
|
153
|
+
):
|
|
154
|
+
"""
|
|
155
|
+
Handles messages of type KVDel
|
|
156
|
+
"""
|
|
157
|
+
data: KVDel = ctx.payload
|
|
158
|
+
if data.from_guild_store:
|
|
159
|
+
guild_kvstore.delete(data.key)
|
|
160
|
+
else:
|
|
161
|
+
kvstore.delete(data.key)
|
|
162
|
+
|
|
163
|
+
ctx.send(
|
|
164
|
+
KVResponse(
|
|
165
|
+
key=data.key,
|
|
166
|
+
value=None,
|
|
167
|
+
method="DEL",
|
|
168
|
+
guild_store=data.from_guild_store,
|
|
169
|
+
)
|
|
170
|
+
)
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
class BaseTestKVStore(ABC):
|
|
174
|
+
|
|
175
|
+
@pytest.fixture
|
|
176
|
+
@abstractmethod
|
|
177
|
+
def dep_map(self) -> dict:
|
|
178
|
+
"""
|
|
179
|
+
Fixture that returns dependency mapping of the storage implementation being tested.
|
|
180
|
+
This should be overridden in subclasses that test specific storage implementations.
|
|
181
|
+
"""
|
|
182
|
+
raise NotImplementedError("This fixture should be overridden in subclasses.")
|
|
183
|
+
|
|
184
|
+
def test_kvstore(self, probe_agent: ProbeAgent, dep_map: dict):
|
|
185
|
+
agent_spec: AgentSpec = (
|
|
186
|
+
AgentBuilder(KVStoreAgent).set_description("KV Store Agent").set_name("KVStoreAgent").build_spec()
|
|
187
|
+
)
|
|
188
|
+
|
|
189
|
+
guild_builder = (
|
|
190
|
+
GuildBuilder("test_guild", "Test Guild", "Guild to test KV Store Agent")
|
|
191
|
+
.add_agent_spec(agent_spec)
|
|
192
|
+
.set_dependency_map(dep_map)
|
|
193
|
+
)
|
|
194
|
+
guild = guild_builder.launch()
|
|
195
|
+
|
|
196
|
+
if "kvstore" in dep_map:
|
|
197
|
+
guild.dependency_map["kvstore"].class_name = dep_map["kvstore"].class_name
|
|
198
|
+
else:
|
|
199
|
+
guild.dependency_map["kvstore"].class_name = InMemoryKVStoreResolver.get_qualified_class_name()
|
|
200
|
+
|
|
201
|
+
guild._add_local_agent(probe_agent)
|
|
202
|
+
|
|
203
|
+
probe_agent.publish_dict(
|
|
204
|
+
topic="default_topic",
|
|
205
|
+
payload=KVPut(key="key1", value=42).model_dump(),
|
|
206
|
+
format=KVPut,
|
|
207
|
+
)
|
|
208
|
+
|
|
209
|
+
time.sleep(0.5)
|
|
210
|
+
|
|
211
|
+
probe_agent.publish_dict(
|
|
212
|
+
topic="default_topic",
|
|
213
|
+
payload=KVGet(key="key1").model_dump(),
|
|
214
|
+
format=KVGet,
|
|
215
|
+
)
|
|
216
|
+
|
|
217
|
+
time.sleep(0.5)
|
|
218
|
+
|
|
219
|
+
messages = probe_agent.get_messages()
|
|
220
|
+
|
|
221
|
+
assert len(messages) == 2
|
|
222
|
+
|
|
223
|
+
assert messages[0].payload["key"] == "key1"
|
|
224
|
+
assert messages[0].payload["value"] == 42
|
|
225
|
+
|
|
226
|
+
assert messages[1].payload["key"] == "key1"
|
|
227
|
+
assert messages[1].payload["value"] == 42
|
|
228
|
+
|
|
229
|
+
probe_agent.clear_messages()
|
|
230
|
+
|
|
231
|
+
probe_agent.publish_dict(
|
|
232
|
+
topic="default_topic",
|
|
233
|
+
payload=KVPut(key="key1", value=43, in_guild_store=True).model_dump(),
|
|
234
|
+
format=KVPut,
|
|
235
|
+
)
|
|
236
|
+
|
|
237
|
+
time.sleep(0.5)
|
|
238
|
+
|
|
239
|
+
probe_agent.publish_dict(
|
|
240
|
+
topic="default_topic",
|
|
241
|
+
payload=KVGet(key="key1", from_guild_store=True).model_dump(),
|
|
242
|
+
format=KVGet,
|
|
243
|
+
)
|
|
244
|
+
|
|
245
|
+
time.sleep(0.5)
|
|
246
|
+
|
|
247
|
+
messages = probe_agent.get_messages()
|
|
248
|
+
|
|
249
|
+
assert len(messages) == 2
|
|
250
|
+
|
|
251
|
+
assert messages[0].payload["key"] == "key1"
|
|
252
|
+
assert messages[0].payload["value"] == 43
|
|
253
|
+
|
|
254
|
+
assert messages[1].payload["key"] == "key1"
|
|
255
|
+
assert messages[1].payload["value"] == 43
|
|
256
|
+
|
|
257
|
+
probe_agent.clear_messages()
|
|
258
|
+
|
|
259
|
+
probe_agent.publish_dict(
|
|
260
|
+
topic="default_topic",
|
|
261
|
+
payload=KVDel(key="key1").model_dump(),
|
|
262
|
+
format=KVDel,
|
|
263
|
+
)
|
|
264
|
+
|
|
265
|
+
time.sleep(0.5)
|
|
266
|
+
|
|
267
|
+
probe_agent.publish_dict(
|
|
268
|
+
topic="default_topic",
|
|
269
|
+
payload=KVGet(key="key1").model_dump(),
|
|
270
|
+
format=KVGet,
|
|
271
|
+
)
|
|
272
|
+
|
|
273
|
+
time.sleep(0.5)
|
|
274
|
+
|
|
275
|
+
probe_agent.publish_dict(
|
|
276
|
+
topic="default_topic",
|
|
277
|
+
payload=KVGet(key="key1", from_guild_store=True).model_dump(),
|
|
278
|
+
format=KVGet,
|
|
279
|
+
)
|
|
280
|
+
|
|
281
|
+
messages = probe_agent.get_messages()
|
|
282
|
+
|
|
283
|
+
assert len(messages) == 3
|
|
284
|
+
|
|
285
|
+
assert messages[0].payload["key"] == "key1"
|
|
286
|
+
assert messages[0].payload["value"] is None
|
|
287
|
+
assert messages[0].payload["method"] == "DEL"
|
|
288
|
+
|
|
289
|
+
assert messages[1].payload["key"] == "key1"
|
|
290
|
+
assert messages[1].format == get_qualified_class_name(KeyNotFound)
|
|
291
|
+
|
|
292
|
+
assert messages[2].payload["key"] == "key1"
|
|
293
|
+
assert messages[2].payload["value"] == 43
|
|
294
|
+
|
|
295
|
+
probe_agent.clear_messages()
|
|
296
|
+
|
|
297
|
+
probe_agent.publish_dict(
|
|
298
|
+
topic="default_topic",
|
|
299
|
+
payload=KVDel(key="key1", from_guild_store=True).model_dump(),
|
|
300
|
+
format=KVDel,
|
|
301
|
+
)
|
|
302
|
+
|
|
303
|
+
time.sleep(0.5)
|
|
304
|
+
|
|
305
|
+
probe_agent.publish_dict(
|
|
306
|
+
topic="default_topic",
|
|
307
|
+
payload=KVGet(key="key1", from_guild_store=True).model_dump(),
|
|
308
|
+
format=KVGet,
|
|
309
|
+
)
|
|
310
|
+
|
|
311
|
+
time.sleep(0.5)
|
|
312
|
+
|
|
313
|
+
messages = probe_agent.get_messages()
|
|
314
|
+
|
|
315
|
+
assert len(messages) == 2
|
|
316
|
+
|
|
317
|
+
assert messages[0].payload["key"] == "key1"
|
|
318
|
+
assert messages[0].payload["value"] is None
|
|
319
|
+
|
|
320
|
+
assert messages[1].payload["key"] == "key1"
|
|
321
|
+
assert messages[1].format == get_qualified_class_name(KeyNotFound)
|
|
322
|
+
|
|
323
|
+
guild.shutdown()
|
|
File without changes
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
from typing import Generic, TypeVar
|
|
2
|
+
|
|
3
|
+
from pydantic import BaseModel, Field
|
|
4
|
+
|
|
5
|
+
from rustic_ai.core.guild import Agent, AgentMode, AgentSpec, AgentType, agent
|
|
6
|
+
from rustic_ai.core.guild.dsl import BaseAgentProps
|
|
7
|
+
|
|
8
|
+
T = TypeVar("T")
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class DemoAgentProps(BaseAgentProps):
|
|
12
|
+
prop1: str = Field(default="default_value")
|
|
13
|
+
prop2: int = Field(default=1)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class SimpleClass:
|
|
17
|
+
pass
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class GenericClass(Generic[T]):
|
|
21
|
+
pass
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
class MessageDataType(BaseModel):
|
|
25
|
+
data: str
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
class DemoAgentSimple(Agent):
|
|
29
|
+
def __init__(self, agent_spec: AgentSpec):
|
|
30
|
+
super().__init__(agent_spec=agent_spec, agent_type=AgentType.BOT, agent_mode=AgentMode.LOCAL)
|
|
31
|
+
|
|
32
|
+
@agent.processor(MessageDataType)
|
|
33
|
+
def handle_message(self, ctx: agent.ProcessContext[MessageDataType]):
|
|
34
|
+
print(f"Received message: {ctx.payload.data}")
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
class DemoAgentGeneric(Agent[DemoAgentProps]):
|
|
38
|
+
def __init__(self, agent_spec: AgentSpec[DemoAgentProps]):
|
|
39
|
+
super().__init__(agent_spec=agent_spec, agent_type=AgentType.BOT, agent_mode=AgentMode.LOCAL)
|
|
40
|
+
|
|
41
|
+
@agent.processor(MessageDataType)
|
|
42
|
+
def handle_message(self, ctx: agent.ProcessContext[MessageDataType]):
|
|
43
|
+
print(f"Received message: {ctx.payload.data}")
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
class DemoAgentGenericWithoutTypedSpec(Agent[DemoAgentProps]):
|
|
47
|
+
def __init__(self, agent_spec: AgentSpec):
|
|
48
|
+
super().__init__(agent_spec=agent_spec, agent_type=AgentType.BOT, agent_mode=AgentMode.LOCAL)
|
|
49
|
+
|
|
50
|
+
@agent.processor(MessageDataType)
|
|
51
|
+
def handle_message(self, ctx: agent.ProcessContext[MessageDataType]):
|
|
52
|
+
print(f"Received message: {ctx.payload.data}")
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
class DemoAgentGenericWithoutTypedParams(Agent[DemoAgentProps]):
|
|
56
|
+
def __init__(self, agent_spec):
|
|
57
|
+
super().__init__(agent_spec=agent_spec, agent_type=AgentType.BOT, agent_mode=AgentMode.LOCAL)
|
|
58
|
+
|
|
59
|
+
@agent.processor(MessageDataType)
|
|
60
|
+
def handle_message(self, ctx: agent.ProcessContext[MessageDataType]):
|
|
61
|
+
print(f"Received message: {ctx.payload.data}")
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
class DemoAgentWithMissingGenericAnnotation(Agent):
|
|
65
|
+
def __init__(self, agent_spec: AgentSpec[DemoAgentProps]):
|
|
66
|
+
super().__init__(agent_spec=agent_spec, agent_type=AgentType.BOT, agent_mode=AgentMode.LOCAL)
|
|
67
|
+
|
|
68
|
+
@agent.processor(MessageDataType)
|
|
69
|
+
def handle_message(self, ctx: agent.ProcessContext[MessageDataType]):
|
|
70
|
+
print(f"Received message: {ctx.payload.data}")
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
from typing import List
|
|
2
|
+
|
|
3
|
+
from rustic_ai.core.guild import Agent, AgentMode, AgentType, BaseAgentProps, agent
|
|
4
|
+
from rustic_ai.core.guild.dsl import AgentSpec
|
|
5
|
+
from rustic_ai.core.messaging.core import JsonDict
|
|
6
|
+
from rustic_ai.core.messaging.core.message import Message
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class SimpleAgent(Agent):
|
|
10
|
+
def __init__(
|
|
11
|
+
self,
|
|
12
|
+
agent_spec: AgentSpec,
|
|
13
|
+
):
|
|
14
|
+
super().__init__(agent_spec=agent_spec, agent_type=AgentType.BOT, agent_mode=AgentMode.LOCAL)
|
|
15
|
+
self.received_messages: List[Message] = []
|
|
16
|
+
|
|
17
|
+
@agent.processor(JsonDict)
|
|
18
|
+
def collect_message(self, ctx: agent.ProcessContext[JsonDict]) -> None:
|
|
19
|
+
self.received_messages.append(ctx.message.model_copy(deep=True))
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class SimpleAgentProps(BaseAgentProps):
|
|
23
|
+
prop1: str
|
|
24
|
+
prop2: int
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
class SimpleAgentWithProps(Agent[SimpleAgentProps]):
|
|
28
|
+
def __init__(self, agent_spec: AgentSpec[SimpleAgentProps]):
|
|
29
|
+
super().__init__(agent_spec=agent_spec, agent_type=AgentType.BOT, agent_mode=AgentMode.LOCAL)
|
|
30
|
+
self.received_messages: List[Message] = []
|
|
31
|
+
self._props = agent_spec.props
|
|
32
|
+
|
|
33
|
+
@agent.processor(JsonDict)
|
|
34
|
+
def collect_message(self, ctx: agent.ProcessContext[JsonDict]) -> None:
|
|
35
|
+
self.received_messages.append(ctx.message.model_copy(deep=True))
|
|
File without changes
|