πŸ’¬ Simple Chat Agent

A basic conversational agent deployment with session management, HTTP endpoints, and cost optimization. Perfect for customer support, virtual assistants, or general Q&A applications.

Conversational AI Production Ready Cost Optimized

Key Properties

Model Llama-3-8B-Instruct
Quantization INT8 (16GB VRAM)
Context Length 8,192 tokens
Scaling Range 3-30 replicas
Warm Pool 30% (9 replicas)
GPU Profile MIG 1g.5gb

Complete Deployment

1. Define the Model

model.yaml
apiVersion: neuronetes.io/v1alpha1
kind: Model
metadata:
  name: llama-3-8b-chat
  namespace: default
spec:
  weightsURI: s3://models/llama-3-8b-instruct/
  size: 16Gi
  quantization: int8
  architecture: llama
  parameterCount: "8B"
  format: safetensors
  cachePolicy:
    priority: medium
    pinDuration: 1h
    evictionPolicy: lru

2. Create AgentClass with Guardrails

agentclass.yaml
apiVersion: neuronetes.io/v1alpha1
kind: AgentClass
metadata:
  name: chat-assistant
  namespace: default
spec:
  modelRef:
    name: llama-3-8b-chat
  
  maxContextLength: 8192
  
  systemPrompt: |
    You are a helpful, friendly AI assistant. Provide clear,
    concise, and accurate responses. Be conversational but professional.
  
  temperature: 0.8
  maxTokens: 2048
  
  guardrails:
    - type: pii-detection
      action: redact
      threshold: 0.8
    - type: safety-check
      action: block
      threshold: 0.9
  
  slo:
    ttft: 300ms
    tokensPerSecond: 75
    p95Latency: 1s
  
  memoryConfig:
    type: ephemeral
    ttl: 30m
    maxSize: 5000

3. Deploy AgentPool with Autoscaling

agentpool.yaml
apiVersion: neuronetes.io/v1alpha1
kind: AgentPool
metadata:
  name: chat-pool
  namespace: default
spec:
  agentClassRef:
    name: chat-assistant
  
  minReplicas: 3
  maxReplicas: 30
  prewarmPercent: 30
  
  migProfile: "1g.5gb"
  
  autoscaling:
    metrics:
      - type: concurrent-sessions
        target: "100"
      - type: ttft-p95
        target: "300ms"
    
    behavior:
      scaleUp:
        stabilizationWindow: 30s
        maxChangeAbsolute: 5
      scaleDown:
        stabilizationWindow: 180s
        maxChangeAbsolute: 2
  
  sessionAffinity:
    enabled: true
    keyHeader: "X-Session-ID"
    ttl: 30m
    type: conversation-id
  
  scheduling:
    costOptimization:
      enabled: true
      spotEnabled: true
      maxCostPerHour: 30.0

Expected Results

Performance Metrics

245ms
TTFT P95
82 tok/s
Throughput
850ms
P95 Latency
100+
Concurrent Sessions
$0.02
Cost per 1K tokens

Testing the Agent

bash
# Get the endpoint
ENDPOINT=$(kubectl get svc neuronetes-ingress -o jsonpath='{.status.loadBalancer.ingress[0].ip}')

# Send a request
curl -X POST http://$ENDPOINT/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "X-Session-ID: test-session-123" \
  -d '{
    "messages": [
      {
        "role": "user",
        "content": "Hello! Can you help me understand quantum computing?"
      }
    ],
    "stream": false
  }'

Client Libraries

Python

Python
import requests

def chat(message, session_id="default"):
    response = requests.post(
        f"http://{ENDPOINT}/v1/chat/completions",
        headers={
            "Content-Type": "application/json",
            "X-Session-ID": session_id
        },
        json={
            "messages": [{"role": "user", "content": message}],
            "stream": False
        }
    )
    return response.json()

# Usage
result = chat("What is the weather like today?", "user-123")
print(result["choices"][0]["message"]["content"])

πŸ”§ RAG-Powered Code Assistant

A complete agent deployment with RAG (Retrieval-Augmented Generation) for code assistance, featuring multiple tools, queue-based task processing, and session-based state management.

RAG Pipeline Multi-Tool Enterprise Ready

Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”      β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”      β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Client    │─────▢│   Ingress    │─────▢│   Agent     β”‚
β”‚  (VSCode)   │◀─────│   (HTTP)     │◀─────│    Pool     β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜      β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜      β””β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜
                                                   β”‚
                     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”             β”‚
                     β”‚  Task Queue  │◀─────────────
                     β”‚   (NATS)     β”‚             β”‚
                     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜             β”‚
                                                   β”‚
                     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”             β”‚
                     β”‚Vector Store  │◀─────────────
                     β”‚  (Weaviate)  β”‚             β”‚
                     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜             β”‚
                                                   β”‚
                     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”             β”‚
                     β”‚Session Store β”‚β—€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                     β”‚   (Redis)    β”‚
                     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Key Properties

