Agents storage
Introduction
This file can be run on any platform supporting Python, with the necessary install permissions. This example shows how to use an Agent's storage through the uAgents Python library.
Please check out the example code in our examples repo (opens in a new tab) to run this locally.
Supporting documentation
The agent
Self hosted
storage.pyfrom uagents import Agent, Context agent = Agent(name="bob") @agent.on_event("startup") async def initialize_storage(ctx: Context): ctx.storage.set("count", 0) @agent.on_interval(period=1.0) async def on_interval(ctx: Context): current_count = ctx.storage.get("count") ctx.logger.info(f"My count is: {current_count}") ctx.storage.set("count", current_count + 1) if __name__ == "__main__": agent.run()