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
        • Installation
        • Creating a simple agent
        • Message Handling Example
        • Reach out to the Team!
        • 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
AI Agents
Quickstart

Quick Start Guide for uAgents Framework

This quickstart guide quickly let you install the uAgents Framework and get started in few steps!

Installation

System requirements

  • Python 3.8+: A popular programming language.
  • PIP: Python package manager for installing libraries.
  • Poetry (optional): For managing virtual environments and dependencies.

Installation steps

  1. Create a Project Directory. Open your terminal and create a new directory for your project:

    mkdir directory_name
    cd directory_name
  2. Initialize and activate virtual environment. Use Poetry to initialize and activate a virtual environment (optional but recommended):

    poetry init -n && poetry shell
  3. Install uAgents Framework. Use PIP to install the uAgents Framework package.

    pip install uagents
  4. Verify installation. Check if the installation was successful.

    pip show uagents

Troubleshooting

Problem on MacOS/Python 3.11: Installing coincurve (17.0.0) fails.

Solution

Install the necessary tools.

brew install automake autoconf libtool

Creating a simple agent

This example shows how to make an agent perform a task periodically.

Create a new Python script:

touch interval_task.py

Open interval_task.py in your text editor and add the following code:

interval_task.py
from uagents import Agent, Context
 
# Create an agent named Alice
alice = Agent(name="alice", seed="YOUR NEW PHRASE")
 
# Define a periodic task for Alice
@alice.on_interval(period=2.0)
async def say_hello(ctx: Context):
    ctx.logger.info(f'hello, my name is {alice.name}')
 
# Run the agent
if __name__ == "__main__":
    alice.run()

Be sure to update seed with a unique phrase.

Run Script

Run the script to see the output:

python interval-task.py

Expected Output: hello, my name is alice every 2 seconds.

Message Handling Example

This guide will walk you through creating a simple interaction between two agents, Emma and Liam. Emma will send a message to Liam at regular intervals, and Liam will handle and log the received messages.

Create a new Python script:

touch simple_example.py

Open simple_example.py in your text editor and add the following code:

simple_example.py
from uagents import Agent, Bureau, Context, Model
 
# Define the message structure
class Message(Model):
    message: str
 
# Create agents
emma = Agent(name="Emma", seed="emma_seed")
liam = Agent(name="Liam", seed="liam_seed")
 
# Define behavior for Emma
@emma.on_interval(period=3.0)
async def send_message(ctx: Context):
    # Create an instance of the Message class with the desired content
    message_to_liam = Message(message="Hey Liam, how's it going?")
    # Send the message to Liam
    await ctx.send(liam.address, message_to_liam)
 
# Define behavior for handling messages received by Liam
@liam.on_message(model=Message)
async def liam_message_handler(ctx: Context, sender: str, msg: Message):
    ctx.logger.info(f"Received message from {sender}: {msg.message}")
 
# Create a bureau and add agents
bureau = Bureau()
bureau.add(emma)
bureau.add(liam)
 
# Run the bureau
if __name__ == "__main__":
    bureau.run()

Again, be sure to update seed with a unique phrase.

Run Script

Run the script to see the agents communicate:

python simple_example.py

Expected Output:

[ Liam]: Received message from agent1q2aexr7d0e0x6z5r8zs972jyd8uq9429tc2qfgpax96x6ppyjs25keexnuk: Hey Liam, how's it going?

Reach out to the Team!

Cool! You are now ready to start exploring the concepts and resources available to start developing your agents on the Fetch Network! Remember that our Team is available on Telegram ↗️ (opens in a new tab) and Discord ↗️ (opens in a new tab) channels for any additional inquiry.

Was this page helpful?

GuidesWhat's an Agent?
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