Skip to main content

Adapters for uAgents to integrate with LangChain and CrewAI

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

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 all extras
pip install "uagents-adapter[langchain,crewai]"

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']}")

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:

  1. Obtain an API token from Agentverse.ai
  2. 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
![tag:innovationlab](https://img.shields.io/badge/innovationlab-3D8BD3)

**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
![tag:innovationlab](https://img.shields.io/badge/innovationlab-3D8BD3)

**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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

uagents_adapter-0.2.1.tar.gz (15.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

uagents_adapter-0.2.1-py3-none-any.whl (20.3 kB view details)

Uploaded Python 3

File details

Details for the file uagents_adapter-0.2.1.tar.gz.

File metadata

  • Download URL: uagents_adapter-0.2.1.tar.gz
  • Upload date:
  • Size: 15.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.3 CPython/3.11.12 Linux/6.11.0-1013-azure

File hashes

Hashes for uagents_adapter-0.2.1.tar.gz
Algorithm Hash digest
SHA256 40be746bcf7f9b76f1ae844b5c45120f73e5b42fcc9401b52854fdef938ba239
MD5 6af7270a46fccad50bad606e7e55043b
BLAKE2b-256 27ecb734e66357979b3528b59e1f4cd620ab6f17fdf5de39d09393f838ce1439

See more details on using hashes here.

File details

Details for the file uagents_adapter-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: uagents_adapter-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 20.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.3 CPython/3.11.12 Linux/6.11.0-1013-azure

File hashes

Hashes for uagents_adapter-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 9593106d5f6d8605bbed217181fa51e4297c54f5828171bc43c9984d78952bb6
MD5 10dbd6663aa08ec747dfa0ff491e3b0c
BLAKE2b-256 5a531e38ce1e7cb76b07f450ce36bc356872e30e5c16d99afc701ae5703644e0

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page