Skip to content

Commit

Permalink
refactor(core): separate prefix from address in agent info (#609)
Browse files Browse the repository at this point in the history
  • Loading branch information
jrriehl authored Jan 17, 2025
1 parent 197296f commit 379809f
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 32 deletions.
21 changes: 3 additions & 18 deletions python/docs/api/uagents/mailbox.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,6 @@ Check if the agent is a mailbox agent.

- `bool` - True if the agent is a mailbox agent, False otherwise.

<a id="src.uagents.mailbox.is_proxy_agent"></a>

#### is`_`proxy`_`agent

```python
def is_proxy_agent(endpoints: list[AgentEndpoint],
agentverse: AgentverseConfig) -> bool
```

Check if the agent is a proxy agent.

**Returns**:

- `bool` - True if the agent is a proxy agent, False otherwise.

<a id="src.uagents.mailbox.register_in_agentverse"></a>

#### register`_`in`_`agentverse
Expand All @@ -41,7 +26,6 @@ async def register_in_agentverse(
request: AgentverseConnectRequest,
identity: Identity,
prefix: AddressPrefix,
endpoints: list[AgentEndpoint],
agentverse: AgentverseConfig,
agent_details: Optional[AgentUpdates] = None) -> RegistrationResponse
```
Expand All @@ -52,9 +36,10 @@ Registers agent in Agentverse

- `request` _AgentverseConnectRequest_ - Request object
- `identity` _Identity_ - Agent identity object
- `prefix` _AddressPrefix_ - Agent address prefix - can be "agent" (mainnet) or "test-agent" (testnet)
- `endpoints` _list[AgentEndpoint]_ - Endpoints of the agent
- `prefix` _AddressPrefix_ - Agent address prefix
can be "agent" (mainnet) or "test-agent" (testnet)
- `agentverse` _AgentverseConfig_ - Agentverse configuration
- `agent_details` _Optional[AgentUpdates]_ - Agent details (name, readme, avatar_url)


**Returns**:
Expand Down
3 changes: 2 additions & 1 deletion python/docs/api/uagents/registration.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ if it is different from the supported version.
#### register

```python
async def register(agent_address: str,
async def register(agent_identifier: str,
identity: Identity,
protocols: List[str],
endpoints: List[AgentEndpoint],
metadata: Optional[Dict[str, Any]] = None)
Expand Down
6 changes: 4 additions & 2 deletions python/src/uagents/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,8 @@ async def _handle_error_message(ctx: Context, sender: str, msg: ErrorMessage):
@self.on_rest_get("/agent_info", AgentInfo) # type: ignore
async def _handle_get_info(_ctx: Context):
return AgentInfo(
identifier=self.identifier,
address=self.address,
prefix=TESTNET_PREFIX if self._test else MAINNET_PREFIX,
endpoints=self._endpoints,
protocols=list(self.protocols.keys()),
)
Expand Down Expand Up @@ -672,7 +673,8 @@ def info(self) -> AgentInfo:
AgentInfo: The agent's address, endpoints, protocols, and metadata.
"""
return AgentInfo(
identifier=self.identifier,
address=self.address,
prefix=TESTNET_PREFIX if self._test else MAINNET_PREFIX,
endpoints=self._endpoints,
protocols=list(self.protocols.keys()),
metadata=self.metadata,
Expand Down
5 changes: 1 addition & 4 deletions python/src/uagents/mailbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from uagents.dispatch import dispatcher
from uagents.envelope import Envelope
from uagents.models import Model
from uagents.types import AgentEndpoint
from uagents.types import AddressPrefix, AgentEndpoint
from uagents.utils import get_logger

logger = get_logger("mailbox")
Expand Down Expand Up @@ -46,9 +46,6 @@ class ChallengeProofResponse(Model):
expiry: str


AddressPrefix = Literal["agent", "test-agent"]


class RegistrationRequest(BaseModel):
address: str
prefix: Optional[AddressPrefix] = "test-agent"
Expand Down
2 changes: 1 addition & 1 deletion python/src/uagents/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ async def register_batch(
endpoints=record.endpoints,
signature=record.signature,
sequence=record.timestamp,
address=record.identifier,
address=record.address,
)

denom = self._client.network_config.fee_denomination
Expand Down
10 changes: 5 additions & 5 deletions python/src/uagents/registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ def __init__(

def add_agent(self, agent_info: AgentInfo, identity: Identity):
attestation = AgentRegistrationAttestation(
agent_identifier=agent_info.identifier,
agent_identifier=f"{agent_info.prefix}://{agent_info.address}",
protocols=list(agent_info.protocols),
endpoints=agent_info.endpoints,
metadata=coerce_metadata_to_str(extract_geo_metadata(agent_info.metadata)),
Expand Down Expand Up @@ -362,23 +362,23 @@ def __init__(

def add_agent(self, agent_info: AgentInfo, identity: Identity):
agent_record = AlmanacContractRecord(
identifier=agent_info.identifier,
address=agent_info.address,
prefix=agent_info.prefix,
protocols=agent_info.protocols,
endpoints=agent_info.endpoints,
contract_address=str(self._almanac_contract.address),
sender_address=str(self._wallet.address()),
)
self._records.append(agent_record)
self._identities[agent_info.identifier] = identity
self._identities[agent_info.address] = identity

def _get_balance(self) -> int:
return self._ledger.query_bank_balance(Address(self._wallet.address()))

async def register(self):
self._logger.info("Registering agents on Almanac contract...")
for record in self._records:
_, _, agent_address = parse_identifier(record.identifier)
record.sign(self._identities[agent_address])
record.sign(self._identities[record.address])

if self._get_balance() < REGISTRATION_FEE * len(self._records):
self._logger.warning(
Expand Down
6 changes: 5 additions & 1 deletion python/src/uagents/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,17 @@
RestHandlerMap = Dict[Tuple[RestMethod, str], RestHandler]


AddressPrefix = Literal["agent", "test-agent"]


class AgentEndpoint(BaseModel):
url: str
weight: int


class AgentInfo(BaseModel):
identifier: str
address: str
prefix: AddressPrefix
endpoints: List[AgentEndpoint]
protocols: List[str]
metadata: Optional[Dict[str, Any]] = None
Expand Down

0 comments on commit 379809f

Please sign in to comment.