Skip to main content
Version: 1.0.3

uAgents Adapters: Connecting AI Framework Ecosystems

uAgents Adapters provide a bridge between the uAgents ecosystem and various agentic frameworks, enabling seamless communication between different AI agent architectures.

Why Use Adapters?​

AI development landscapes often involve multiple frameworks and technologies, each with their own strengths:

  • LangChain: Powerful for composing LLMs with tools and chains
  • LangGraph: Excellent for complex orchestration and stateful workflows
  • CrewAI: Specialized for multi-agent collaborative systems

The uAgents Adapter package allows you to leverage these specialized frameworks while still benefiting from the uAgents ecosystem for communication, discovery, and deployment.

Available Adapters​

The uAgents Adapter package currently supports several major AI frameworks:

1. LangChain Adapter​

Connect LangChain agents, chains, and tools to the uAgents ecosystem.

from uagents_adapter import LangchainRegisterTool

# Register a LangChain agent as a uAgent
tool = LangchainRegisterTool()
agent_info = tool.invoke({
"agent_obj": langchain_agent,
"name": "my_langchain_agent",
"port": 8000,
"description": "A LangChain agent powered by GPT-4",
"api_token": AGENTVERSE_API_KEY
})

2. LangGraph Adapter​

Integrate LangGraph's powerful orchestration with uAgents.

from uagents_adapter import LangchainRegisterTool

# Wrap LangGraph agent function for uAgent integration
def langgraph_agent_func(query):
# Process with LangGraph
result = langgraph_app.invoke(query)
return result

# Register the LangGraph function as a uAgent
tool = LangchainRegisterTool()
agent_info = tool.invoke({
"agent_obj": langgraph_agent_func,
"name": "my_langgraph_agent",
"port": 8080,
"description": "A LangGraph orchestration agent",
"api_token": AGENTVERSE_API_KEY
})

3. CrewAI Adapter​

Expose CrewAI's collaborative agent teams as uAgents.

from uagents_adapter import CrewaiRegisterTool

# Create a function to handle CrewAI operations
def crew_handler(query):
# Process with CrewAI
result = my_crew.kickoff(inputs={"query": query})
return result

# Register the CrewAI function as a uAgent
tool = CrewaiRegisterTool()
agent_info = tool.invoke({
"agent_obj": crew_handler,
"name": "my_crew_agent",
"port": 8081,
"description": "A CrewAI team of specialized agents",
"api_token": AGENTVERSE_API_KEY
})

Common Parameters​

All adapters accept the following parameters:

ParameterTypeDescription
agent_objobjectThe framework-specific agent or function to wrap
namestringName for your agent in the uAgents ecosystem
portintPort for the agent's HTTP server
descriptionstringHuman-readable description of agent capabilities
api_tokenstringYour Agentverse API key for registration
mailboxboolWhether to use Agentverse mailbox for persistence (optional)
ai_agent_addressstringAI Agent address to conver Natural language into structured query prompt (optional)

Communication Protocol​

Once registered, adapter agents communicate using the uAgents chat protocol:

from uagents_core.contrib.protocols.chat import (
ChatMessage, TextContent
)

# Send a message to an adapter-wrapped agent
message = ChatMessage(
timestamp=datetime.utcnow(),
msg_id=uuid4(),
content=[TextContent(type="text", text="Your query here")]
)
await ctx.send(adapter_agent_address, message)

Cleanup and Management​

Always clean up your agents when shutting down to ensure proper deregistration:

from uagents_adapter import cleanup_uagent

try:
# Your agent code here
while True:
time.sleep(1)
except KeyboardInterrupt:
# Clean up the agent
cleanup_uagent("your_agent_name")
print("Agent stopped.")

Next Steps​

To explore concrete examples of adapter usage, refer to the uAgents Adapter Examples section.