DEV Community

HyperNexus
HyperNexus

Posted on • Originally published at tormentnexus.site

From Zero to Production AI Agent: The Definitive TormentNexus Deployment Guide

From Zero to Production AI Agent: The Definitive TormentNexus Deployment Guide

Stop experimenting. Learn the exact steps to install TormentNexus, configure your MCP server, connect your LLM, and deploy a robust AI agent to production. This guide covers self-hosted AI agent deployment from the first command to the final API call.

Why Your AI Agent Needs a Battle-Tested Deployment Pipeline

The graveyard of AI projects is littered with brilliant Jupyter notebooks that never saw the light of day. The chasm between a local prototype and a production AI agent is not just technical—it's operational. You need persistent state, scalable tool execution, secure secret management, and a unified runtime. TormentNexus bridges this gap with a purpose-built platform designed for AI agent deployment.

This isn't another framework library. TormentNexus is a self-hosted AI runtime that handles the complex orchestration layer your agent needs: managing long-running processes, connecting to diverse data sources via the Model Context Protocol (MCP), providing observability, and offering a consistent API for both your LLM and your agent's tools. In this guide, we will deploy a complete AI agent that can query a local database and fetch real-time weather data, all running from your own infrastructure.

Phase 1: Install TormentNexus and Bootstrap Your Environment

We begin with a clean installation. TormentNexus is distributed as a single binary with a companion CLI for project management, ensuring a self-contained and reproducible environment. We'll install it on an Ubuntu 22.04 LTS server, though it runs identically on macOS and other Linux distributions.

First, we download the latest stable version (as of writing, v1.13.0) and initialize a new project directory. The `torment init` command scaffolds the necessary configuration files and directory structure.

# Download and install TormentNexus (Linux amd64)
curl -fsSL https://releases.tormentnexus.site/v1.13.0/install.sh | sudo bash

# Initialize a new project in your home directory
cd ~
torment init my-production-agent
cd my-production-agent
ls -la

The `ls` command reveals the core of your new project: `torment.toml` (the central configuration), a `mcp/` directory for your server definitions, and a `data/` folder for agent persistence. This structure is version-controlled by default, providing a clear audit trail for your AI agent deployment.

Phase 2: Configure Your First Model Context Protocol (MCP) Server

The Model Context Protocol is the standard for how an AI agent interacts with the outside world. In TormentNexus, you define MCP servers as modular units of functionality. We will configure a server that connects to a local PostgreSQL database, allowing our agent to execute SQL queries.

Create a new file at `mcp/database.server.toml`. The TOML syntax is declarative and self-documenting. We'll define a server named `postgres-query` and specify its connection parameters and the tools it exposes.

# mcp/database.server.toml

[mcp.servers.postgres-query]
description = "Provides read-only access to the company analytics database."
engine = "torment-sql"
version = "0.1.0"

[mcp.servers.postgres-query.config]
# Secrets are referenced securely from the environment
connection_string = "${DB_CONNECTION_STRING}"
# Define the tools this server makes available to the agent
[[mcp.servers.postgres-query.tools]]
name = "execute_query"
description = "Executes a read-only SQL query and returns the result as a JSON array."
parameters = { query = { type = "string", description = "The SQL SELECT query to execute." } }
permissions = ["database:read"]

Critical for production AI: note the `${DB_CONNECTION_STRING}` syntax. TormentNexus injects secrets from a `.env` file or your host environment, never hardcoding credentials into version control. This is non-negotiable for secure, self-hosted AI agent deployment.

Phase 3: Connect Your LLM Provider and Define Agent Identity

Now, we connect the "brain" of the operation. TormentNexus supports a wide array of LLM providers through a unified interface. We'll configure our agent to use OpenAI's GPT-4 Turbo, but you could equally use Anthropic, local Ollama, or a custom endpoint.

Edit the main `torment.toml` file to define the agent's core identity, its LLM connection, and which MCP servers it can use. This single file is the source of truth for your entire agent's capabilities.

# torment.toml - Core Agent Configuration

[agent]
name = "DataScout"
description = "An autonomous agent that answers business questions by querying the analytics DB and verifying external data."
version = "1.0.0"

[llm]
# Use the OpenAI provider; API key is in environment as OPENAI_API_KEY
provider = "openai"
model = "gpt-4-turbo-preview"
temperature = 0.1  # Low temperature for consistent, factual output

# Grant the agent access to specific MCP servers
[agent.tools]
allowed_servers = ["postgres-query", "weather-api"]

# Define the agent's system prompt and initial context
[agent.prompt]
system_prompt = """
You are DataScout, a meticulous data analyst AI. Your primary job is to answer user questions by:
1. First, breaking down complex questions into logical sub-queries.
2. Using the `execute_query` tool from the `postgres-query` MCP server to fetch relevant data.
3. Presenting your findings clearly, citing the data source and the specific SQL you ran.
Always prioritize accuracy over speed. If a query might be too broad, ask for clarification.
"""

This configuration achieves two key production AI goals: fine-grained permission control (the agent can only access specified MCP servers) and deterministic behavior through careful prompt engineering and low temperature settings.

Phase 4: Launch, Test, and Observe Your Production Agent

With configuration complete, we start the TormentNexus runtime. This launches the agent in a supervised daemon mode, manages all connections, and starts a local API server for interaction and monitoring.

# Set your secrets in the .env file
echo 'DB_CONNECTION_STRING=postgresql://user:pass@localhost:5432/analytics' >> .env
echo 'OPENAI_API_KEY=sk-...' >> .env

# Start the agent in the background with logging
torment start --background --log-file=data/agent.log

# Check the agent's status and health
torment status
# Output:
# 🟢 Agent 'DataScout' is running.
#    PID: 28451
#    Uptime: 15s
#    MCP Servers: 2 online
#    API Endpoint: http://localhost:8000/v1/chat

Your agent is now live and ready for queries. You can interact with it via the local API endpoint using standard HTTP requests. The logs in `data/agent.log` provide real-time observability into tool calls, LLM interactions, and any errors—essential for debugging a production system.

Beyond Launch: Scaling and Securing Your Self-Hosted AI

Deploying the initial instance is just the beginning. For a truly resilient production AI, consider these critical enhancements provided by the TormentNexus platform:

  • Persistence: The `data/` directory maintains agent state across restarts, preserving conversation history and learned contexts.
  • Horizontal Scaling: Run multiple agent instances behind a load balancer, with shared state backed by a Redis or Postgres instance you configure in `torment.toml`.
  • Authentication: Enable JWT-based API authentication in the `[api]` section of your config to secure the chat endpoint.
  • Monitoring Integration: Expose Prometheus metrics from the runtime endpoint (`/metrics`) to integrate with Grafana dashboards for tracking tool latency, token usage, and error rates.

The journey from a script to a service is complete. You've not just deployed an AI agent; you've operationalized it.

Ready to move your AI from prototype to production? Download TormentNexus and follow this guide to deploy your first self-hosted AI agent in under an hour. Visit https://tormentnexus.site for documentation, examples, and the latest release.


Originally published at tormentnexus.site

Top comments (0)