Build and understand uAgents
uAgents is a lightweight Python package designed to help you deploy microservices. These microservices can then be utilized by your AI agents as tools for executing tasks and achieving defined objectives.
Prerequisites
- Recommended: Python 3.10–3.13 (tested path for current Innovation Lab tutorials)
- A working Python package manager (
pip) - Current tutorials target
uagents>=0.25.3
Python version notes
- Python 3.10–3.13: Recommended.
pip install "uagents>=0.25.3"installs a modern package that matches this guide (mailbox=True, concurrent message handling, current Almanac/Agentverse flows). - Python 3.8 / 3.9: Legacy only. Plain
pip install uagentsmay resolve older releases (for example 0.10.x / 0.20.x) that do not match the behavior shown here. Do not use these versions for this tutorial. - Python 3.14+: Not yet supported. Install may succeed, but constructing
Agent(...)can fail (missing event loop). - Windows vs WSL: A Windows Python install is not available inside WSL. Use native Windows (PowerShell/CMD) with Windows Python, or install
python3,python3-venv, andpython3-pipinside WSL separately.
Installing uAgents framework
Fetch.ai's uAgents Framework package is a Python library running on Ubuntu/Debian, macOS, and Windows systems.
On your computer, you may need to install:
- Python 3.10–3.13 (recommended)
- PIP - Python package manager.
- uAgents library (
uagents>=0.25.3)
Install with Pip
- Create a directory:
- macOS / Linux
- Windows (PowerShell)
- Windows (CMD)
mkdir my_agents_project
cd my_agents_project
mkdir my_agents_project
cd my_agents_project
mkdir my_agents_project
cd my_agents_project
- Initialize and activate a virtual environment:
- macOS / Linux
- Windows (PowerShell)
- Windows (CMD)
python3 -m venv venv
source venv/bin/activate
If python3 is unavailable, try python -m venv venv instead.
py -3.12 -m venv venv
.\venv\Scripts\Activate.ps1
You can also use python -m venv venv if the python launcher is on your PATH.
py -3.12 -m venv venv
venv\Scripts\activate.bat
You can also use python -m venv venv if the python launcher is on your PATH.
- Install Fetch.ai uagents library:
pip install "uagents>=0.25.3"
Pinning uagents>=0.25.3 ensures mailbox, concurrency, and Agentverse flows match this guide. On Python 3.8/3.9 this pin will fail or resolve incompatibly — use Python 3.10–3.13 instead.
- Verify the installation:
pip show uagents
Confirm the reported version is 0.25.3 or newer.
Create your first uAgent
Once you've installed the uAgents library, it's quite simple to get a minimal use case running.
The uAgent
- Create a Python script:
- macOS / Linux
- Windows (PowerShell)
- Windows (CMD)
touch my_first_agent.py
New-Item -Path my_first_agent.py -ItemType File
type nul > my_first_agent.py
You can also create the file in your editor of choice.
-
Import the necessary classes and instantiate your agent:
from uagents import Agent, Context
# instantiate agent
agent = Agent(
name="alice",
seed="secret_seed_phrase",
port=8000,
endpoint=["http://localhost:8000/submit"],
)
# startup handler
@agent.on_event("startup")
async def startup_function(ctx: Context):
ctx.logger.info(f"Hello, I'm agent {agent.name} and my address is {agent.address}.")
if __name__ == "__main__":
agent.run()-
Agent parameters:
name: Identifies the agent (here, “alice”).seed: Sets a deterministic seed, generating fixed addresses each time.portandendpoint: Configure where the agent will be available.
-
Behavior on startup:
The
@agent.on_event("startup")decorator sets a function that runs as soon as the agent launches. In this sample, the agent logs a message including its name and unique address.
-
Concurrent Message Handling
The uAgents v0.23.6 release introduces optional concurrent message handling for local agents (requires a modern uagents install such as >=0.25.3). When enabled, an agent can process multiple incoming messages at the same time.
Overview
Previously, local agents processed one message at a time:
- Message handlers ran sequentially.
- Long-running tasks (for example image/video generation or heavy computation) blocked other incoming requests.
- This behavior protected shared objects such as
ctx.storageandctx.wallet, which are not thread-safe.
Sequential execution remains the default behavior for safety and consistency.
Why use concurrent message handling?
Enable this feature when:
- Your agent handles long-running or blocking operations.
- You need better responsiveness under multiple independent requests.
- Your logic is mostly stateless, or shared-state access is carefully controlled.
Important safety note
With concurrency enabled, multiple handlers may access shared objects at the same time. This can cause race conditions, inconsistent writes, or incorrect wallet operations.
To reduce risk:
- Avoid concurrent writes to shared storage.
- Avoid overlapping wallet operations.
- Keep shared-state access minimal, predictable, or explicitly serialized.
How to enable concurrency
Pass handle_messages_concurrently=True when creating your agent. Here is the complete my_first_agent.py example with the flag enabled:
from uagents import Agent, Context
# instantiate agent with concurrent message handling
agent = Agent(
name="alice",
seed="secret_seed_phrase",
port=8000,
endpoint=["http://localhost:8000/submit"],
handle_messages_concurrently=True,
)
# startup handler
@agent.on_event("startup")
async def startup_function(ctx: Context):
ctx.logger.info(f"Hello, I'm agent {agent.name} and my address is {agent.address}.")
if __name__ == "__main__":
agent.run()
Once enabled, handlers can run in parallel and the agent can continue handling new requests while long-running tasks are still in progress.
For full guidance and best practices, see the official uAgents guide: Concurrent Message Handling.
Run your agent
With your virtual environment activated, run the script:
- macOS / Linux
- Windows (PowerShell)
- Windows (CMD)
python3 my_first_agent.py
If you created the venv with python, use python my_first_agent.py instead.
python my_first_agent.py
If python is not found, try py my_first_agent.py.
python my_first_agent.py
If python is not found, try py my_first_agent.py.
Sample output
INFO: [alice]: Registration on Almanac API successful
INFO: [alice]: Registering on almanac contract...
INFO: [alice]: Registering on almanac contract...complete
INFO: [alice]: Agent inspector available at https://Agentverse.ai/inspect/?uri=http%3A//127.0.0.1%3A8000&address=agent1q...
INFO: [alice]: Starting server on http://0.0.0.0:8000 (Press CTRL+C to quit)
INFO: [alice]: Hello, I'm agent alice and my address is agent1q...
Ways to create uAgents
There are multiple ways to create and deploy uAgents, each suited to different needs:
- Hosted Agents
- Local Agents
- Mailbox Agents
Understanding these options will help you choose the best setup.
Hosted Agents
You can create and host agents directly on Agentverse:
- Navigate to Agentverse → Agents tab → + Launch an Agent:

