Skip to Content

Registering in Almanac Contract

Overview

Agents participating in any system are required to register in the Almanac contract. The Almanac is a smart contract developed and deployed on the Fetch.ai blockchain which provides users with a direct way to query a particular agent’s information, as well as allowing other agents to retrieve information about any specific agents registered within the contract.

Agents registration in the Almanac contract requires agents to register using their Agent Address and pay a fee for registration to be found by other agents on the network.

ℹ️

Check out the Communicating with other agents guide to better understand how Agents make use of the Almanac to accomplish remote communication.

The system employs strict time limitations for registrations, measured in blocks, to ensure the smooth operation of a large ecosystem of agents. This limitation addresses the liveness problem by encouraging agents to periodically re-register their information within the Almanac contract, thus keeping the registration details up to date for each one of them.

Indeed, once an agent’s registration information expires due to the time limit, queries for that agent will no longer return the previously registered information.

ℹ️

This mechanism promotes the accuracy and relevance of the agents information available to others.

During each registration process, agents must prove ownership of their address. This is achieved by signing a sequence number using their agent private key and subsequently submitting the signature to the contract for verification. The sequence number should increment with each successful registration and can also be queried. These steps are automated, ensuring a streamlined registration experience for agents.

By implementing these measures, the system guarantees that:

  • Agents are registered in the Almanac contract.
  • Users can query registered agents information.
  • Registration is up-to-date.
  • Ownership of agents addresses is verified through signature verification.

Agents registration process

Prerequisites

Make sure you have read the following resources before going on with this guide:

Imports needed

Walk-through

  1. First of all, create a Python script and name it:

    windows
    echo. > registration.py
  2. Open your terminal and registration.py file in an editor of your choice. Let’s start by importing the Agent class from the uagents library to create our Agent. This function will check if you have enough tokens to register in the Almanac contract, if not it will add testnet tokens to your ASI Network address. Then, create an agent, alice, you need to provide the name, seed, port and endpoint parameters to correctly run it! The code will look similar to the following:

Self hosted
registration.py
from uagents import Agent, Context, Protocol agent = Agent( name="alice", port=8000, seed="alice secret phrase", endpoint=["http://127.0.0.1:8000/submit"], ) @agent.on_interval(period=3) async def hi(ctx: Context): ctx.logger.info(f"Hello") agent.run()

There’s a few things happening in this script; we initialize Alice with an endpoint. An endpoint is the address in which other agents can send messages to where Alice will be listening. As highlighted in Registration and Endpoints Weighting, agents can communicate by querying the Almanac and retrieving an endpoint from the recipient agent. Therefore, we need to specify the service endpoints when defining our agents.

We also have to define agent.run(). This .run() function runs the agent, but more importantly this registers the agent to the Almanac when code is initialized.

Once you run your script, your agent will start the registration process automatically. Finally, it will try to register on the Almanac contract. Then, we will be ready to start to a remote communication with other agents registered within the Almanac contract. The output should be similar to:

INFO: [Alice]: Registration on Almanac API successful INFO: [Alice]: Registering on almanac contract... INFO: [Alice]: Registering on almanac contract...complete INFO: [Alice]: Hello INFO: [Alice]: Agent inspector available at https://agentverse.ai/inspect/?uri=http%3A//127.0.0.1%3A8000&address=agent1qfccl7xc2hrwzntx9rxgf56lh80kuf5av6h4nyk3ywvxyu846zqwyl3g0jf INFO: [Alice]: Starting server on http://0.0.0.0:8000 (Press CTRL+C to quit) INFO: [Alice]: Hello INFO: [Alice]: Hello INFO: [Alice]: Hello

The output for the above code would be similar to the following:

INFO: [alice]: Registration on Almanac API successful INFO: [alice]: Registering on almanac contract... INFO: [alice]: Registering on almanac contract...complete INFO: [alice]: Agent inspector available at https://agentverse.ai/inspect/?uri=http%3A//127.0.0.1%3A8000&address=agent1q0c5m0ugjml6rwa05fwe8wecqnxjc8vk6grqwlylpp9h4nfzxm4cyaha7r8 INFO: [alice]: Starting server on http://0.0.0.0:8000 (Press CTRL+C to quit) INFO: [alice]: Hello INFO: [alice]: Hello INFO: [alice]: Hello
Last updated on