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.pyfrom uagents import Agent, Context agent = Agent(name="Hosted", seed="your_seed_phrase", port=8000, endpoint=["http://127.0.0.1:8000/submit"]) 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:
WARNING: [Hosted]: No endpoints provided. Skipping registration: Agent won't be reachable. INFO: [Hosted]: Agent inspector available at https://agentverse.ai/inspect/?uri=http%3A//127.0.0.1%3A8000&address=agent1qv9h2wymp8l4vg2ezeszxkllz6lkmh9uhz7rvfyamy0wslhlaxh65fmemgt INFO: [Hosted]: Starting server on http://0.0.0.0:8000 (Press CTRL+C to quit) INFO: [Hosted]: My count is: 1 INFO: [Hosted]: My global is: 1 INFO: [Hosted]: My count is: 2 INFO: [Hosted]: My global is: 2 INFO: [Hosted]: My count is: 3 INFO: [Hosted]: My global is: 3 INFO: [Hosted]: My count is: 4 INFO: [Hosted]: My global is: 4
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 .