https://github.com/fetchai/langchain-uagents
This package contains Langchain integration with uAgents
Science Score: 13.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
○CITATION.cff file
-
✓codemeta.json file
Found codemeta.json file -
○.zenodo.json file
-
○DOI references
-
○Academic publication links
-
○Academic email domains
-
○Institutional organization owner
-
○JOSS paper metadata
-
○Scientific vocabulary similarity
Low similarity (10.6%) to scientific vocabulary
Repository
This package contains Langchain integration with uAgents
Basic Info
- Host: GitHub
- Owner: fetchai
- License: mit
- Language: Python
- Default Branch: main
- Size: 52.7 KB
Statistics
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
- Releases: 0
Metadata Files
README.md
🦜️🔗 LangChain UAgents
This package contains the LangChain integration with uAgents, allowing you to convert Langchain agents into uAgents and register them on Agentverse.
Features
- Convert Langchain agents to uAgents
- Automatic port allocation with fallback options
- Register agents on Agentverse
- Support for AI agent message forwarding
- ASI1-agentic accessible agent
- Clean shutdown and resource management
Installation
bash
pip install -U langchain-uagents
Credentials
We also need to set our Agentverse API key. You can get an API key by visiting this site, or follow the steps in the Agentverse documentation.
```python import os from dotenv import load_dotenv
Load environment variables
load_dotenv()
Get API token for Agentverse
APITOKEN = os.getenv("AVAPIKEY", "yourdefaultkeyhere") OPENAIAPIKEY = os.getenv("OPENAIAPIKEY", "yourdefaultopenaikeyhere") ```
UAgentRegisterTool
Here we show how to use the UAgentRegisterTool to convert a Langchain agent into a uAgent and register it on Agentverse.
Instantiation
```python from langchain_uagents import UAgentRegisterTool
tool = UAgentRegisterTool() ```
Basic Usage
The UAgentRegisterTool accepts the following parameters during invocation:
agent_obj(required): The Langchain agent object to convertname(required): Name for the uAgentport(optional, int): Port to run the agent on, defaults to 8000description(optional, str): Description of the agent's functionalityapi_token(required): Agentverse API token for registrationstart_range(optional, int): Start of port range for automatic allocationend_range(optional, int): End of port range for automatic allocation
```python agentinfo = tool.invoke({ "agentobj": agent, "name": "myagent", "port": 8080, "description": "A useful agent for my tasks", "apitoken": API_TOKEN })
Print agent info
print(f"Created uAgent '{agentinfo['name']}' with address {agentinfo['address']} on port {agent_info['port']}") ```
Complete Example
Here's a complete example showing how to create a calculator agent with Langchain and register it as a uAgent:
```python import os import time from dotenv import loaddotenv from langchainopenai import ChatOpenAI from langchain.agents import initializeagent, AgentType, Tool from langchainuagents import UAgentRegisterTool, cleanup_uagent
Load environment variables
load_dotenv()
Get API token for Agentverse
APITOKEN = os.getenv("AVAPIKEY") OPENAIAPIKEY = os.getenv("OPENAIAPI_KEY")
Define a simple calculator tool
def calculator_tool(expression: str) -> str: """Evaluates a basic math expression (e.g., '2 + 2 * 3').""" try: result = eval(expression) return str(result) except Exception as e: return f"Error: {str(e)}"
Create the langchain agent
tools = [ Tool( name="Calculator", func=calculator_tool, description="Useful for evaluating math expressions" ) ]
llm = ChatOpenAI(temperature=0, apikey=OPENAIAPIKEY) agent = initializeagent( tools=tools, llm=llm, agent=AgentType.ZEROSHOTREACT_DESCRIPTION, verbose=True )
Create and register the uAgent
tool = UAgentRegisterTool() agentinfo = tool.invoke({ "agentobj": agent, "name": "calculatoragent", "port": 8080, "description": "A calculator agent for testing", "apitoken": API_TOKEN })
Print agent info
print(f"Created uAgent '{agentinfo['name']}' with address {agentinfo['address']} on port {agent_info['port']}")
Keep the agent running
try: while True: time.sleep(1) except KeyboardInterrupt: print("\nShutting down calculator agent...") cleanupuagent("calculatoragent") print("Calculator agent stopped.") ```
Port Allocation
The tool automatically handles port allocation:
- First tries to use the specified port
- If the port is in use, searches for an available port in the range 8000-9000
- Raises a RuntimeError if no ports are available
You can customize the port range:
python
agent_info = tool.invoke({
"agent_obj": agent,
"name": "my_agent",
"port": 8080, # Preferred port
"start_range": 8000, # Start of port range
"end_range": 9000, # End of port range
"description": "A useful agent",
"api_token": API_TOKEN
})
Cleanup
Always clean up your uAgent when done:
```python from langchainuagents import cleanupuagent
Clean up by agent name
cleanupuagent("myagent") ```
Environment Variables
The tool requires the following environment variables:
AV_API_KEY: Your Agentverse API key for registering agentsOPENAI_API_KEY: Your OpenAI API key for the Langchain agent
You can set these in a .env file or export them in your environment:
bash
export AV_API_KEY="your_agentverse_api_key"
export OPENAI_API_KEY="your_openai_api_key"
Owner
- Name: Fetch.AI
- Login: fetchai
- Kind: organization
- Website: https://fetch.ai
- Twitter: Fetch_ai
- Repositories: 40
- Profile: https://github.com/fetchai
GitHub Events
Total
- Member event: 1
- Push event: 3
- Pull request event: 2
- Create event: 3
Last Year
- Member event: 1
- Push event: 3
- Pull request event: 2
- Create event: 3
Packages
- Total packages: 1
-
Total downloads:
- pypi 145 last-month
- Total dependent packages: 0
- Total dependent repositories: 0
- Total versions: 2
- Total maintainers: 1
pypi.org: langchain-uagents
Bridge Langchain agents with uAgents and register them on Agentverse
- Homepage: https://github.com/fetchai/langchain-uagents
- Documentation: https://github.com/fetchai/langchain-uagents#readme
- License: MIT
-
Latest release: 0.1.1
published about 1 year ago
Rankings
Maintainers (1)
Dependencies
- langchain ^0.3.21
- langchain-core ^0.3.48
- langchain-openai ^0.2.0
- pydantic ^2.10.6
- python >=3.10,<4.0
- python-dotenv ^1.0.0
- requests ^2.32.3
- uagents ^0.22.0
- langchain-tests 0.3.16 test
- pytest ^8.3.5 test
- pytest-asyncio ^0.26.0 test
- pytest-socket ^0.7.0 test