Model Llama-3-70B-Instruct
Quantization INT4 (140GB VRAM)
Context Length 128,000 tokens
Sharding 4-way tensor parallel
Tools code-search, file-read
GPU Profile 2x A100 40GB

AgentClass with Tools

agentclass-tools.yaml
apiVersion: neuronetes.io/v1alpha1
kind: AgentClass
metadata:
  name: code-assistant
spec:
  modelRef:
    name: llama-3-70b
  
  maxContextLength: 128000
  
  systemPrompt: |
    You are an expert code assistant. Help developers with:
    - Code review and suggestions
    - Bug fixing and debugging
    - Documentation generation
    - Code search and navigation
    
    Use the available tools to access the codebase.
  
  toolPermissions:
    - name: code-search
      rateLimit: 100/min
      timeout: 5s
      maxConcurrency: 3
      requiredScopes:
        - read:code
    
    - name: file-read
      rateLimit: 50/min
      timeout: 2s
      maxConcurrency: 2
      requiredScopes:
        - read:files
  
  guardrails:
    - type: pii-detection
      action: redact
    - type: code-injection-check
      action: block
  
  slo:
    ttft: 500ms
    tokensPerSecond: 50
    p95Latency: 2s

Expected Results

Performance Metrics

450ms
TTFT P95
55 tok/s
Throughput
1.8s
P95 Latency
2.3s
Tool Call P95
95%
Tool Success Rate

πŸ“š Complete RAG Pipeline

A production-ready retrieval-augmented generation setup with vector store, embedding model, and data locality optimization for maximum performance.

Vector Search Data Locality High Performance

Key Properties

LLM Model Llama-3-70B
Embedding Model BGE-Large-EN-v1.5
Vector Store Weaviate (3 replicas)
Session Store Redis (encrypted)
Retrieval Top-K 5 documents
Reranking Enabled

RAG AgentClass Configuration

rag-agentclass.yaml
apiVersion: neuronetes.io/v1alpha1
kind: AgentClass
metadata:
  name: rag-agent
  namespace: rag-system
spec:
  modelRef:
    name: llama-3-70b-rag
  
  maxContextLength: 128000
  
  systemPrompt: |
    You are a helpful assistant with access to a knowledge base.
    
    When answering questions:
    1. Use the retrieve tool to find relevant information
    2. Cite sources from the retrieved documents
    3. Be accurate and admit when you don't know
    4. Synthesize information from multiple sources
    
    Format citations as [Source: document_id].
  
  toolPermissions:
    - name: retrieve
      rateLimit: "50/min"
      timeout: 5s
      maxConcurrency: 3
      config:
        top_k: 5
        rerank: true
        cache_ttl: 300
    
    - name: rerank
      rateLimit: "30/min"
      timeout: 2s
  
  slo:
    ttft: 800ms
    tokensPerSecond: 45
    p95Latency: 3s

Data Locality Configuration

agentpool-locality.yaml
apiVersion: neuronetes.io/v1alpha1
kind: AgentPool
metadata:
  name: rag-pool
  namespace: rag-system
spec:
  agentClassRef:
    name: rag-agent
  
  minReplicas: 3
  maxReplicas: 15
  
  scheduling:
    priority: 90
    
    # Co-locate with vector store for low latency
    dataLocality:
      vectorStoreAffinity:
        - weaviate
      cacheAffinity:
        - redis
    
    costOptimization:
      enabled: true
      spotEnabled: true
      sloHeadroomMs: 1500

Expected Results

Performance Metrics

720ms
TTFT P95
48 tok/s
Throughput
2.8s
P95 Latency
180ms
Retrieval Time
85%
Cache Hit Rate
92%
Retrieval Accuracy

Query Example

Python
import requests

def rag_query(question, session_id=None):
    """Query the RAG system"""
    
    response = requests.post(
        "http://rag-http.rag-system/v1/rag/query",
        headers={
            "Content-Type": "application/json",
            "X-Session-ID": session_id or "default"
        },
        json={
            "messages": [
                {
                    "role": "user",
                    "content": question
                }
            ],
            "stream": False,
            "retrieval_config": {
                "top_k": 5,
                "rerank": True
            }
        }
    )
    
    return response.json()

# Example usage
result = rag_query(
    "What are the best practices for Kubernetes security?",
    session_id="user-123"
)

print(result["choices"][0]["message"]["content"])
print(f"Sources used: {result['metadata']['sources_used']}")

πŸ“Š Example Comparison

Feature Chat Agent Code Assistant RAG Pipeline
Model Size 8B 70B 70B
TTFT P95 245ms 450ms 720ms
Throughput 82 tok/s 55 tok/s 48 tok/s
GPU Memory 16GB 140GB 140GB
Cost/1K tokens $0.02 $0.15 $0.18
Tools None 2 2
Use Case General chat Code help Knowledge Q&A