diff --git a/.gitignore b/.gitignore index 30ab9e7..801e516 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,32 @@ conversation_logs/ agents/test.py nanda_agent/__pycache__ +# Virtual environments +venv/ +env/ +.venv/ +.env/ + # Build artifacts dist/ -*.egg-info/ \ No newline at end of file +*.egg-info/ + +# Python cache files +__pycache__/ +*.pyc +*.pyo +*.pyd + +# IDE files +.vscode/ +.idea/ +*.swp +*.swo + +# OS files +.DS_Store +Thumbs.db + +# Log files +*.log +out.log \ No newline at end of file diff --git a/README-Phala-Cloud.md b/README-Phala-Cloud.md new file mode 100644 index 0000000..ab3cce9 --- /dev/null +++ b/README-Phala-Cloud.md @@ -0,0 +1,80 @@ +# Deploy NANDA Agent on Phala Cloud + +Deploy your NANDA agent in a secure, trusted execution environment using Phala Cloud's TEE infrastructure. + +## Why Phala Cloud + +**Trusted Execution Environment (TEE)** provides hardware-level security for AI agents: + +- **Privacy Protection**: Agent computations run in isolated, encrypted environments +- **Verifiable Trust**: Cryptographic proof that your agent code hasn't been tampered with +- **Autonomous Security**: Agents can handle sensitive data without exposing it to cloud providers +- **Attestation**: Users can verify the integrity of your agent before interacting with it + +TEE is crucial for autonomous AI agents because it ensures trustworthy AI operations while preserving user privacy - essential for building the decentralized agent ecosystem. + +## Deployment Steps + +### 1. Build Your Agent + +```bash +cd nanda_agent +./build.sh docker_user_name/nanda-test:latest +``` + +This creates a Docker image with your agent and all dependencies. + +### 2. Deploy to Phala Cloud + +Create a Confidential VM using the [provided configuration](./nanda_agent/examples/docker-compose-phala.yml): + +```yaml +services: + nanda-pirate: + image: h4x3rotab/nanda-demo:latest # change to yours + ports: + - "5000:5000" + - "6000:6000" + environment: + - ANTHROPIC_API_KEY=${ANTHROPIC_API_KEY:-your-api-key-here} + - DOMAIN_NAME=${DSTACK_APP_ID}-5000.${DSTACK_GATEWAY_DOMAIN} + - API_URL=https://${DSTACK_APP_ID}-5000.${DSTACK_GATEWAY_DOMAIN} + - PUBLIC_URL=https://${DSTACK_APP_ID}-6000.${DSTACK_GATEWAY_DOMAIN} + - PORT=6000 + - API_PORT=5000 + - TERMINAL_PORT=6010 + - IMPROVE_MESSAGES=true + - UI_MODE=true + - SSL=false + restart: unless-stopped + container_name: nanda-pirate-agent + volumes: + - nanda-logs:/app/conversation_logs + +volumes: + nanda-logs: +``` + +The CVM will: +- Run your agent in a secure TEE +- Provide end-to-end secure networking and encrypted storage + +### 3. Register Your Agent + +1. **Find the enrollment link** in the logs +2. **Register on NANDA Chat** using the enrollment link + +Your agent is now running in a trusted environment and accessible through the NANDA network. + +## Environment Variables + +Set the environment variables in encrypted secrets when creating the CVM: + +```bash +ANTHROPIC_API_KEY=your-api-key +``` + +## Resources + +- [Phala Network Documentation](https://docs.phala.network/) +- [Phala Cloud Console](https://cloud.phala.network/) diff --git a/README.md b/README.md index 81f2ed1..2762b71 100644 --- a/README.md +++ b/README.md @@ -236,6 +236,9 @@ The framework will automatically: - Set up proper agent registration - Configure production-ready logging +## Deploy Autonomous Agents in TEE + +[Phala Cloud](https://cloud.phala.network) allows you to build fully autonomous and privacy preserving AI Agents with verifiable cryptogrphic proofs using TEE (Trusted Execution Environment). Learn more at [Phala Cloud Deployment README](./README-Phala-Cloud.md). ## Appendix: Configuration Details diff --git a/nanda_agent/examples/.dockerignore b/nanda_agent/examples/.dockerignore new file mode 100644 index 0000000..7a3066f --- /dev/null +++ b/nanda_agent/examples/.dockerignore @@ -0,0 +1,21 @@ +venv/ +env/ +.venv/ +.env/ +__pycache__/ +*.pyc +*.pyo +*.pyd +.git/ +.gitignore +*.log +out.log +pirate_agent*.log +conversation_logs/ +.DS_Store +Thumbs.db +.vscode/ +.idea/ +*.swp +*.swo +README.md \ No newline at end of file diff --git a/nanda_agent/examples/Dockerfile b/nanda_agent/examples/Dockerfile new file mode 100644 index 0000000..e233163 --- /dev/null +++ b/nanda_agent/examples/Dockerfile @@ -0,0 +1,35 @@ +FROM python:3.10-slim + +# Set working directory +WORKDIR /app + +# Install system dependencies +RUN apt-get update && apt-get install -y \ + curl \ + && rm -rf /var/lib/apt/lists/* + +# Copy requirements file +COPY requirements.txt . + +# Install Python dependencies +RUN pip install --no-cache-dir -r requirements.txt + +# Copy the application files +COPY langchain_pirate.py . + +# Create directory for conversation logs +RUN mkdir -p conversation_logs + +# Set environment variables with defaults +ENV ANTHROPIC_API_KEY="" +ENV DOMAIN_NAME="localhost" +ENV PORT=6000 +ENV TERMINAL_PORT=6010 +ENV IMPROVE_MESSAGES=true +ENV UI_MODE=true + +# Expose the port +EXPOSE 6000 + +# Set the entrypoint +ENTRYPOINT ["python", "langchain_pirate.py"] \ No newline at end of file diff --git a/nanda_agent/examples/build.sh b/nanda_agent/examples/build.sh new file mode 100755 index 0000000..c607354 --- /dev/null +++ b/nanda_agent/examples/build.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +# Usage: ./build.sh yourname/repo:tag +# e.g. ./build.sh h4x3rotab/nanda-demo:latest + +docker build --platform linux/amd64 -t "${1}" . +docker push "${1}" diff --git a/nanda_agent/examples/docker-compose-phala.yml b/nanda_agent/examples/docker-compose-phala.yml new file mode 100644 index 0000000..a1d363d --- /dev/null +++ b/nanda_agent/examples/docker-compose-phala.yml @@ -0,0 +1,24 @@ +services: + nanda-pirate: + image: h4x3rotab/nanda-demo:latest + ports: + - "5000:5000" + - "6000:6000" + environment: + - ANTHROPIC_API_KEY=${ANTHROPIC_API_KEY:-your-api-key-here} + - DOMAIN_NAME=${DSTACK_APP_ID}-5000.${DSTACK_GATEWAY_DOMAIN} + - API_URL=https://${DSTACK_APP_ID}-5000.${DSTACK_GATEWAY_DOMAIN} + - PUBLIC_URL=https://${DSTACK_APP_ID}-6000.${DSTACK_GATEWAY_DOMAIN} + - PORT=6000 + - API_PORT=5000 + - TERMINAL_PORT=6010 + - IMPROVE_MESSAGES=true + - UI_MODE=true + - SSL=false + restart: unless-stopped + container_name: nanda-pirate-agent + volumes: + - nanda-logs:/app/conversation_logs + +volumes: + nanda-logs: \ No newline at end of file diff --git a/nanda_agent/examples/langchain_pirate.py b/nanda_agent/examples/langchain_pirate.py index 5f95857..a1f8861 100644 --- a/nanda_agent/examples/langchain_pirate.py +++ b/nanda_agent/examples/langchain_pirate.py @@ -65,10 +65,15 @@ def main(): if domain != "localhost": # Production with SSL - nanda.start_server_api(os.getenv("ANTHROPIC_API_KEY"), domain) + api_port = int(os.getenv("API_PORT", "5000")) + port = int(os.getenv("PORT", "6000")) + public_url = os.getenv("PUBLIC_URL") + api_url = os.getenv("API_URL") + ssl = os.getenv("SSL") == "true" + nanda.start_server_api(os.getenv("ANTHROPIC_API_KEY"), domain, port=port, api_port=api_port, api_url=api_url, ssl=ssl, public_url=public_url) else: # Development server - nanda.start_server() + nanda.start_server(port=port) if __name__ == "__main__": main() \ No newline at end of file