Customizable AI Agent Communication Framework with pluggable message improvement logic
Project description
NANDA Agent Framework
A customizable improvement logic for your agents, and easily get registered into NANDA registry
Features
- Pluggable Message Improvement: Easily customize how your agents improve messages
- Multiple AI Frameworks: Support for LangChain, CrewAI, and custom logic
- Agent-to-Agent Communication: Built-in A2A communication system
- Registry System: Automatic agent discovery and registration
- SSL Support: Production-ready with Let's Encrypt certificates
- Example Agents: Ready-to-use examples for common use cases
Installation
Basic Installation
pip install nanda-agent
Quick Start
1. Set Your API Key (For running your personal hosted agents, need API key and your own domain)
export ANTHROPIC_API_KEY="your-api-key-here"\
export DOMAIN_NAME="your-domain.com"
2. Create Your Own Agent - Development
2.1 Write your improvement logic using the framework you like. Here it is a simple moduule without any llm call.
2.2 In the main(), create your improvement function, initialize NANDA using the improvement function, and start the server with Anthropic key and domain using nanda.start_server_api().
2.3 In the requirements.txt file add nanda-agent along with other requirements
2.4 Move this file into your server(the domain should match to the IP address) and run this python file in background
if langchain_pirate.py is python file name, use the below instructions to run in the background:
nohup python3 langchain_pirate.py > out.log 2>&1 &
#!/usr/bin/env python3
from nanda_agent import NANDA
import os
def create_custom_improvement():
"""Create your custom improvement function"""
def custom_improvement_logic(message_text: str) -> str:
"""Transform messages according to your logic"""
try:
# Your custom transformation logic here
improved_text = message_text.replace("hello", "greetings")
improved_text = improved_text.replace("goodbye", "farewell")
return improved_text
except Exception as e:
print(f"Error in improvement: {e}")
return message_text # Fallback to original
return custom_improvement_logic
def main():
# Create your improvement function
my_improvement = create_custom_improvement()
# Initialize NANDA with your custom logic
nanda = NANDA(my_improvement)
# Start the server
anthropic_key = os.getenv("ANTHROPIC_API_KEY")
domain = os.getenv("DOMAIN_NAME")
nanda.start_server_api(anthropic_key, domain)
if __name__ == "__main__":
main()
Using with LangChain
from nanda_agent import NANDA
from langchain_core.prompts import PromptTemplate
from langchain_core.output_parsers import StrOutputParser
from langchain_anthropic import ChatAnthropic
def create_langchain_improvement():
llm = ChatAnthropic(
api_key=os.getenv("ANTHROPIC_API_KEY"),
model="claude-3-haiku-20240307"
)
prompt = PromptTemplate(
input_variables=["message"],
template="Make this message more professional: {message}"
)
chain = prompt | llm | StrOutputParser()
def langchain_improvement(message_text: str) -> str:
return chain.invoke({"message": message_text})
return langchain_improvement
# Use it
nanda = NANDA(create_langchain_improvement())
# Start the server
anthropic_key = os.getenv("ANTHROPIC_API_KEY")
domain = os.getenv("DOMAIN_NAME")
nanda.start_server_api(anthropic_key, domain)
Using with CrewAI
from nanda_agent import NANDA
from crewai import Agent, Task, Crew
from langchain_anthropic import ChatAnthropic
def create_crewai_improvement():
llm = ChatAnthropic(
api_key=os.getenv("ANTHROPIC_API_KEY"),
model="claude-3-haiku-20240307"
)
improvement_agent = Agent(
role="Message Improver",
goal="Improve message clarity and professionalism",
backstory="You are an expert communicator.",
llm=llm
)
def crewai_improvement(message_text: str) -> str:
task = Task(
description=f"Improve this message: {message_text}",
agent=improvement_agent,
expected_output="An improved version of the message"
)
crew = Crew(agents=[improvement_agent], tasks=[task])
result = crew.kickoff()
return str(result)
return crewai_improvement
# Use it
nanda = NANDA(create_crewai_improvement())
# Start the server
anthropic_key = os.getenv("ANTHROPIC_API_KEY")
domain = os.getenv("DOMAIN_NAME")
nanda.start_server_api(anthropic_key, domain)
Checkout the examples folder for more details
Configuration
Environment Variables
ANTHROPIC_API_KEY: Your Anthropic API key (required)DOMAIN_NAME: Domain name for SSL certificatesAGENT_ID: Custom agent ID (optional, auto-generated if not provided)PORT: Agent bridge port (default: 6000)IMPROVE_MESSAGES: Enable/disable message improvement (default: true)
Production Deployment
For production deployment with SSL:
export ANTHROPIC_API_KEY="your-api-key"
export DOMAIN_NAME="your-domain.com"
nanda-pirate
Detailed steps to be done for the deployment
Assuming your customized improvement logic is in langchain_pirate.py
1. Copy the py and requirements file to a folder of choice in the server
cmd: scp langchain_pirate.py requirements.txt root@66.175.209.173:/opt/test-agents
2. ssh into the server, ensure the latest software is in the system
cmd : ssh root@ 66.175.209.173
sudo apt update && sudo apt install python3 python3-pip python3-venv certbot
3. Download the certificates into the machine for your domain. You should ensure in DNS an A record is mapping this domain chat1.chat39.org to IP address 66.175.209.173
cmd : sudo certbot certonly --standalone -d chat1.chat39.org
4. Create and Activate a virtual env in the folder where files are moved in step 1
cmd : cd /opt/test-agents && python3 -m venv jinoos && source jinoos/bin/activate
5. Install the requirements file
cmd : python -m pip install --upgrade pip && pip3 install -r requirements.txt
6. Ensure the env variables are available either through .env or you can provide export
cmd : export ANTHROPIC_API_KEY=my-anthropic-key && export DOMAIN_NAME=my-domain
7. Run the new improvement logic as a batch process
cmd : nohup python3 langchain_pirate.py > out.log 2>&1 &
8. Open the log file and you could find the agent enrollment link
cmd : cat out.log
9. Take the link and go to browser
The framework will automatically:
- Generate SSL certificates using Let's Encrypt
- Set up proper agent registration
- Configure production-ready logging
API Endpoints
When running with start_server_api(), the following endpoints are available:
GET /api/health- Health checkPOST /api/send- Send message to agentGET /api/agents/list- List registered agentsPOST /api/receive_message- Receive message from agentGET /api/render- Get latest message
Agent Communication
Agents can communicate with each other using the @agent_id syntax:
@agent123 Hello there!
The message will be improved using your custom logic before being sent.
Command Line Tools
# Show help
nanda-agent --help
# List available examples
nanda-agent --list-examples
# Run specific examples
nanda-pirate # Simple pirate agent
nanda-pirate-langchain # LangChain pirate agent
nanda-sarcastic # CrewAI sarcastic agent
Architecture
The NANDA framework consists of:
- AgentBridge: Core communication handler
- Message Improvement System: Pluggable improvement logic
- Registry System: Agent discovery and registration
- A2A Communication: Agent-to-agent messaging
- Flask API: External communication interface
Development
Creating Custom Agents
- Create your improvement function
- Initialize NANDA with your function
- Start the server
- Your agent is ready to communicate!
Examples
The framework includes several example agents:
- Simple Pirate Agent: Basic string replacement
- LangChain Pirate Agent: AI-powered pirate transformation
- CrewAI Sarcastic Agent: Team-based sarcastic responses
License
MIT License - see LICENSE file for details.
Contributing
Contributions are welcome! Please see CONTRIBUTING.md for guidelines.
Support
For issues and questions:
- GitHub Issues: https://github.com/nanda-ai/nanda-agent/issues
- Email: support@nanda.ai
Changelog
v1.0.0
- Initial release
- Basic NANDA framework
- LangChain integration
- CrewAI integration
- Example agents
- Production deployment support
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
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 nanda_agent-1.0.3.tar.gz.
File metadata
- Download URL: nanda_agent-1.0.3.tar.gz
- Upload date:
- Size: 28.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d663cbc786b2b7dc83970bd5bef926ad328818470a6fdd5064c20d06391d7a5f
|
|
| MD5 |
7dcb03b08b5dd30e23b247315931714e
|
|
| BLAKE2b-256 |
ced09e37a005bb75e1b045e88bdc446439c20a605ce047d0802fe491fde9b59b
|
File details
Details for the file nanda_agent-1.0.3-py3-none-any.whl.
File metadata
- Download URL: nanda_agent-1.0.3-py3-none-any.whl
- Upload date:
- Size: 29.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ee7a9ceecc72564b78a5632fa337b0b5f571d751476fe98b89b268c2740fe194
|
|
| MD5 |
298b659fd19f8a0f1ccbaef77a45946c
|
|
| BLAKE2b-256 |
c7ad7bd774544878067d4d624442d38d5d67d281a7de926ae7654e9a67177379
|