Then, click Create an Agent button:

-
Choose Blank Agent or Skeleton Agent.
- From a Blank Agent - You have to code everything.
- From a Skeleton Agent - You will get one data model with one decorator each.
Choose Blank Agent.

- Provide a name for your new Agent.

- After creation, click on the agent and then Build tab to open the embedded code editor.

- Add your Python code (similar to the
my_first_agent.pyexample).

- Click Start to run the agent; logs appear in the terminal below the editor.

Hosted Agents support the full Python built-in library and specific third-party packages (like uagents, requests, openai, etc.). However, some libraries are restricted for security reasons. If you need additional packages, consider using Mailbox Agents.
Supported Libraries on Agentverse:
The Agentverse now provides full Python support! This means that all Hosted Agents will now support the full Python built-in library plus the following packages:
Once you run a hosted agent, you don't have to bother about its uptime. It will be always running. For additional information on Agentverse Imports, head over to this guide.
Local Agents
Local Agents run entirely on your own machine or server, just like the example in my_first_agent.py. These agents:
- Have complete freedom to import any Python library or custom modules.
- Can handle events, messages, and tasks continuously.
- Are registered on the Almanac contract, allowing them to communicate with other local agents.
- Require you to manage uptime, environment dependencies, and scaling if necessary.
Let's set up a local agent.
from uagents import Agent
SEED_PHRASE = "put_your_seed_phrase_here"
# Local agent with a fixed seed and HTTP endpoint
agent = Agent(
name="alice",
port=8000,
seed=SEED_PHRASE,
endpoint=["http://localhost:8000/submit"],
)
# Copy the address shown below
print(f"Your agent's address is: {agent.address}")
if __name__ == "__main__":
agent.run()
Use Case: Ideal for tasks requiring advanced customization, local file access, or extensive machine learning libraries.
Mailbox Agents
When you need to use libraries not allowed by the hosted environment, or you want direct local control while also integrating with Agentverse, you can set up a Mailbox Agent.
A Mailbox Agent runs locally but connects to the Agentverse via a secure channel, enabling interaction with other hosted or local agents. To configure this:
- Let's set up a local agent first like we did in the section here but include
mailbox=True.
mailbox=True requires a modern uagents install (>=0.25.3 on Python 3.10–3.13). Older releases (for example 0.10.x on Python 3.8) ignore a bare mailbox=True flag.
from uagents import Agent
SEED_PHRASE = "put_your_seed_phrase_here"
# Now your agent is ready to join the Agentverse!
agent = Agent(
name="alice",
port=8000,
seed=SEED_PHRASE,
mailbox=True,
)
# Copy the address shown below
print(f"Your agent's address is: {agent.address}")
if __name__ == "__main__":
agent.run()
- Run the Script
You should get something similar within your terminal output:
INFO: [alice]: Starting agent with address: agent1qw8jn3nfl2fyyhe7v4x8pfmsge4hs9zqrqw9eq7h7hluzmd0da8z7j0uacx
INFO: [alice]: Agent inspector available at https://Agentverse.ai/inspect/?uri=http%3A//127.0.0.1%3A8000&address=agent1q0nrj45ah0e53424n9uqc83d9xxs6534jug7j6ka4z6wnrsx7ex2kwx86t4
INFO: [alice]: Starting server on http://0.0.0.0:8000 (Press CTRL+C to quit)
INFO: [alice]: Starting mailbox client for https://Agentverse.ai
INFO: [alice]: Mailbox access token acquired
INFO: [alice]: Registration on Almanac API successful
INFO: [alice]: Registering on almanac contract...
INFO: [alice]: Registering on almanac contract...complete
- If you wish to publish your agent on the Agentverse, you can do so by adding the
publish_agent_details=Trueparameter while defining the agent.
README guidelines
If you publish agent details (publish_agent_details=True), include a README.md to describe what your agent does and how to use it.
Create a README.md file in the same directory as your agent script.
# Now your agent is ready to join the Agentverse!
agent = Agent(
name="alice",
port=8000,
mailbox=True,
publish_agent_details=True,
readme_path="README.md",
)
This will publish the agent details like name on the Agentverse.
Local Network Access Permission (Chrome Update)
Recent Chrome (v142+) and Brave updates introduced a Local Network Access permission prompt. If this permission is not granted, the browser cannot detect locally running agents.
Solution:
When prompted with "Allow this site to access devices on your local network", click Allow. If you missed the prompt, you can manually enable it in: Chrome Settings → Privacy and Security → Site Settings → Additional permissions → Local network access
Reference: Chrome For Developers Blog – Local Network Access Update