Blades is a multimodal AI Agent framework based on the Go language, supporting custom models, tools, memory, middleware, etc., suitable for multi-turn dialogue, chain-of-thought reasoning, and structured output scenarios.
Ensure you have Go 1.24+ installed, then initialize your project and import Blades with the following commands:
cd your-project-namego mod init your-project-namego get github.com/go-kratos/bladesPrerequisites
Before running, you need to configure environment variables for the model side (different ModelProvider variable names may vary; the key is to ensure the API Key and Base URL are available):
Below is a complete example of building a simple chat Agent using the OpenAI model:
package main
import ( "context" "log"
"github.com/go-kratos/blades" "github.com/go-kratos/blades/contrib/openai" "github.com/openai/openai-go/v2/option")
func main() { // Configure OpenAI API key and base URL using environment variables: model := openai.NewModel(os.Getenv("OPENAI_MODEL"), openai.Config{ APIKey: os.Getenv("OPENAI_API_KEY"), }) agent, err := blades.NewAgent( "Blades Agent", blades.WithModel(model), blades.WithInstruction("You are a helpful assistant that provides detailed and accurate information."), ) if err != nil { log.Fatal(err) } // Create a new input message input := blades.UserMessage("What is the capital of France?") // Create a new input message // Run the agent runner := blades.NewRunner(agent) result, err := runner.Run(context.Background(), input) if err != nil { log.Fatal(err) } log.Println(result.Text())}If you want to switch to another provider’s API, you need to set environment variables, for example:
export OPENAI_BASE_URL=https://api.deepseek.comYou need to set the environment variable OPENAI_API_KEY, for example:
export OPENAI_API_KEY=your-api-key| Provider | Models | Compatibility |
|---|---|---|
| OpenAI | ChatGPT, gpt-5, gpt-4, etc… | qwen3-mqx、deepseek-chat |
| Claude | Claude 3.7 Sonnet | - |
| Gemini | Gemini 2.5 Pro | - |
| Component | Description |
|---|---|
| Agent | Agent interface for integrating and coordinating various functional agents such as models, tools, and memory |
| Tool | External capability plugins (e.g., calling APIs, querying databases) |
| Memory | Conversation memory management, supporting multi-turn context |
| Middleware | Middleware mechanism for cross-cutting concerns such as logging, rate limiting, and authentication |
| ModelProvider | Model adapter (e.g., OpenAI, DeepSeek), providing a unified calling interface |