fetch-logo
ConceptsConceptsGuidesGuidesExamplesExamplesReferencesReferencesAPIsAPIs
GitHub (opens in a new tab)
  • Guides
      • Quickstart
        • What's an Agent?
        • uAgents Framework installation
        • Create your first agent
        • Agents address
        • Communicating with other agents
        • Agent Handlers (on_...)
        • Agents storage functions
        • Public and private Agents
        • Send tokens with Agents
        • Agents Mailboxes
        • Agent Functions
        • Make agents AI Engine compatible
        • Multi-file agent pipeline for AI Engine: Hugging face API to create a multi agent pipeline
        • Options for running local agents
        • Hosted agent
        • Introducing dialogues
        • Almanac Contract
        • Verify messages with Agents
        • Multi-file agent pipeline for AI Engine: Network of Primary and Secondary functions in Agentverse
        • Localwallet
        • Agentverse: Hosted Agents
        • Agentverse: Dice Roll agent
        • Agentverse: Allowed Imports
        • Agentverse: Mailbox
        • Register Agentverse Functions
        • Agentverse Functions: coin toss agent
        • Field descriptions for DeltaV
        • Agentverse Command Line Interface (AVCTL)
        • AVCTL Hosting commands
      • Agents and Functions creation APIs
      • Secret Management APIs
      • How to convert native FET to and from ERC-20 FET
      • How to stake FET tokens
      • Different ways of staking FET
      • Re-delegating staked FET token
      • Reconciliation service
      • How to setup a Multisig Wallet
        • Getting started
        • How to use the Fetch wallet
        • How to stake and claim rewards
        • Address book
        • Connections
        • Fetch Wallet Hardware Connection Guide
        • Installation
        • Connecting to a blockchain
        • Querying balances
        • Wallets and private keys
        • Sending funds
        • Staking
        • Smart contracts
          • Stake auto-compounder
          • Stake optimizer
          • Oracles
          • Wallet top-up
          • Liquidity pool
          • Swap automation
        • Installation️
        • Getting started
        • Keys
          • How to add profiles
          • How to add contract templates
          • How to compile contracts
          • How to deploy contracts
          • Contract interaction
        • Installation
        • How to use chain state snapshots
        • State-synchronization (state-sync)
        • How to set up a validator node
        • How to join a testnet
        • How to run a single node test network
        • Governance
        • How to get testnet tokens via the Token Faucet
          • CLI - Introduction
          • CLI - Managing keys
          • CLI - Managing tokens
          • CLI - Multisig keys
          • CLI - Delegation
          • Governance proposals
      • Agents 101
      • Agents 101 for AI Engine
  • Guides
      • Quickstart
        • What's an Agent?
        • uAgents Framework installation
        • Create your first agent
        • Agents address
        • Communicating with other agents
        • Agent Handlers (on_...)
        • Agents storage functions
        • Public and private Agents
        • Send tokens with Agents
        • Agents Mailboxes
        • Agent Functions
        • Make agents AI Engine compatible
        • Multi-file agent pipeline for AI Engine: Hugging face API to create a multi agent pipeline
        • Options for running local agents
        • Hosted agent
        • Introducing dialogues
        • Almanac Contract
        • Verify messages with Agents
        • Multi-file agent pipeline for AI Engine: Network of Primary and Secondary functions in Agentverse
        • Localwallet
        • Agentverse: Hosted Agents
        • Agentverse: Dice Roll agent
        • Agentverse: Allowed Imports
        • Agentverse: Mailbox
        • Register Agentverse Functions
        • Agentverse Functions: coin toss agent
          • Introduction
          • Create your coin toss agent!
          • Run your coin toss agent!
          • Register your coin toss agent function!
          • Let's find our service on DeltaV
        • Field descriptions for DeltaV
        • Agentverse Command Line Interface (AVCTL)
        • AVCTL Hosting commands
      • Agents and Functions creation APIs
      • Secret Management APIs
      • How to convert native FET to and from ERC-20 FET
      • How to stake FET tokens
      • Different ways of staking FET
      • Re-delegating staked FET token
      • Reconciliation service
      • How to setup a Multisig Wallet
        • Getting started
        • How to use the Fetch wallet
        • How to stake and claim rewards
        • Address book
        • Connections
        • Fetch Wallet Hardware Connection Guide
        • Installation
        • Connecting to a blockchain
        • Querying balances
        • Wallets and private keys
        • Sending funds
        • Staking
        • Smart contracts
          • Stake auto-compounder
          • Stake optimizer
          • Oracles
          • Wallet top-up
          • Liquidity pool
          • Swap automation
        • Installation️
        • Getting started
        • Keys
          • How to add profiles
          • How to add contract templates
          • How to compile contracts
          • How to deploy contracts
          • Contract interaction
        • Installation
        • How to use chain state snapshots
        • State-synchronization (state-sync)
        • How to set up a validator node
        • How to join a testnet
        • How to run a single node test network
        • Governance
        • How to get testnet tokens via the Token Faucet
          • CLI - Introduction
          • CLI - Managing keys
          • CLI - Managing tokens
          • CLI - Multisig keys
          • CLI - Delegation
          • Governance proposals
      • Agents 101
      • Agents 101 for AI Engine
