Skip to content

Commit

Permalink
fix: extract geo-location metadata for registration
Browse files Browse the repository at this point in the history
  • Loading branch information
jrriehl committed Oct 29, 2024
1 parent 55247e7 commit 1391e46
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions python/src/uagents/registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,17 @@ def coerce_metadata_to_str(
return out


def extract_geo_metadata(
metadata: Optional[Dict[str, Any]],
) -> Optional[Dict[str, Any]]:
"""
Extract geo-location metadata from the metadata dictionary.
"""
if metadata is None:
return None
return {k: v for k, v in metadata.items() if k == "geolocation"}


async def almanac_api_post(
url: str, data: BaseModel, raise_from: bool = True, retries: int = 3
) -> bool:
Expand Down Expand Up @@ -166,18 +177,12 @@ async def register(
endpoints: List[AgentEndpoint],
metadata: Optional[Dict[str, Any]] = None,
):
clean_metadata = (
{k: v for k, v in metadata.items() if k == "geolocation"}
if metadata
else None
) # only keep geolocation metadata for registration

# create the attestation
attestation = AgentRegistrationAttestation(
agent_address=agent_address,
protocols=protocols,
endpoints=endpoints,
metadata=coerce_metadata_to_str(clean_metadata),
metadata=coerce_metadata_to_str(extract_geo_metadata(metadata)),
)

# sign the attestation
Expand Down Expand Up @@ -205,7 +210,7 @@ def add_agent(self, agent_info: AgentInfo, identity: Identity):
agent_address=agent_info.agent_address,
protocols=list(agent_info.protocols),
endpoints=agent_info.endpoints,
metadata=coerce_metadata_to_str(agent_info.metadata),
metadata=coerce_metadata_to_str(extract_geo_metadata(agent_info.metadata)),
)
attestation.sign(identity)
self._attestations.append(attestation)
Expand Down Expand Up @@ -357,7 +362,7 @@ def add_agent(self, agent_info: AgentInfo, identity: Identity):
agent_address=agent_info.agent_address,
protocols=agent_info.protocols,
endpoints=agent_info.endpoints,
metadata=agent_info.metadata,
metadata=coerce_metadata_to_str(extract_geo_metadata(agent_info.metadata)),
contract_address=str(self._almanac_contract.address),
sender_address=str(self._wallet.address()),
)
Expand Down

0 comments on commit 1391e46

Please sign in to comment.