Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[agent]
address = ""
address = "agent1qwsjpp5gq9k79pvvd459jdgtkdudga0z0padwldf3m3htqq9ecn8knkrp90"
include = ""
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[agent]
address = ""
address = "agent1qgy3fthchdfgvcmtl0dzr78xvde6aattgsvmpcf2vljgs4pn7ye7gk8r756"
include = ""
20 changes: 10 additions & 10 deletions 6-deployed-agents/geo/google-maps-places-agent/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ Use a Geocode agent first, to convert an address into coordinates.

```python
POIAreaRequest(
loc_search = Coordinates(latitude=48.140505822096365, longitude=11.559987118245475),
latitude=48.140505822096365,
longitude=11.559987118245475,
radius_in_m = 500,
limit = 10,
query_string = "coffee shop",
Expand Down Expand Up @@ -57,13 +58,9 @@ from typing import Any, Dict, List, Optional
from uagents import Model


class Coordinates(Model):
class POIAreaRequest(Model):
latitude: float
longitude: float


class POIAreaRequest(Model):
loc_search: Coordinates
radius_in_m: int
limit: int = 20
query_string: str
Expand All @@ -73,10 +70,11 @@ class POIAreaRequest(Model):
class POI(Model):
placekey: str
location_name: str
brands: Optional[List[str]] = None
brands: Optional[list[str]] = None
top_category: Optional[str] = None
sub_category: Optional[str] = None
location: Coordinates
latitude: float
longitude: float
address: str
city: str
region: Optional[str] = None
Expand All @@ -86,7 +84,8 @@ class POI(Model):


class POIResponse(Model):
loc_search: Coordinates
latitude: float
longitude: float
radius_in_m: int
data_origin: str
data: List[POI]
Expand All @@ -99,7 +98,8 @@ agent = Agent()
GMAPS_AGENT_ADDRESS = "<deployed_agent_address>"

example_request = POIAreaRequest(
loc_search=Coordinates(latitude=48.140505822096365, longitude=11.559987118245475),
latitude=48.140505822096365,
longitude=11.559987118245475,
radius_in_m=500,
query_string="coffee shop",
)
Expand Down
7 changes: 4 additions & 3 deletions 6-deployed-agents/geo/google-maps-places-agent/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ async def handle_poi_request(ctx: Context, sender: str, msg: POIAreaRequest):
client=gmaps,
ctx=ctx,
query_string=msg.query_string,
lat=msg.loc_search.latitude,
lng=msg.loc_search.longitude,
lat=msg.latitude,
lng=msg.longitude,
radius_in_m=msg.radius_in_m,
limit=msg.limit,
)
Expand All @@ -55,7 +55,8 @@ async def handle_poi_request(ctx: Context, sender: str, msg: POIAreaRequest):
await ctx.send(
sender,
POIResponse(
loc_search=msg.loc_search,
latitude=msg.latitude,
longitude=msg.longitude,
radius_in_m=msg.radius_in_m,
data_origin="Google Places API",
data=response,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,9 @@
from uagents import Model


class Coordinates(Model):
class POIAreaRequest(Model):
latitude: float
longitude: float


class POIAreaRequest(Model):
loc_search: Coordinates
radius_in_m: int
limit: int = 20
query_string: str
Expand All @@ -22,7 +18,8 @@ class POI(Model):
brands: Optional[list[str]] = None
top_category: Optional[str] = None
sub_category: Optional[str] = None
location: Coordinates
latitude: float
longitude: float
address: str
city: str
region: Optional[str] = None
Expand All @@ -32,7 +29,8 @@ class POI(Model):


class POIResponse(Model):
loc_search: Coordinates
latitude: float
longitude: float
radius_in_m: int
data_origin: str
data: List[POI]
10 changes: 4 additions & 6 deletions 6-deployed-agents/geo/google-maps-places-agent/logic.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import time

from client import Client
from communication import POI, Coordinates
from communication import POI
from uagents import Context


Expand Down Expand Up @@ -41,7 +41,7 @@ async def find_pois(
# wait a bit to not trigger the API rate limit (https://github.com/googlemaps/google-maps-services-python/issues/366)
time.sleep(2)
except Exception as e:
ctx.logger.error(e)
ctx.logger.error(str(e))
break

if pois:
Expand All @@ -65,10 +65,8 @@ async def find_pois(
POI(
placekey=p["place_id"] or "",
location_name=p["name"] or "",
location=Coordinates(
latitude=p["geometry"]["location"]["lat"],
longitude=p["geometry"]["location"]["lng"],
),
latitude=p["geometry"]["location"]["lat"],
longitude=p["geometry"]["location"]["lng"],
address=p["formatted_address"] or "",
city=addr["administrative_area_level_2"]
if "administrative_area_level_2" in addr
Expand Down
60 changes: 22 additions & 38 deletions 6-deployed-agents/geo/open-charge-map-agent/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from enum import Enum

from api_adapter import OCMAPI, Unit
from models import POI, Coordinates, POIAreaRequest, POIResponse
from models import POI, POIAreaRequest, POIResponse
from uagents import Agent, Context, Model
from uagents.experimental.chat_agent import ChatAgent
from uagents.experimental.quota import QuotaProtocol, RateLimit
Expand Down Expand Up @@ -72,42 +72,28 @@ def get_charger_info(
pois.append(
POI(
placekey=charger["UUID"] or "",
location_name=charger["AddressInfo"]["Title"]
if charger["AddressInfo"]
else "",
brands=[charger["OperatorInfo"]["Title"]]
if charger["OperatorInfo"]
else [],
location_name=charger["AddressInfo"]["Title"] if charger.get("AddressInfo") else "",
brands=[charger["OperatorInfo"]["Title"]] if charger.get("OperatorInfo") else [],
top_category="Automotive Services",
sub_category="Charging Station",
# naics_code=336320, # check https://www.naics.com/search/
location=Coordinates(
latitude=charger["AddressInfo"]["Latitude"],
longitude=charger["AddressInfo"]["Longitude"],
latitude=charger["AddressInfo"]["Latitude"] if charger.get("AddressInfo") else 0.0,
longitude=charger["AddressInfo"]["Longitude"] if charger.get("AddressInfo") else 0.0,
address=charger["AddressInfo"]["AddressLine1"] if charger.get("AddressInfo") else "",
city=charger["AddressInfo"]["Town"] if charger.get("AddressInfo") else "",
region=charger["AddressInfo"]["StateOrProvince"] if charger.get("AddressInfo") else "",
postal_code=charger["AddressInfo"]["Postcode"] if charger.get("AddressInfo") else "",
iso_country_code=(
charger["AddressInfo"]["Country"]["ISOCode"]
if charger.get("AddressInfo") and charger["AddressInfo"].get("Country")
else ""
),
address=charger["AddressInfo"]["AddressLine1"]
if charger["AddressInfo"]
else "",
city=charger["AddressInfo"]["Town"]
if charger["AddressInfo"]
else "",
region=charger["AddressInfo"]["StateOrProvince"]
if charger["AddressInfo"]
else "",
postal_code=charger["AddressInfo"]["Postcode"]
if charger["AddressInfo"]
else "",
iso_country_code=charger["AddressInfo"]["Country"]["ISOCode"]
if charger["AddressInfo"]
else "",
metadata={ # add more metadata if necessary
"UsageCost": charger["UsageCost"] or "",
"status": charger["StatusType"]["Title"]
if charger["StatusType"]
else "",
metadata={
"UsageCost": charger.get("UsageCost") or "",
"status": charger["StatusType"]["Title"] if charger.get("StatusType") else "",
},
)
)

return pois


Expand All @@ -118,8 +104,8 @@ async def handle_request(ctx: Context, sender: str, msg: POIAreaRequest):

try:
pois = get_charger_info(
latitude=msg.loc_search.latitude,
longitude=msg.loc_search.longitude,
latitude=msg.latitude,
longitude=msg.longitude,
radius=msg.radius_in_m / 1000,
limit=msg.limit,
)
Expand All @@ -140,12 +126,10 @@ async def handle_request(ctx: Context, sender: str, msg: POIAreaRequest):
await ctx.send(
sender,
POIResponse(
loc_search=Coordinates(
latitude=msg.loc_search.latitude,
longitude=msg.loc_search.longitude,
),
latitude=msg.latitude,
longitude=msg.longitude,
radius_in_m=msg.radius_in_m,
data_origin=agent.name,
data_origin="",
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: The data_origin field in POIResponse is hardcoded to an empty string, removing data source information. It should be set dynamically using agent.name.
Severity: MEDIUM

Suggested Fix

In agent.py, change the POIResponse instantiation to set data_origin to agent.name instead of an empty string. This will restore the data provenance information.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.

Location: 6-deployed-agents/geo/open-charge-map-agent/agent.py#L132

Potential issue: When constructing a `POIResponse`, the `data_origin` field is hardcoded
to an empty string (`""`). The previous version of the code set this field dynamically
using `agent.name`. This change removes crucial data provenance information, making it
impossible for consumers of this data to identify its source. The `ChatAgent` is
initialized with a `name` parameter, suggesting the `agent.name` attribute is still
available and should be used.

Did we get this right? 👍 / 👎 to inform future reviews.

data=pois,
),
)
Expand Down
14 changes: 6 additions & 8 deletions 6-deployed-agents/geo/open-charge-map-agent/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,13 @@
from uagents import Model


class Coordinates(Model):
class POIAreaRequest(Model):
latitude: float
longitude: float


class POIAreaRequest(Model):
loc_search: Coordinates
radius_in_m: int
limit: int = 20
query_string: str
filter: Dict[str, Any] = {}
filter: Dict[str, Any] = Field(default_factory=dict)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: The POIAreaRequest model uses Field without importing it from uagents, which will cause a NameError when the module is loaded.
Severity: CRITICAL

Suggested Fix

Add Field to the import statement from uagents at the top of the file 6-deployed-agents/geo/open-charge-map-agent/models.py. The import should be from uagents import Field, Model.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.

Location: 6-deployed-agents/geo/open-charge-map-agent/models.py#L12

Potential issue: The `POIAreaRequest` model in `models.py` uses
`Field(default_factory=dict)` to define the `filter` attribute. However, `Field` is not
imported from `uagents` or any other library. Since class definitions are executed when
a module is loaded, this will cause an immediate `NameError: name 'Field' is not
defined` as soon as the Python interpreter attempts to parse the class, preventing the
agent module from loading entirely.

Did we get this right? 👍 / 👎 to inform future reviews.



class POI(Model):
Expand All @@ -22,7 +18,8 @@ class POI(Model):
brands: Optional[List[str]] = None
top_category: Optional[str] = None
sub_category: Optional[str] = None
location: Coordinates
latitude: float
longitude: float
address: str
city: str
region: Optional[str] = None
Expand All @@ -32,7 +29,8 @@ class POI(Model):


class POIResponse(Model):
loc_search: Coordinates
latitude: float
longitude: float
radius_in_m: int
data_origin: str
data: List[POI]

This file was deleted.

This file was deleted.

This file was deleted.

Loading