The process of creating an agent in the AXES framework is designed to be intuitive and modular, allowing developers to customize and deploy agents tailored to specific use cases with minimal complexity.
The AXES framework simplifies the entire lifecycle of agent creation, from conceptualization to deployment, ensuring developers can focus on innovation without being hindered by technical complexities.
import * as k8s from "@kubernetes/client-node";
import * as shell from "shelljs";
import * as fs from "fs";
import path from "path";
// Configuration
const EKS_CLUSTER_NAME = "your-eks-cluster";
const ECR_REPOSITORY = "your-ecr-repo";
const NAMESPACE = "agent-framework";
const AI_TOOLS = {
tool1: "some-python-lib-1",
tool2: "some-python-lib-2",
tool3: "some-python-lib-3",
};
// Helper function to execute shell commands
function executeCommand(command: string) {
if (shell.exec(command).code !== 0) {
console.error(`Command failed: ${command}`);
process.exit(1);
}
}
// Step 1: Generate Dockerfile dynamically
function createDockerfile(agentName: string, tools: string[]) {
const dockerfileContent = `
FROM python:3.9-slim
WORKDIR /app
# Install dependencies
RUN apt-get update && apt-get install -y curl
# Install selected AI tools
${tools.map((tool) => `RUN pip install ${tool}`).join("\n")}
# Copy agent code
COPY agent.py /app/
CMD ["python", "agent.py"]
`;
fs.writeFileSync("Dockerfile", dockerfileContent);
}
// Step 2: Build and push Docker image
function buildAndPushDockerImage(agentName: string): string {
const imageTag = `${ECR_REPOSITORY}/${agentName.toLowerCase()}:${Date.now()}`;
executeCommand(`docker build -t ${imageTag} .`);
executeCommand(`aws ecr get-login-password | docker login --username AWS --password-stdin ${ECR_REPOSITORY}`);
executeCommand(`docker push ${imageTag}`);
return imageTag;
}
// Step 3: Deploy agent to Kubernetes
async function deployToKubernetes(agentName: string, image: string) {
const k8sApi = new k8s.KubeConfig();
k8sApi.loadFromDefault();
const k8sClient = k8sApi.makeApiClient(k8s.AppsV1Api);
const deploymentManifest = {
apiVersion: "apps/v1",
kind: "Deployment",
metadata: { name: agentName, namespace: NAMESPACE },
spec: {
replicas: 1,
selector: { matchLabels: { app: agentName } },
template: {
metadata: { labels: { app: agentName } },
spec: {
containers: [
{
name: agentName,
image,
ports: [{ containerPort: 5000 }],
},
],
},
},
},
};
// Apply the deployment
try {
await k8sClient.createNamespacedDeployment(NAMESPACE, deploymentManifest);
console.log(`Agent ${agentName} deployed successfully to Kubernetes!`);
} catch (error) {
console.error(`Failed to deploy agent: ${error}`);
}
}
// Main function
async function main() {
console.log("Welcome to the AXES Agent Deployment Script!");
// Agent name
const agentName = "sample-agent";
// AI Tools selection
console.log("Available AI Tools:");
Object.keys(AI_TOOLS).forEach((tool, index) => console.log(`${index + 1}. ${tool}`));
const selectedToolIndexes = prompt("Enter the numbers of tools to include (comma-separated): ");
const selectedTools = selectedToolIndexes
.split(",")
.map((index) => AI_TOOLS[Object.keys(AI_TOOLS)[parseInt(index.trim()) - 1]]);
// Generate Dockerfile
console.log("Generating Dockerfile...");
createDockerfile(agentName, selectedTools);
// Build and push Docker image
console.log("Building and pushing Docker image...");
const image = buildAndPushDockerImage(agentName);
// Deploy to Kubernetes
console.log("Deploying to Kubernetes...");
await deployToKubernetes(agentName, image);
console.log("Deployment process completed!");
}
main().catch((error) => {
console.error("Error during deployment:", error);
});
This script dynamically builds, deploys, and integrates agents into a Kubernetes environment, providing flexibility for AI tool selection and scalability for the AXES framework.