Skip to content

fix(core): agent registration endpoint mismatch #466

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 19, 2024
Merged
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
6 changes: 3 additions & 3 deletions python/docs/api/uagents/agent.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ An agent that interacts within a communication environment.
- `_resolver` _Resolver_ - The resolver for agent communication.
- `_loop` _asyncio.AbstractEventLoop_ - The asyncio event loop used by the agent.
- `_logger` - The logger instance for logging agent activities.
- `_endpoints` _List[dict]_ - List of endpoints at which the agent is reachable.
- `_endpoints` _List[AgentEndpoint]_ - List of endpoints at which the agent is reachable.
- `_use_mailbox` _bool_ - Indicates if the agent uses a mailbox for communication.
- `_agentverse` _dict_ - Agentverse configuration settings.
- `_mailbox_client` _MailboxClient_ - The client for interacting with the agentverse mailbox.
Expand Down Expand Up @@ -473,14 +473,14 @@ Sign the registration data for Almanac contract.
#### update`_`endpoints

```python
def update_endpoints(endpoints: List[Dict[str, Any]])
def update_endpoints(endpoints: List[AgentEndpoint])
```

Update the list of endpoints.

**Arguments**:

- `endpoints` _List[Dict[str, Any]]_ - List of endpoint dictionaries.
- `endpoints` _List[AgentEndpoint]_ - List of endpoint dictionaries.

<a id="src.uagents.agent.Agent.update_loop"></a>

Expand Down
2 changes: 1 addition & 1 deletion python/docs/api/uagents/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
```python
def parse_endpoint_config(
endpoint: Optional[Union[str, List[str], Dict[str, dict]]]
) -> Optional[List[Dict[str, Any]]]
) -> List[AgentEndpoint]
```

Parse the user-provided endpoint configuration.
Expand Down
2 changes: 1 addition & 1 deletion python/docs/api/uagents/envelope.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Represents an envelope for message communication between agents.
- `target` _str_ - The target's address.
- `session` _UUID4_ - The session UUID that persists for back-and-forth
dialogues between agents.
- `schema_digest` _str_ - The schema digest for the enclosed message (alias for protocol).
- `schema_digest` _str_ - The schema digest for the enclosed message.
- `protocol_digest` _Optional[str]_ - The digest of the protocol associated with the message
(optional).
- `payload` _Optional[str]_ - The encoded message payload of the envelope (optional).
Expand Down
4 changes: 2 additions & 2 deletions python/docs/api/uagents/network.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ Get the expiry height of an agent's registration.
#### get`_`endpoints

```python
def get_endpoints(address: str)
def get_endpoints(address: str) -> List[AgentEndpoint]
```

Get the endpoints associated with an agent's registration.
Expand Down Expand Up @@ -201,7 +201,7 @@ Get the protocols associated with an agent's registration.
```python
async def register(ledger: LedgerClient, wallet: LocalWallet,
agent_address: str, protocols: List[str],
endpoints: List[Dict[str, Any]], signature: str)
endpoints: List[AgentEndpoint], signature: str)
```

Register an agent with the Almanac contract.
Expand Down
17 changes: 9 additions & 8 deletions python/src/uagents/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
REGISTRATION_RETRY_INTERVAL_SECONDS,
REGISTRATION_UPDATE_INTERVAL_SECONDS,
TESTNET_PREFIX,
AgentEndpoint,
parse_agentverse_config,
parse_endpoint_config,
)
Expand Down Expand Up @@ -197,7 +198,7 @@ class Agent(Sink):
_resolver (Resolver): The resolver for agent communication.
_loop (asyncio.AbstractEventLoop): The asyncio event loop used by the agent.
_logger: The logger instance for logging agent activities.
_endpoints (List[dict]): List of endpoints at which the agent is reachable.
_endpoints (List[AgentEndpoint]): List of endpoints at which the agent is reachable.
_use_mailbox (bool): Indicates if the agent uses a mailbox for communication.
_agentverse (dict): Agentverse configuration settings.
_mailbox_client (MailboxClient): The client for interacting with the agentverse mailbox.
Expand Down Expand Up @@ -316,10 +317,10 @@ def __init__(
self._mailbox_client = MailboxClient(self, self._logger)
# if mailbox is provided, override endpoints with mailbox endpoint
self._endpoints = [
{
"url": f"{self.mailbox['http_prefix']}://{self.mailbox['base_url']}/v1/submit",
"weight": 1,
}
AgentEndpoint(
url=f"{self.mailbox['http_prefix']}://{self.mailbox['base_url']}/v1/submit",
weight=1,
),
]
else:
self._mailbox_client = None
Expand Down Expand Up @@ -613,12 +614,12 @@ def sign_registration(self) -> str:
self._almanac_contract.get_sequence(self.address),
)

def update_endpoints(self, endpoints: List[Dict[str, Any]]):
def update_endpoints(self, endpoints: List[AgentEndpoint]):
"""
Update the list of endpoints.

Args:
endpoints (List[Dict[str, Any]]): List of endpoint dictionaries.
endpoints (List[AgentEndpoint]): List of endpoint dictionaries.

"""

Expand Down Expand Up @@ -669,7 +670,7 @@ async def register(self):
"I do not have enough funds to register on Almanac contract"
)
if self._test:
add_testnet_funds(str(self.wallet.address()))
add_testnet_funds(self.wallet.address().data)
self._logger.info(
f"Adding testnet funds to {self.wallet.address()}"
)
Expand Down
5 changes: 4 additions & 1 deletion python/src/uagents/asgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,10 @@ async def serve(self):
self._logger.info(
f"Starting server on http://{HOST}:{self._port} (Press CTRL+C to quit)"
)
await self._server.serve()
try:
await self._server.serve()
except KeyboardInterrupt:
self._logger.info("Shutting down server")

async def __call__(self, scope, receive, send): # pylint: disable=too-many-branches
"""
Expand Down
4 changes: 2 additions & 2 deletions python/src/uagents/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ def get_expiry(self, address: str) -> int:

return (expiry - height) * AVERAGE_BLOCK_INTERVAL

def get_endpoints(self, address: str) -> Optional[List[AgentEndpoint]]:
def get_endpoints(self, address: str) -> List[AgentEndpoint]:
"""
Get the endpoints associated with an agent's registration.

Expand All @@ -204,7 +204,7 @@ def get_endpoints(self, address: str) -> Optional[List[AgentEndpoint]]:
response = self.query(query_msg)

if not response["record"]:
return None
return []

endpoints = []
for endpoint in response.get("record")[0]["record"]["service"]["endpoints"]:
Expand Down
Loading