Guides
Agentverse
Agentverse: Agent Functions
Agentverse Functions: coin toss agent

Agentverse Functions: register a coin toss agent as a Function

Introduction

In the Agentverse Functions: register your Functions on the Agentverse! ↗️ guide, you have gotten familiar with the creation of an agent that can be registered as a Function and then be used in DeltaV ↗️.

ℹ️

Checkout the Functions ↗️ guide for additional information needed for Agent Functions and their registration on the Agentverse and Fetch network.

Create your coin toss agent!

For this navigate to the Agentverse: My Agents ↗️ (opens in a new tab) tab and click on the + New Agent button:

When the dialog is open, select the Toss a Coin use case:

A new agent will be created for you:

Run your coin toss agent!

After clicking on the row of your newly created agent, you should be able to see the source code of your coin toss agent in the editor view:

agent.py
# Here we demonstrate how we can create a simple coin toss agent that is compatible with DeltaV.
 
# After running this agent, it can be registered to DeltaV on Agentverse My Agents tab. For registration you will have to use the agent's address.
 
import random
# third party modules used in this example
from pydantic import Field
from ai_engine import UAgentResponse, UAgentResponseType
 
 
class CoinToss(Model):
    choice: str = Field(description="The choice. Must be heads or tails.")
 
coin_toss_protocol = Protocol("CoinToss")
 
 
@coin_toss_protocol.on_message(model=CoinToss, replies={UAgentResponse})
async def toss_coin(ctx: Context, sender: str, msg: CoinToss):
    random_number = random.randint(0, 1)
    if random_number == 0:
        coin_tossed = "heads"
    else:
        coin_tossed = "tails"
    if coin_tossed == msg.choice:
        message = "You won!"
    else:
        message = "You lost!"
    await ctx.send(
        sender, UAgentResponse(message=message, type=UAgentResponseType.FINAL)
)
 
agent.include(coin_toss_protocol, publish_manifest=True)

Now click on the Run button in the upper right corner of the editor so that you have your coin toss agent up and running!

Register your coin toss agent function!

Similar to the this guide ↗️, let's navigate to the Agentverse: My Agents ↗️ (opens in a new tab) tab. Here, click on your agent to show the Agent Editor and then click on the Deploy tab to start registering your agent function.

After clicking the + New Function button, you will need to provide all details required. Fill the form out as follows:

  • Fucntion title: just the name of your Agent Function. In this example let's call it Coin toss function
  • Description: Super important to be as detailed as you can, as reasoning engine looks at descriptions to understand what your Function does. In this example we can specify something like this: Coin toss Function. Takes the "heads" or "tails" input from the user and based on it decides if the user won or lost.
  • Application, Protocol, Model and Field descriptions will be automatically populated based on the source code of your coin toss agent ↗️

Let's find our service on DeltaV

Now, head to DeltaV ↗️ (opens in a new tab) and sign in.

First, in the What function would you like to assemble? bar you can provide a predefined objective; let's type Toss a coin.

After being redirected to the chat screen, you will be asked to select an option. As your objective task (Toss a coin) specified on the previous screen contained words related to the description of your coin toss agent ↗️, your Coin Toss Function is listed as an option.

Let's select it.

After selecting the task, you will be asked if you want to pick heads or tails. The AI Engine ↗️ behind DeltaV asks this question based on the description. The choice must be heads or tails.

Select whichever option you feel like. In this case let's pick heads.

Then, you can confirm or reject the context that the AI Engine is planning to execute. Let's confirm it!

After your function has been executed you can see the You won! or You lost! message.

With that, you have gotten a Coin Toss Function which can be discovered and contacted with DeltaV. Awesome!

Was this page helpful?

Register Agentverse FunctionsField descriptions for DeltaV
footer-logo

Main website

Integrations

Events

We’re hiring!

Twitter (opens in a new tab)Telegram (opens in a new tab)Discord (opens in a new tab)GitHub (opens in a new tab)Youtube (opens in a new tab)LinkedIn (opens in a new tab)Reddit (opens in a new tab)
Sign up for developer updates