Examples
Full Stack Pattern

Full Stack Pattern

The Full Stack pattern (Identity + RPC + Policy) represents the most comprehensive security implementation. This pattern is ideal for complex systems where multiple AI agents need to collaborate while adhering to strict policies.

Use Case: Autonomous Supply Chain Network

This pattern demonstrates a fully secured network of AI agents that:

  • Autonomously manage global supply chain operations
  • Coordinate across multiple organizations
  • Enforce complex business rules and compliance
  • Maintain secure, verifiable transactions
  • Optimize operations in real-time
// Procurement Agent
const procurementAgent = await secureConnect(
  new LangChain.Agent({
    name: "procurement_agent",
    llm: new OpenAI({ temperature: 0 }),
    tools: [supplierTool, inventoryTool, forecastTool]
  }), 
  {
    spiffe: {
      trustDomain: "supply.chain.org"
    },
    policy: {
      initialPolicy: procurementPolicy  // Includes spend limits, supplier requirements
    },
    rpc: {
      endpoint: "https://procurement-agent"
    }
  }
);
 
// Logistics Agent
const logisticsAgent = await secureConnect(
  new LangChain.Agent({
    name: "logistics_agent",
    llm: new OpenAI({ temperature: 0 }),
    tools: [routingTool, shipmentTool, trackingTool]
  }), 
  {
    spiffe: {
      trustDomain: "supply.chain.org"
    },
    policy: {
      initialPolicy: logisticsPolicy  // Includes routing rules, customs compliance
    },
    rpc: {
      endpoint: "https://logistics-agent"
    }
  }
);
 
// Inventory Agent
const inventoryAgent = await secureConnect(
  new LangChain.Agent({
    name: "inventory_agent",
    llm: new OpenAI({ temperature: 0 }),
    tools: [warehouseTool, stockTool, demandTool]
  }), 
  {
    spiffe: {
      trustDomain: "supply.chain.org"
    },
    policy: {
      initialPolicy: inventoryPolicy  // Includes stock levels, storage rules
    },
    rpc: {
      endpoint: "https://inventory-agent"
    }
  }
);
 
// Example of autonomous supply chain orchestration
async function optimizeSupplyChain(demand) {
  try {
    // 1. Inventory Check & Demand Analysis
    const inventoryStatus = await inventoryAgent.analyzeStock({
      demand: demand,
      forecast: await getForecast(demand.region)
    });
 
    // 2. Procurement Planning with Policy Checks
    const procurementPlan = await procurementAgent.secureCall(
      "inventory_agent",
      "create_procurement_plan",
      {
        inventory: inventoryStatus,
        suppliers: await getQualifiedSuppliers(demand.region),
        metadata: {
          inventory_agent: await inventoryAgent.getIdentity(),
          timestamp: new Date()
        }
      }
    );
 
    // 3. Logistics Coordination
    const logisticsPlan = await logisticsAgent.secureCall(
      "procurement_agent",
      "plan_logistics",
      {
        procurement: procurementPlan,
        constraints: {
          time: demand.deadline,
          cost: demand.budget,
          regulations: await getRegulations(demand.route)
        },
        metadata: {
          procurement_agent: await procurementAgent.getIdentity(),
          timestamp: new Date()
        }
      }
    );
 
    return {
      plan: {
        procurement: procurementPlan,
        logistics: logisticsPlan,
        inventory: inventoryStatus
      },
      metrics: {
        cost_reduction: calculateSavings(procurementPlan),
        time_optimization: calculateTimeImprovement(logisticsPlan),
        risk_mitigation: assessRisk(procurementPlan, logisticsPlan)
      },
      compliance: {
        regulations: verifyCompliance(logisticsPlan),
        policies: validatePolicies(procurementPlan)
      },
      audit: {
        agents: {
          procurement: await procurementAgent.getIdentity(),
          logistics: await logisticsAgent.getIdentity(),
          inventory: await inventoryAgent.getIdentity()
        },
        timestamps: {
          start: new Date(),
          completion: new Date()
        }
      }
    };
  } catch (error) {
    console.error("Supply chain optimization failed:", error.message);
    throw error;
  }
}

Real-World Applications

  1. Global Manufacturing

    • Autonomous supplier management
    • Real-time logistics optimization
    • Inventory optimization
    • Regulatory compliance across borders
    • Multi-party coordination
  2. Retail Operations

    • Demand-driven procurement
    • Dynamic inventory management
    • Last-mile delivery optimization
    • Vendor compliance management
    • Real-time supply chain visibility
  3. Pharmaceutical Supply Chain

    • Temperature-controlled logistics
    • Regulatory compliance tracking
    • Quality control automation
    • End-to-end traceability
    • Emergency supply optimization