uagents-core 0.3.2__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.
- {uagents_core-0.3.2 → uagents_core-0.3.3}/PKG-INFO +1 -1
- {uagents_core-0.3.2 → uagents_core-0.3.3}/pyproject.toml +1 -1
- {uagents_core-0.3.2 → uagents_core-0.3.3}/uagents_core/registration.py +4 -0
- {uagents_core-0.3.2 → uagents_core-0.3.3}/uagents_core/utils/registration.py +140 -15
- {uagents_core-0.3.2 → uagents_core-0.3.3}/README.md +0 -0
- {uagents_core-0.3.2 → uagents_core-0.3.3}/uagents_core/__init__.py +0 -0
- {uagents_core-0.3.2 → uagents_core-0.3.3}/uagents_core/config.py +0 -0
- {uagents_core-0.3.2 → uagents_core-0.3.3}/uagents_core/contrib/__init__.py +0 -0
- {uagents_core-0.3.2 → uagents_core-0.3.3}/uagents_core/contrib/protocols/__init__.py +0 -0
- {uagents_core-0.3.2 → uagents_core-0.3.3}/uagents_core/contrib/protocols/chat/__init__.py +0 -0
- {uagents_core-0.3.2 → uagents_core-0.3.3}/uagents_core/contrib/protocols/subscriptions/__init__.py +0 -0
- {uagents_core-0.3.2 → uagents_core-0.3.3}/uagents_core/envelope.py +0 -0
- {uagents_core-0.3.2 → uagents_core-0.3.3}/uagents_core/helpers.py +0 -0
- {uagents_core-0.3.2 → uagents_core-0.3.3}/uagents_core/identity.py +0 -0
- {uagents_core-0.3.2 → uagents_core-0.3.3}/uagents_core/logger.py +0 -0
- {uagents_core-0.3.2 → uagents_core-0.3.3}/uagents_core/models.py +0 -0
- {uagents_core-0.3.2 → uagents_core-0.3.3}/uagents_core/protocol.py +0 -0
- {uagents_core-0.3.2 → uagents_core-0.3.3}/uagents_core/storage.py +0 -0
- {uagents_core-0.3.2 → uagents_core-0.3.3}/uagents_core/types.py +0 -0
- {uagents_core-0.3.2 → uagents_core-0.3.3}/uagents_core/utils/__init__.py +0 -0
- {uagents_core-0.3.2 → uagents_core-0.3.3}/uagents_core/utils/messages.py +0 -0
- {uagents_core-0.3.2 → uagents_core-0.3.3}/uagents_core/utils/resolver.py +0 -0
@@ -73,6 +73,10 @@ class AgentRegistrationAttestation(VerifiableModel):
|
|
73
73
|
metadata: dict[str, str | list[str] | dict[str, str]] | None = None
|
74
74
|
|
75
75
|
|
76
|
+
class AgentRegistrationAttestationBatch(BaseModel):
|
77
|
+
attestations: list[AgentRegistrationAttestation]
|
78
|
+
|
79
|
+
|
76
80
|
# Agentverse related models
|
77
81
|
class RegistrationRequest(BaseModel):
|
78
82
|
address: str
|
@@ -19,6 +19,7 @@ from uagents_core.logger import get_logger
|
|
19
19
|
from uagents_core.protocol import is_valid_protocol_digest
|
20
20
|
from uagents_core.registration import (
|
21
21
|
AgentRegistrationAttestation,
|
22
|
+
AgentRegistrationAttestationBatch,
|
22
23
|
AgentStatusUpdate,
|
23
24
|
AgentUpdates,
|
24
25
|
AgentverseConnectRequest,
|
@@ -27,11 +28,33 @@ from uagents_core.registration import (
|
|
27
28
|
RegistrationRequest,
|
28
29
|
RegistrationResponse,
|
29
30
|
)
|
30
|
-
from uagents_core.types import AgentEndpoint
|
31
|
+
from uagents_core.types import AddressPrefix, AgentEndpoint
|
31
32
|
|
32
33
|
logger = get_logger("uagents_core.utils.registration")
|
33
34
|
|
34
35
|
|
36
|
+
class AgentRegistrationInput:
|
37
|
+
identity: Identity
|
38
|
+
prefix: str | None = None
|
39
|
+
endpoints: list[str]
|
40
|
+
protocol_digests: list[str]
|
41
|
+
metadata: dict[str, str | list[str] | dict[str, str]] | None = None
|
42
|
+
|
43
|
+
def __init__(
|
44
|
+
self,
|
45
|
+
identity: Identity,
|
46
|
+
endpoints: list[str],
|
47
|
+
protocol_digests: list[str],
|
48
|
+
prefix: AddressPrefix | None = None,
|
49
|
+
metadata: dict[str, str | list[str] | dict[str, str]] | None = None,
|
50
|
+
):
|
51
|
+
self.identity = identity
|
52
|
+
self.prefix = prefix
|
53
|
+
self.endpoints = endpoints
|
54
|
+
self.protocol_digests = protocol_digests
|
55
|
+
self.metadata = metadata
|
56
|
+
|
57
|
+
|
35
58
|
def _send_post_request(
|
36
59
|
url: str,
|
37
60
|
data: BaseModel,
|
@@ -63,11 +86,32 @@ def _send_post_request(
|
|
63
86
|
return False, None
|
64
87
|
|
65
88
|
|
89
|
+
def _build_signed_attestation(
|
90
|
+
item: AgentRegistrationInput,
|
91
|
+
) -> AgentRegistrationAttestation:
|
92
|
+
agent_endpoints: list[AgentEndpoint] = [
|
93
|
+
AgentEndpoint(url=endpoint, weight=1) for endpoint in item.endpoints
|
94
|
+
]
|
95
|
+
|
96
|
+
attestation = AgentRegistrationAttestation(
|
97
|
+
agent_identifier=f"{item.prefix}://{item.identity.address}"
|
98
|
+
if item.prefix
|
99
|
+
else item.identity.address,
|
100
|
+
protocols=item.protocol_digests,
|
101
|
+
endpoints=agent_endpoints,
|
102
|
+
metadata=item.metadata,
|
103
|
+
)
|
104
|
+
|
105
|
+
attestation.sign(item.identity)
|
106
|
+
return attestation
|
107
|
+
|
108
|
+
|
66
109
|
def register_in_almanac(
|
67
110
|
identity: Identity,
|
68
111
|
endpoints: list[str],
|
69
112
|
protocol_digests: list[str],
|
70
113
|
metadata: dict[str, str | list[str] | dict[str, str]] | None = None,
|
114
|
+
prefix: AddressPrefix | None = None,
|
71
115
|
*,
|
72
116
|
agentverse_config: AgentverseConfig | None = None,
|
73
117
|
timeout: int = DEFAULT_REQUEST_TIMEOUT,
|
@@ -77,6 +121,7 @@ def register_in_almanac(
|
|
77
121
|
|
78
122
|
Args:
|
79
123
|
identity (Identity): The identity of the agent.
|
124
|
+
prefix (AddressPrefix | None): The prefix for the agent identifier.
|
80
125
|
endpoints (list[str]): The endpoints that the agent can be reached at.
|
81
126
|
protocol_digests (list[str]): The digests of the protocol that the agent supports
|
82
127
|
agentverse_config (AgentverseConfig): The configuration for the agentverse API
|
@@ -95,10 +140,6 @@ def register_in_almanac(
|
|
95
140
|
)
|
96
141
|
return False
|
97
142
|
|
98
|
-
agent_endpoints: list[AgentEndpoint] = [
|
99
|
-
AgentEndpoint(url=endpoint, weight=1) for endpoint in endpoints
|
100
|
-
]
|
101
|
-
|
102
143
|
# check protocol digests
|
103
144
|
for proto_digest in protocol_digests:
|
104
145
|
if not is_valid_protocol_digest(proto_digest):
|
@@ -112,22 +153,18 @@ def register_in_almanac(
|
|
112
153
|
agentverse_config = agentverse_config or AgentverseConfig()
|
113
154
|
almanac_api = urllib.parse.urljoin(agentverse_config.url, DEFAULT_ALMANAC_API_PATH)
|
114
155
|
|
115
|
-
# get the agent address
|
116
|
-
agent_address = identity.address
|
117
|
-
|
118
156
|
# create the attestation
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
endpoints=
|
157
|
+
item = AgentRegistrationInput(
|
158
|
+
identity=identity,
|
159
|
+
prefix=prefix,
|
160
|
+
endpoints=endpoints,
|
161
|
+
protocol_digests=protocol_digests,
|
123
162
|
metadata=metadata,
|
124
163
|
)
|
164
|
+
attestation = _build_signed_attestation(item)
|
125
165
|
|
126
166
|
logger.info(msg="Registering with Almanac API", extra=attestation.model_dump())
|
127
167
|
|
128
|
-
# sign the attestation
|
129
|
-
attestation.sign(identity)
|
130
|
-
|
131
168
|
# submit the attestation to the API
|
132
169
|
status, _ = _send_post_request(
|
133
170
|
url=f"{almanac_api}/agents", data=attestation, timeout=timeout
|
@@ -135,6 +172,94 @@ def register_in_almanac(
|
|
135
172
|
return status
|
136
173
|
|
137
174
|
|
175
|
+
def register_batch_in_almanac(
|
176
|
+
items: list[AgentRegistrationInput],
|
177
|
+
*,
|
178
|
+
agentverse_config: AgentverseConfig | None = None,
|
179
|
+
timeout: int = DEFAULT_REQUEST_TIMEOUT,
|
180
|
+
validate_all_before_registration: bool = False,
|
181
|
+
) -> tuple[bool, list[str]]:
|
182
|
+
"""
|
183
|
+
Register multiple identities with the Almanac API to make them discoverable by other agents.
|
184
|
+
|
185
|
+
The return value is a 2-tuple including:
|
186
|
+
* (bool) Whether the registration request was both attempted and successful.
|
187
|
+
* (list[str]) A list of addresses of identities that failed validation.
|
188
|
+
|
189
|
+
If `validate_all_before_registration` is `True`, no registration request will be sent
|
190
|
+
unless all identities pass validation.
|
191
|
+
|
192
|
+
Args:
|
193
|
+
items (list[AgentRegistrationInput]): The list of identities to register.
|
194
|
+
See `register_in_almanac` for details about attributes in `AgentRegistrationInput`.
|
195
|
+
agentverse_config (AgentverseConfig): The configuration for the agentverse API
|
196
|
+
timeout (int): The timeout for the request
|
197
|
+
"""
|
198
|
+
invalid_identities: list[str] = []
|
199
|
+
attestations: list[AgentRegistrationAttestation] = []
|
200
|
+
|
201
|
+
for item in items:
|
202
|
+
# check endpoints
|
203
|
+
if not item.endpoints:
|
204
|
+
logger.warning(
|
205
|
+
f"No endpoints provided for {item.identity.address}; skipping registration",
|
206
|
+
)
|
207
|
+
invalid_identities.append(item.identity.address)
|
208
|
+
for endpoint in item.endpoints:
|
209
|
+
result = urllib.parse.urlparse(endpoint)
|
210
|
+
if not all([result.scheme, result.netloc]):
|
211
|
+
logger.error(
|
212
|
+
msg=f"Invalid endpoint provided for {item.identity.address}; "
|
213
|
+
+ "skipping registration",
|
214
|
+
extra={"endpoint": endpoint},
|
215
|
+
)
|
216
|
+
invalid_identities.append(item.identity.address)
|
217
|
+
|
218
|
+
# check protocol digests
|
219
|
+
for proto_digest in item.protocol_digests:
|
220
|
+
if not is_valid_protocol_digest(proto_digest):
|
221
|
+
logger.error(
|
222
|
+
msg=f"Invalid protocol digest provided for {item.identity.address}; "
|
223
|
+
+ "skipping registration",
|
224
|
+
extra={"protocol_digest": proto_digest},
|
225
|
+
)
|
226
|
+
invalid_identities.append(item.identity.address)
|
227
|
+
|
228
|
+
# Remove duplicates
|
229
|
+
invalid_identities = sorted(list(set(invalid_identities)))
|
230
|
+
|
231
|
+
for item in items:
|
232
|
+
if item.identity.address not in invalid_identities:
|
233
|
+
attestations.append(_build_signed_attestation(item))
|
234
|
+
|
235
|
+
if validate_all_before_registration and invalid_identities:
|
236
|
+
return False, invalid_identities
|
237
|
+
|
238
|
+
# get the almanac API endpoint
|
239
|
+
agentverse_config = agentverse_config or AgentverseConfig()
|
240
|
+
almanac_api = urllib.parse.urljoin(agentverse_config.url, DEFAULT_ALMANAC_API_PATH)
|
241
|
+
|
242
|
+
logger.info(
|
243
|
+
msg="Bulk registering with Almanac API",
|
244
|
+
extra={
|
245
|
+
"agent_addresses": [
|
246
|
+
attestation.agent_identifier for attestation in attestations
|
247
|
+
]
|
248
|
+
},
|
249
|
+
)
|
250
|
+
attestation_batch = AgentRegistrationAttestationBatch(
|
251
|
+
attestations=attestations,
|
252
|
+
)
|
253
|
+
|
254
|
+
# submit the attestation to the API
|
255
|
+
status, _ = _send_post_request(
|
256
|
+
url=f"{almanac_api}/agents/batch",
|
257
|
+
data=attestation_batch,
|
258
|
+
timeout=timeout,
|
259
|
+
)
|
260
|
+
return status, invalid_identities
|
261
|
+
|
262
|
+
|
138
263
|
# associate user account with your agent
|
139
264
|
def register_in_agentverse(
|
140
265
|
request: AgentverseConnectRequest,
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
{uagents_core-0.3.2 → uagents_core-0.3.3}/uagents_core/contrib/protocols/subscriptions/__init__.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
|