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
        • 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
Intermediate topics
Hosted agent
ℹ️

This article is a work-in-progress. It will be expanded rapidly.

Agents running on agentverse

Agents running on Agentverse ↗️ (opens in a new tab) act as Functions ↗️; they do this by having an orchestrator in the background that calls functions on the agent when a routine should execute, or a message is called. This helps us keep hosted agents costs down which are passed on to the user.

However, you should be aware of how state works in a hosted agent. A global variable in agentverse will always have the value of the initialized value you set. Updating this value from a function will not work outside the scope of that function call, as the variable is set when the agent is loaded into the Orchestrator which does not load up the entire agent for each call, a global variable will always have the initial set value. To have values persist you must store this values in storage.

Let's show this with an example:

storage_agent_example.py
from uagents import Agent, Context
 
agent = Agent()
 
global_counter = 0
 
@agent.on_interval(period=1.0)
async def on_interval(ctx: Context):
    global global_counter
 
 
    # increment the global counter - bad!
    global_counter += 1
 
 
    current_count = int(ctx.storage.get("count") or 0)
    current_count += 1
 
    ctx.logger.info(f"My count is: {current_count}")
    ctx.logger.info(f"My global is: {global_counter}")
 
    ctx.storage.set("count", current_count)
 
 
if __name__ == "__main__":
    agent.run()

Output in Agentverse would be:

2024-06-27 09:05:14	Info	Agent	[INFO]: My count is: 1
2024-06-27 09:05:14	Info	Agent	[INFO]: My global is: 1
2024-06-27 09:05:15	Info	Agent	[INFO]: My count is: 2
2024-06-27 09:05:15	Info	Agent	[INFO]: My global is: 1
2024-06-27 09:05:17	Info	Agent	[INFO]: My count is: 3
2024-06-27 09:05:17	Info	Agent	[INFO]: My global is: 1

You can see from this output, global is never updated.

To learn more about Agents storage and how it works in Agentverse, take a look at [Storage Functions ↗️]((/guides/agents/intermediate/storage-function).

Was this page helpful?

Options for running local agentsIntroducing dialogues
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