uagents-core 0.3.4__py3-none-any.whl → 0.3.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.
uagents_core/types.py CHANGED
@@ -1,4 +1,5 @@
1
1
  import uuid
2
+ from abc import ABC, abstractmethod
2
3
  from enum import Enum
3
4
  from typing import Any, Literal
4
5
 
@@ -48,3 +49,31 @@ class MsgStatus(BaseModel):
48
49
  destination: str
49
50
  endpoint: str
50
51
  session: uuid.UUID | None = None
52
+
53
+
54
+ class Resolver(ABC):
55
+ @abstractmethod
56
+ async def resolve(self, destination: str) -> tuple[str | None, list[str]]:
57
+ """
58
+ Resolve the destination to an address and endpoint.
59
+
60
+ Args:
61
+ destination (str): The destination name or address to resolve.
62
+
63
+ Returns:
64
+ tuple[str | None, list[str]]: The address (if available) and resolved endpoints.
65
+ """
66
+ raise NotImplementedError
67
+
68
+ @abstractmethod
69
+ def sync_resolve(self, destination: str) -> list[str]:
70
+ """
71
+ Resolve the destination to a list of endpoints.
72
+
73
+ Args:
74
+ destination (str): The destination name or address to resolve.
75
+
76
+ Returns:
77
+ list[str]: The resolved endpoints.
78
+ """
79
+ raise NotImplementedError
@@ -14,8 +14,8 @@ from uagents_core.helpers import weighted_random_sample
14
14
  from uagents_core.identity import Identity
15
15
  from uagents_core.logger import get_logger
16
16
  from uagents_core.models import Model
17
- from uagents_core.types import DeliveryStatus, MsgStatus
18
- from uagents_core.utils.resolver import lookup_endpoint_for_agent
17
+ from uagents_core.types import DeliveryStatus, MsgStatus, Resolver
18
+ from uagents_core.utils.resolver import AlmanacResolver
19
19
 
20
20
  logger = get_logger("uagents_core.utils.messages")
21
21
 
@@ -89,6 +89,7 @@ def send_message_to_agent(
89
89
  session_id: UUID | None = None,
90
90
  strategy: Literal["first", "random", "all"] = "first",
91
91
  agentverse_config: AgentverseConfig | None = None,
92
+ resolver: Resolver | None = None,
92
93
  ) -> list[MsgStatus]:
93
94
  """
94
95
  Send a message to an agent with default settings.
@@ -103,9 +104,12 @@ def send_message_to_agent(
103
104
  agentverse_config (AgentverseConfig, optional): The configuration for the agentverse.
104
105
  """
105
106
  agentverse_config = agentverse_config or AgentverseConfig()
106
- endpoints = lookup_endpoint_for_agent(
107
- agent_identifier=destination, agentverse_config=agentverse_config
108
- )
107
+
108
+ if not resolver:
109
+ resolver = AlmanacResolver(
110
+ agentverse_config=agentverse_config,
111
+ )
112
+ endpoints = resolver.sync_resolve(destination)
109
113
  if not endpoints:
110
114
  logger.error("No endpoints found for agent", extra={"destination": destination})
111
115
  return []
@@ -14,6 +14,7 @@ from uagents_core.config import (
14
14
  from uagents_core.helpers import weighted_random_sample
15
15
  from uagents_core.identity import parse_identifier
16
16
  from uagents_core.logger import get_logger
17
+ from uagents_core.types import Resolver
17
18
 
18
19
  logger = get_logger("uagents_core.utils.resolver")
19
20
 
@@ -71,3 +72,20 @@ def lookup_endpoint_for_agent(
71
72
  )
72
73
 
73
74
  return []
75
+
76
+
77
+ class AlmanacResolver(Resolver):
78
+ def __init__(self, agentverse_config: AgentverseConfig | None = None):
79
+ self.agentverse_config = agentverse_config or AgentverseConfig()
80
+
81
+ async def resolve(self, destination: str) -> tuple[str | None, list[str]]:
82
+ endpoints = lookup_endpoint_for_agent(
83
+ agent_identifier=destination, agentverse_config=self.agentverse_config
84
+ )
85
+ return None, endpoints
86
+
87
+ def sync_resolve(self, destination: str) -> list[str]:
88
+ endpoints = lookup_endpoint_for_agent(
89
+ agent_identifier=destination, agentverse_config=self.agentverse_config
90
+ )
91
+ return endpoints
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: uagents-core
3
- Version: 0.3.4
3
+ Version: 0.3.5
4
4
  Summary: Core components for agent based systems
5
5
  License: Apache 2.0
6
6
  Author: Ed FitzGerald
@@ -12,12 +12,12 @@ uagents_core/models.py,sha256=fxsFjRochkJUdgPltT1HWgBl-9K-HVQWl8sSMVgeJFY,1066
12
12
  uagents_core/protocol.py,sha256=T9jasOkltne33E16Y7VrqcB2moWVsv-Qh4XLZotyz8g,5428
13
13
  uagents_core/registration.py,sha256=lmDXnsAs2CvpgE1Ik0qja_0RAY7zJruK11_jUrlqlWs,3226
14
14
  uagents_core/storage.py,sha256=VLqMSFXOspzrlbUNvaqS95ht9oJze1c-p4CD6Ul80h4,5150
15
- uagents_core/types.py,sha256=_W3EN1wEIRFxuhhBxyZxQH_dA_3AtoPPReIzrgcTUHc,1167
15
+ uagents_core/types.py,sha256=nPK2ebRL6S-vLZx2AR3OO2RTEb_N2Yno6PqL8KHkeo4,1993
16
16
  uagents_core/utils/__init__.py,sha256=v0MaxDYCTtQlwbblEHCfLtbeTnA2hCmKKJk7mlcE20U,135
17
- uagents_core/utils/messages.py,sha256=5o3ahVaeGwzWMAxDs0fl2pC1duDq2VS_-czoVtZpkOc,5066
17
+ uagents_core/utils/messages.py,sha256=x_99pLzMjKKuWrpSAAS9mtVUAjFEZco64mMmHJdtxEI,5149
18
18
  uagents_core/utils/registration.py,sha256=Lp17tn4knw4qpKx_mZO5gDHD6pGssUhux6SGDhhb7rc,14607
19
- uagents_core/utils/resolver.py,sha256=X18oe-WPU_6pfTc6x_Oa69kZQYCMidkaSeCs68Poaik,2169
19
+ uagents_core/utils/resolver.py,sha256=zcHKkTWxuIHq1kR89RDocruGs3i1S2baQpg4TK4j8QY,2868
20
20
  uagents_core/utils/subscriptions.py,sha256=l29elYqKycgU3s2SN_oh-svfhDkqZce0-EIiv4jjxJw,2450
21
- uagents_core-0.3.4.dist-info/METADATA,sha256=ETB4mlX4APkU5KarF2ivzpT7C9I0xmsfXV_37DYYZrY,1009
22
- uagents_core-0.3.4.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
23
- uagents_core-0.3.4.dist-info/RECORD,,
21
+ uagents_core-0.3.5.dist-info/METADATA,sha256=UbvgotVaLQXTyBJUWwW3dmjs6inQO2J7iPz2ybU2Amw,1009
22
+ uagents_core-0.3.5.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
23
+ uagents_core-0.3.5.dist-info/RECORD,,