Adapters for uAgents to integrate with LangChain, CrewAI, and MCP
Project description
uAgents Adapter
This package provides adapters for integrating uAgents with popular AI libraries:
- LangChain Adapter: Convert LangChain agents to uAgents
- CrewAI Adapter: Convert CrewAI crews to uAgents
- MCP Server Adapter: Integrate Model Control Protocol (MCP) servers with uAgents
Installation
# Install the base package
pip install uagents-adapter
# Install with LangChain support
pip install "uagents-adapter[langchain]"
# Install with CrewAI support
pip install "uagents-adapter[crewai]"
# Install with MCP support
pip install "uagents-adapter[mcp]"
# Install with all extras
pip install "uagents-adapter[langchain,crewai,mcp]"
LangChain Adapter
The LangChain adapter allows you to convert any LangChain agent into a uAgent that can interact with other agents in the Agentverse ecosystem.
from langchain_core.agents import AgentExecutor, create_react_agent
from langchain_core.tools import BaseTool
from langchain_openai import ChatOpenAI
from uagents_adapter import LangchainRegisterTool
# Create your LangChain agent
llm = ChatOpenAI(model_name="gpt-4")
tools = [...] # Your tools here
agent = create_react_agent(llm, tools)
agent_executor = AgentExecutor(agent=agent, tools=tools)
# Create uAgent register tool
register_tool = LangchainRegisterTool()
# Register the agent as a uAgent
result = register_tool.invoke({
"agent_obj": agent_executor,
"name": "my_langchain_agent",
"port": 8000,
"description": "My LangChain agent as a uAgent",
"mailbox": True, # Use Agentverse mailbox service
"api_token": "YOUR_AGENTVERSE_API_TOKEN", # Optional: for Agentverse registration
"return_dict": True # Return a dictionary instead of a string
})
print(f"Created uAgent '{result['agent_name']}' with address {result['agent_address']} on port {result['agent_port']}")
CrewAI Adapter
The CrewAI adapter allows you to convert any CrewAI crew into a uAgent.
from crewai import Crew, Agent, Task
from uagents_adapter import CrewaiRegisterTool
# Define your CrewAI crew
agent1 = Agent(
role="Researcher",
goal="Research thoroughly",
backstory="You are a skilled researcher",
verbose=True,
allow_delegation=False
)
task1 = Task(
description="Research about a topic",
agent=agent1
)
crew = Crew(
agents=[agent1],
tasks=[task1],
verbose=True
)
# Create CrewAI register tool
register_tool = CrewaiRegisterTool()
# Register the crew as a uAgent
result = register_tool.invoke({
"crew_obj": crew,
"name": "my_crew_agent",
"port": 8001,
"description": "My CrewAI crew as a uAgent",
"mailbox": True, # Use Agentverse mailbox service
"api_token": "YOUR_AGENTVERSE_API_TOKEN", # Optional: for Agentverse registration
"query_params": {
"topic": {
"type": "string",
"description": "The topic to research",
"required": True
}
},
"example_query": "Research about artificial intelligence",
"return_dict": True # Return a dictionary instead of a string
})
print(f"Created uAgent '{result['agent_name']}' with address {result['agent_address']} on port {result['agent_port']}")
MCP Server Adapter
The MCP Server Adapter allows you to host your MCP Servers on Agentverse and get discovered by ASI:One by enabling Chat Protocol.
First, create a FastMCP server implementation in a server.py file that exposes the required list_tools and call_tool async methods. Then, in the following agent.py, import the MCP server instance and use it with the MCPServerAdapter:
from uagents import Agent
from uagents_adapter import MCPServerAdapter
from server import mcp
# Create an MCP adapter
mcp_adapter = MCPServerAdapter(
mcp_server=mcp,
asi1_api_key="your_asi1_api_key",
model="asi1-mini" # Model options: asi1-mini, asi1-extended, asi1-fast
)
# Create a uAgent
agent = Agent()
# Add the MCP adapter protocols to the agent
for protocol in mcp_adapter.protocols:
agent.include(protocol)
# Run the MCP adapter with the agent
mcp_adapter.run(agent)
Important: When creating MCP tools, always include detailed docstrings using triple quotes (
""") to describe what each tool does, when it should be used, and what parameters it expects. These descriptions are critical for ASI:One to understand when and how to use your tools.
For more detailed instructions and advanced configuration options, see the MCP Server Adapter Documentation.
Agentverse Integration
Mailbox Service
By default, agents are created with mailbox=True, which enables the agent to use the Agentverse mailbox service. This allows agents to communicate with other agents without requiring a publicly accessible endpoint.
When mailbox is enabled:
- Agents can be reached by their agent address (e.g.,
agent1q...) - No port forwarding or public IP is required
- Messages are securely handled through the Agentverse infrastructure
Agentverse Registration
You can optionally register your agent with the Agentverse API, which makes it discoverable and usable by other users in the Agentverse ecosystem:
- Obtain an API token from Agentverse.ai
- Include the token when registering your agent:
result = register_tool.invoke({ # ... other parameters "api_token": "YOUR_AGENTVERSE_API_TOKEN" })
When an agent is registered with Agentverse:
- It connects to the mailbox service automatically
- It appears in the Agentverse directory
- A README with input/output models is automatically generated
- The agent gets an "innovationlab" badge
- Other users can discover and interact with it
- You can monitor its usage and performance through the Agentverse dashboard
Example of auto-generated README for LangChain agents:
# Agent Name
Agent Description

**Input Data Model**
```python
class QueryMessage(Model):
query: str
Output Data Model
class ResponseMessage(Model):
response: str
Example of auto-generated README for CrewAI agents with parameters:
```markdown
# Agent Name
Agent Description

**Input Data Model**
```python
class ParameterMessage(Model):
topic: str
max_results: int | None = None
Output Data Model
class ResponseMessage(Model):
response: str
Example Query
Research about artificial intelligence
## License
Apache 2.0
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file uagents_adapter-0.3.0.tar.gz.
File metadata
- Download URL: uagents_adapter-0.3.0.tar.gz
- Upload date:
- Size: 21.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.3 CPython/3.11.12 Linux/6.11.0-1014-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
552e3e809442101e38465ae0c3de5b08ac7cb36cd25d06f54f39b03ba9a6fce5
|
|
| MD5 |
06779f2a2a2ecadf357b0060aa6c31b7
|
|
| BLAKE2b-256 |
d2fcd65fb4282375006f516f42cda856926301a9a2482b88adadb390b20d5cb8
|
File details
Details for the file uagents_adapter-0.3.0-py3-none-any.whl.
File metadata
- Download URL: uagents_adapter-0.3.0-py3-none-any.whl
- Upload date:
- Size: 28.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.3 CPython/3.11.12 Linux/6.11.0-1014-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f58ed426c7c180d5e2d02734d807865731fa6057e26cf0ca9eac88c6ab97c13e
|
|
| MD5 |
2ca1ac13f00b2010f11a9e04f16f32b3
|
|
| BLAKE2b-256 |
6f2d87d65939037013758c8b66b0d9193a6454e548e893bb01eb70aaa0cf132b
|