---
title: "Define AI agents as code, with Terraform or an API"
description: "Keep each agent's instructions, model, tools, triggers and budget in version control and apply them with an API or Terraform. Tex has an admin API and a Terraform provider on the registry."
updated: 2026-11-29
questions:
  - "Can I define agents as code (YAML, Terraform)?"
  - "Is there a Terraform provider for AI agents?"
  - "How do I version control AI agent definitions?"
  - "Is there an API to run and manage agents?"
  - "Who in my team can change an agent?"
url: https://trytex.ai/answers/ai-agents-as-code
---
# Define AI agents as code, with Terraform or an API

*Updated 2026-11-29. Written by the team that builds Tex, so weigh it accordingly.*

**Short answer:** treat an agent like any other piece of infrastructure: its instructions, model, tools, triggers, sandbox rules and budget in files, reviewed in pull requests and applied by a tool. Tex stores every agent as versions, and you can manage them from the console, its admin API, or the Terraform provider `meet-glen-ai/glen`.

## What an agent definition holds

In Tex an agent is one markdown document. Its header names the model, tools, triggers (schedules, feeds, webhooks), sandbox egress, budget and knowledge base. Its body holds the instructions, in the same shape as Claude Code subagents and skill files. Every save is a new version. A running session finishes on its version, and the next one runs the latest.

## Ways to manage agents in Tex

- **The console's builder,** with a chat that drafts the agent beside the document, a form and a YAML view of the same draft.
- **The admin API,** `/v1/agents`, `/v1/knowledge-bases`, `/v1/feeds` and the tools, with an admin's personal API token.
- **Terraform.** The provider is [meet-glen-ai/glen on the Terraform registry](https://registry.terraform.io/providers/meet-glen-ai/glen), open source at [meet-glen-ai/terraform-provider-glen](https://github.com/meet-glen-ai/terraform-provider-glen). It manages agents, knowledge bases, tools and members. We run our own agents this way.

```hcl
terraform {
  required_providers {
    glen = { source = "meet-glen-ai/glen" }
  }
}
```

Set `GLEN_URL` and `GLEN_API_KEY` (an admin's token from Settings) and run `terraform plan`.

## Questions people ask

**Who can change an agent?**
Admins. Members can run agents, chat with them and read, but not change them. A personal API token acts with its member's current role.

**Can I start a run from my own code?**
Yes. `POST /v1/send/<agent>` with a message starts a session and returns its id. Later messages go to `/v1/sessions/<id>/messages`.

**Is every change recorded?**
Every agent version is kept, and the journal records what each member does.

## What Tex doesn't do

- The Terraform provider is at an early version (0.1.0), so pin it.

[Try Tex with $10 of free credit](https://trytex.ai/?utm_source=answers&utm_medium=aeo&utm_campaign=ai-agents-as-code)
