如何使用 Terraform 以宣告式方式建構 AI Agent
本教學文章介紹如何利用 ChatBotKit Terraform Provider 以宣告式方式建構及部署 AI Agent。文章強調將 AI 基礎設施視為程式碼,以實現版本控制、可重複性及自動化部署。
AI Agents
AI Widgets
AI Messaging
AI SDKs
AI Enterprise
AI Whitelabel
Examples
Documentation
Manuals
Tutorials
Changelog
Reflections
How to Build an AI Agent Declaratively with Terraform
In this tutorial, you'll learn how to build and deploy AI agents declaratively using the ChatBotKit Terraform Provider. By treating your AI infrastructure as code, you gain version control, reproducibility, and automated deployments for your conversational AI solutions.
What You'll Learn
By the end of this tutorial, you will be able to:
Prerequisites
Before starting, make sure you have:
Estimated time: 20-30 minutes
Step 1: Set Up Your Project
Create a new directory for your Terraform project and initialize it:
Create a file named main.tf with the provider configuration:
Set your API key as an environment variable:
Tip: You can get your API key from the ChatBotKit Dashboard.
Initialize Terraform to download the provider:
You should see a message confirming that the ChatBotKit provider was installed successfully.
Step 2: Create a Knowledge Base
AI agents are more useful when they have access to relevant information. Let's create a dataset that serves as a knowledge base:
Add the following to your main.tf file:
The dataset acts as a retrieval-augmented generation (RAG) source. When the bot receives questions, it can search this dataset to find relevant information.
Step 3: Create a Skillset with Abilities
Skillsets give your AI agent the ability to perform actions beyond just answering questions. Let's create a skillset with web search and fetch capabilities:
These abilities use ChatBotKit's built-in templates to give your agent access to real-time web information. Templates provide pre-configured instructions for common actions, making it easy to add powerful capabilities.
Step 4: Define the AI Agent
Now let's create the main bot resource that ties everything together:
The backstory field is crucial—it defines your agent's personality, capabilities, and behavior guidelines. Think of it as the system prompt that shapes how your agent responds.
Step 5: Add an Integration
To make your agent accessible, you need to deploy it to a platform. Let's add a trigger integration that allows the bot to be invoked via webhooks:
You can also deploy to messaging platforms. Here's how to add a Slack integration:
Step 6: Add Outputs
Add outputs to easily reference the created resources:
Step 7: Deploy Your Agent
Preview the changes Terraform will make:
Review the output to ensure everything looks correct. You should see resources being created for the dataset, skillset, abilities, bot, and integration.
Apply the configuration to create your AI agent:
Type yes when prompted to confirm. Terraform will create all the resources and output their IDs.
Step 8: Test Your Agent
Once deployed, you can test your AI agent in the ChatBotKit dashboard:
Complete Configuration
Here's the complete main.tf file for reference:
Troubleshooting
Authentication Errors
If you see Error: 401 Unauthorized, verify that:
Resource Already Exists
If Terraform reports that a resource already exists, you can import it:
State Drift
If resources were modified outside of Terraform, run terraform plan to see the differences and terraform apply to reconcile them.
Next Steps
Now that you have a working AI agent deployed with Terraform, consider exploring:
By managing your AI agents as code, you can version control your configurations, collaborate with your team, and deploy consistently across environments.
Multi-Stage Data Extraction with ChatBotKit Complete API
Modernizing Legacy Applications with AI Widgets
Setting Up MCPServer Integration with VSCode
Build conversational AI solutions for every need and scale.
Products
Resources
Apps
About
相關文章