Workflow Orchestration
The shell script has been created to automate the build and deployment process for AXES agents. The script has been created to containerize the AXES agent code with Docker and deploy it to a Kubernetes cluster, setting it up as part of a managed AXES environment.
#!/bin/bash
set -e
# Variables
DOCKER_IMAGE_NAME="axes-agent"
DOCKER_TAG="latest"
DOCKERFILE="Dockerfile"
K8S_NAMESPACE="axes-agents"
K8S_DEPLOYMENT_NAME="axes-agent-deployment"
K8S_SERVICE_NAME="axes-agent-service"
K8S_CONFIGMAP_NAME="axes-agent-config"
# Functions
function check_prerequisites() {
echo "Checking prerequisites..."
command -v docker >/dev/null 2>&1 || { echo "Docker is not installed. Exiting."; exit 1; }
command -v kubectl >/dev/null 2>&1 || { echo "kubectl is not installed. Exiting."; exit 1; }
echo "Prerequisites verified."
}
function build_docker_image() {
echo "Building Docker image..."
docker build -t "$DOCKER_IMAGE_NAME:$DOCKER_TAG" -f "$DOCKERFILE" . || { echo "Docker build failed. Exiting."; exit 1; }
echo "Docker image built: $DOCKER_IMAGE_NAME:$DOCKER_TAG"
}
function push_docker_image() {
echo "Pushing Docker image to registry..."
# Replace `your-docker-repo` with your Docker registry URL.
docker tag "$DOCKER_IMAGE_NAME:$DOCKER_TAG" "your-docker-repo/$DOCKER_IMAGE_NAME:$DOCKER_TAG"
docker push "your-docker-repo/$DOCKER_IMAGE_NAME:$DOCKER_TAG" || { echo "Failed to push Docker image. Exiting."; exit 1; }
echo "Docker image pushed successfully."
}
function create_k8s_namespace() {
echo "Creating Kubernetes namespace if it doesn't exist..."
kubectl get namespace "$K8S_NAMESPACE" >/dev/null 2>&1 || \
kubectl create namespace "$K8S_NAMESPACE"
echo "Namespace "$K8S_NAMESPACE" is ready."
}
function create_k8s_configmap() {
echo "Creating ConfigMap for environment variables..."
kubectl -n "$K8S_NAMESPACE" create configmap "$K8S_CONFIGMAP_NAME" \
--from-env-file=.env --dry-run=client -o yaml | kubectl apply -f -
echo "ConfigMap created: $K8S_CONFIGMAP_NAME"
}
function deploy_to_k8s() {
echo "Deploying to Kubernetes..."
cat <<EOF | kubectl -n "$K8S_NAMESPACE" apply -f -
apiVersion: apps/v1
kind: Deployment
metadata:
name: $K8S_DEPLOYMENT_NAME
spec:
replicas: 3
selector:
matchLabels:
app: $K8S_DEPLOYMENT_NAME
template:
metadata:
labels:
app: $K8S_DEPLOYMENT_NAME
spec:
containers:
- name: $DOCKER_IMAGE_NAME
image: your-docker-repo/$DOCKER_IMAGE_NAME:$DOCKER_TAG
ports:
- containerPort: 3000
envFrom:
- configMapRef:
name: $K8S_CONFIGMAP_NAME
---
apiVersion: v1
kind: Service
metadata:
name: $K8S_SERVICE_NAME
spec:
selector:
app: $K8S_DEPLOYMENT_NAME
ports:
- protocol: TCP
port: 80
targetPort: 3000
type: LoadBalancer
EOF
echo "Deployment and Service created successfully."
}
# Main Execution
check_prerequisites
build_docker_image
push_docker_image
create_k8s_namespace
create_k8s_configmap
deploy_to_k8s
echo "AXES Agent setup and deployment completed successfully in Kubernetes."
Typescript code has been created to automate the build as per the capabilities needed by the Agent.
* This documentation outlines the process to hook up AI tools as capabilities within an AXES agent using TypeScript.
* The implementation leverages OpenAI's GPT-based models (ChatGPT), LangChain, and LangGraph for tool orchestration.
*
* The examples include:
* - Market analysis tools
* - Wallet functionalities (swap, send, receive, stake on Ethereum)
* - General AI tools (web search, scraping, sentiment analysis, etc.)
*/
// Dependencies:
// - langchain
// - langgraph
// - ethers (for Ethereum wallet interactions)
// - dotenv (for environment variable management)
// - openai
import { OpenAI } from "langchain/llms/openai";
import { Tool, AgentExecutor, initializeAgentExecutor } from "langchain/agents";
import { EthereumWallet } from "ethers";
import { LangGraph } from "langgraph";
import { config } from "dotenv";
config(); // Load environment variables from .env
// Initialize OpenAI Base Model
const baseModel = new OpenAI({
apiKey: process.env.OPENAI_API_KEY,
temperature: 0.7,
modelName: "gpt-4",
});
// Define AI Tools
const aiTools: Tool[] = [
{
name: "MarketAnalyzer",
description: "Analyzes financial markets and provides insights.",
func: async (input: string) => {
// Placeholder for market analysis logic
return `Market analysis for ${input}: Placeholder insights.`;
},
},
{
name: "SentimentAnalyzer",
description: "Performs sentiment analysis on given text.",
func: async (input: string) => {
// Sentiment analysis implementation
return `Sentiment analysis result for '${input}': Positive.`;
},
},
{
name: "WebScraper",
description: "Extracts information from web pages.",
func: async (url: string) => {
// Web scraping logic
return `Scraped data from ${url}: Placeholder data.`;
},
},
];
// Define Ethereum Wallet Tool
const wallet = new EthereumWallet(process.env.WALLET_PRIVATE_KEY);
const walletTools: Tool[] = [
{
name: "WalletSwap",
description: "Swaps tokens on Ethereum.",
func: async (input: string) => {
const [fromToken, toToken, amount] = input.split(",");
// Ethereum swap logic
return `Swapped ${amount} ${fromToken} for ${toToken}.`;
},
},
{
name: "WalletStake",
description: "Stakes tokens on Ethereum.",
func: async (input: string) => {
const [token, amount, stakingContract] = input.split(",");
// Ethereum staking logic
return `Staked ${amount} ${token} at contract ${stakingContract}.`;
},
},
{
name: "WalletSend",
description: "Sends tokens on Ethereum.",
func: async (input: string) => {
const [to, amount, token] = input.split(",");
// Ethereum send logic
return `Sent ${amount} ${token} to ${to}.`;
},
},
];
// Combine AI Tools and Wallet Tools
const allTools = [...aiTools, ...walletTools];
// Create an AgentExecutor
async function initializeAgent() {
const executor = await initializeAgentExecutor(
allTools,
baseModel,
"zero-shot-react-description"
);
console.log("Agent initialized with tools.");
return executor;
}
// Example: Running the Agent
async function runAgent() {
const agent = await initializeAgent();
const result = await agent.call({ input: "Analyze ETH market trends" });
console.log("Agent output:", result.output);
}
runAgent().catch((error) => {
console.error("Error running agent:", error);
});
Last updated