Blades is a multimodal AI Agent framework based on the Go language, supporting custom models, tools, memory, middleware, etc., suitable for multi-turn conversations, chain-of-thought reasoning, and structured output scenarios.
Ensure you have installed Go 1.20+, 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/bladesBelow 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() { // Create an Agent, specifying the model and model provider provider := openai.NewChatProvider( openai.WithChatOptions( option.WithBaseURL("https://api.deepseek.com"), option.WithAPIKey("API-YOUR-KEY"), ), ) agent := blades.NewAgent( "Blades Agent", blades.WithModel("deepseek-chat"), // or gpt-5, qwen3-max, etc. blades.WithProvider(provider), blades.WithInstructions("You are a helpful assistant that provides detailed and accurate information."), ) // Input prompt prompt := blades.NewPrompt( blades.UserMessage("What is the capital of France?"), ) // Execute the Agent result, err := agent.Run(context.Background(), prompt) if err != nil { log.Fatal(err) } // Output the result log.Println(result.Text())}If you want to switch to another LLM 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 | Model | Compatibility |
|---|---|---|
| OpenAI | ChatGPT, GPT-4, GPT-3.5, etc… | Alibaba Bailian, DeepSeek |
| Claude | Claude 3.7 Sonnet | - |
| Gemini | Gemini 2.5 Pro | - |
| Component | Description |
|---|---|
| Agent | The core of the intelligent agent, responsible for coordinating models, tools, memory, etc. |
| Tool | External capability plugins (such as calling APIs, querying databases) |
| Memory | Session memory management, supporting multi-turn context |
| Runnable | A unified interface for all executable components (Agent, Chain, Model, etc. all implement it) |
| Middleware | Middleware mechanism for cross-cutting concerns like logging, rate limiting, authentication |
| ModelProvider | Model adapter (e.g., OpenAI, DeepSeek), providing a unified calling interface |