API Reference
Secure Function

secureConnect()

The secureConnect() function is the main entry point for adding security capabilities to any AI agent.

Signature

async function secureConnect(
  agent: any, 
  options: SecureOptions
): Promise<SecuredAgent>

Parameters

agent

  • Type: any
  • Description: The AI agent to secure. Can be any object or class instance.

options

  • Type: SecureOptions
  • Description: Configuration options for security features.

Returns

Returns a Promise that resolves to a SecuredAgent - the original agent enhanced with security capabilities.

Example

import { secureConnect } from '@aztp/sdk';
 
// Create a secured agent with identity management
const securedAgent = await secureConnect(myAgent, {
  spiffe: {
    trustDomain: "company.local",
    keyDir: "./certs"
  }
});
 
// Add policy enforcement
const securedAgentWithPolicy = await secureConnect(myAgent, {
  spiffe: {
    trustDomain: "company.local",
    keyDir: "./certs"
  },
  policy: {
    endpoint: "http://localhost:8181",
    initialPolicy: myPolicyDocument
  }
});
 
// Full security stack
const fullSecureAgent = await secureConnect(myAgent, {
  spiffe: {
    trustDomain: "company.local",
    keyDir: "./certs"
  },
  policy: {
    endpoint: "http://localhost:8181",
    initialPolicy: myPolicyDocument
  },
  rpc: {
    connection: {
      endpoint: "localhost:50051"
    }
  },
  monitoring: {
    onEvent: (event) => {
      console.log('[Security Event]', event);
    }
  }
});

Security Features

The secured agent gets the following capabilities:

// Identity Management
const identity = await securedAgent.getIdentity();
const isVerified = await securedAgent.verifyIdentity();
 
// Policy Enforcement (if configured)
const canDoAction = await securedAgent.can('action', context);
 
// Secure Communication (if configured)
const result = await securedAgent.secureCall('target-agent', 'action', payload);

Error Handling

The secureConnect() function may throw errors in the following cases:

  • Invalid configuration options
  • Failed identity setup
  • Failed policy initialization
  • Failed RPC setup

Always wrap the secureConnect() call in a try-catch block in production: