This repository provides everything you need to automate and manage tasks within Kubernetes clusters using GPT models. By defining agents in a simple, scriptable format, you can streamline deployments, monitor cluster health, and handle various automation tasks efficiently.
The repository includes:
- Getting Started: Step-by-step guide to setting up and using GPTScript.
- GPTScript Agents: Examples of different agents located under
gpt-agents/.... - Docker: A Dockerfile to build the necessary Docker image, or use the pre-built image from GHCR.
- Kubernetes: Resources for deploying GPTScript agents as Jobs in Kubernetes.
- Failed Deployments: Sample failed deployments for testing and validating agent capabilities.
GPTScript is a framework that allows Large Language Models (LLMs) to operate and interact with various systems. These systems can range from local executables to complex applications with OpenAPI schemas, SDK libraries, or any RAG-based solutions. GPTScript is designed to easily integrate any system, whether local or remote, with your LLM using just a few lines of prompts.
To install the GPTScript CLI on your machine, follow these steps:
MacOS and Linux (Homebrew):
brew install gptscriptMacOS and Linux (install.sh):
curl https://get.gptscript.ai/install.sh | shVerify the Installation:
gptscript --versionThis will ensure that the GPTScript CLI is installed and ready to use.
Defining your own GPTScript agent is straightforward. Agents are defined in .gpt files, which contain the logic and commands the agent will execute.
Here’s a simple example of how an agent can be defined:
# gpt-agents/simple-cli-agent.gpt
Name: cli-agent
Tools: sys.exec
Description: I execute CLI commands on the local system.
Args: command: The CLI command to execute.
Chat: false
#prompt/instruction
Ensure the command is valid, modify it if needed, and then complete the task.
You can run CLI commands on the local system. You are an alpine-based or darwin-based system.
If the cli tool is not installed, then install it.To create your own agent, simply follow this format and customize it based on the tasks you want the agent to perform.
If you run the following command, the agent will be executed in the same directory where the agent is located. If you running it from a different directory, you have to adjust the path to the agent like path/simple-cli-agent.gpt.
alias gpt='gptscript --workspace "$(dirname "$0")" --disable-cache --openai-api-key "sk-..." simple-cli-agent.gpt $0'The Docker image provides an isolated environment to run GPTScript agents with all dependencies pre-installed. Here’s how you can use it:
First, build the Docker image using the provided Dockerfile:
docker build -t gptscript-agent-image ./build/dockerTo run the Docker container with the GPTScript agent, use the following command:
docker run --rm \
-e GPTSCRIPT_DEFAULT_MODEL="gpt-4o" \
-e OPENAI_API_KEY="your-openai-api-key" \
-e MERGED_AGENT_FILE="simple-cli-agent.gpt" \
-e OUTSIDE_AGENTS_FILES="https://raw.githubusercontent.com/your-repo/agent-file.gpt" \
gptscript-agent-imagedocker run --rm \
-e GPTSCRIPT_DEFAULT_MODEL="gpt-4o" \
-e OPENAI_API_KEY="your-openai-api-key" \
-e MERGED_AGENT_FILE="simple-cli-agent.gpt" \
-e OUTSIDE_AGENTS_FILES="https://raw.githubusercontent.com/your-repo/agent-file.gpt" \
ghcr.io/la-cc/gptscript-agents:latestThis will run the simple-cli-agent.gpt file inside the Docker container, allowing you to execute tasks defined in the agent. If you have additional agent files, you can specify them using the OUTSIDE_AGENTS_FILES environment variable.
The project also includes resources for deploying GPTScript agents as Jobs in a Kubernetes cluster.
Deploying the GPTScript agents as a Job in Kubernetes is straightforward, with resources already provided in this repository. You only need to make minor adjustments to the ConfigMap and Secret to match your environment.
Follow these steps: Here's a revised version of the text that better communicates the deployment process, focusing on the need to adjust the existing resources:
Deploying the GPTScript agent as a Job in Kubernetes is straightforward, with resources already provided in this repository. You only need to make minor adjustments to the ConfigMap and Secret to match your environment. Follow these steps:
-
Adjust the ConfigMap: Update the
configmap.yamlfile to configure the environment variables needed by your GPTScript agent. Here's an example:apiVersion: v1 kind: ConfigMap metadata: name: gptscript-agent-config data: GPTSCRIPT_DEFAULT_MODEL: "gpt-4o" OPENAI_BASE_URL: "https://api.openai.com/v1" AGENT_FILE: "simple-k8s-fix.gpt" COMMAND_STRING: "Does my cluster have any issues?" OUTSIDE_AGENTS_FILES: "https://raw.githubusercontent.com/victorgetz/gptscript-agents/main/gptscript-bot/files/devops-bot.gpt, https://github.com/victorgetz/gptscript-agents/blob/main/gptscript-bot/files/shared-context.gpt" # Uncomment and adjust the following paths if needed # GPTSCRIPT_CACHE_DIR: "/home/agentuser/.cache/gptscript" # GPTSCRIPT_CONFIG: "/home/agentuser/.config/gptscript/config.yaml" # GPTSCRIPT_WORKSPACE: "/home/agentuser/workspace"
-
Adjust the Secret: Ensure your
secret.yamlfile contains the necessary API key in Base64 format. Here's an example:apiVersion: v1 kind: Secret metadata: name: openai-api-key-secret type: Opaque data: api-key: <your-base64-encoded-api-key>
-
Deploy all Resources: Once the ConfigMap and Secret are in place, you can deploy the GPTScript agent as a Kubernetes Job. The
job.yamlfile already defines how the Job should be run. Apply the Job with the following command:kubectl apply -f k8s/deploy/
-
Monitor the Job: After deploying GPTScript as a Job, you can monitor its status and view logs to ensure everything is working as expected:
kubectl get jobs kubectl logs <pod-name> #output like: The cluster had the following issues which have been resolved: - Deleted a crash-looping pod in the `default` namespace. - Updated the image for `faulty-image-tag-deployment` to `nginx:latest`. - Updated the image for `typo-image-deployment` to `nginx:latest`.
The demo-k8s-deployments directory contains YAML files for various Kubernetes deployments that can be used to test the GPTScript agents:
deployment-typo-image-name.yamldeployment-wrong-env.yamldeployment-wrong-image-tag.yamlpod-crashloopback.yaml
These files represent common issues that might occur in a Kubernetes environment. You can use them to validate and test the capabilities of your GPTScript agents.
- GPTScript Agents from Victor Getz: A collection of GPTScript agents for various tasks and to devops related tasks. Also an Helm Chart to deploy GPTScript agents in Kubernetes as job or as a cronjob.
- Origin: GPTScript Agents that contains a few examples of GPTScript agents. Also how you can use it with Python and Golang.
- Jenkins Example GPTScript