GAI 是 AI Skill Hub 本期精选Agent工作流之一。综合评分 8.0 分,整体质量较高。我们强烈推荐将其纳入你的 AI 工具库,帮助提升工作效率。
GAI 是一套完整的 AI Agent 自动化工作流方案。通过可视化的节点编排,将复杂的多步骤任务拆解为清晰的自动化流程,实现全程无人值守的智能处理。支持与数百种外部服务和 API 无缝集成,适合构建数据处理管线、业务自动化和 AI 辅助决策系统。
GAI 是一套完整的 AI Agent 自动化工作流方案。通过可视化的节点编排,将复杂的多步骤任务拆解为清晰的自动化流程,实现全程无人值守的智能处理。支持与数百种外部服务和 API 无缝集成,适合构建数据处理管线、业务自动化和 AI 辅助决策系统。
# 方式一:go install(推荐) go install github.com/lace-ai/gai@latest # 方式二:从源码编译 git clone https://github.com/lace-ai/gai cd gai go build -o gai . # 方式三:下载预编译二进制 # 访问 Releases 页面下载对应平台二进制文件 # https://github.com/lace-ai/gai/releases
# 查看帮助 gai --help # 基本运行 gai [options] <input> # 详细使用说明请查阅文档 # https://github.com/lace-ai/gai
# gai 配置说明 # 查看配置选项 gai --config-example > config.yml # 常见配置项 # output_dir: ./output # log_level: info # workers: 4 # 环境变量(覆盖配置文件) export GAI_CONFIG="/path/to/config.yml"
<p align="center"> <a href="https://github.com/lace-ai/gai/blob/main/go.mod"> <img alt="GitHub go.mod Go version" src="https://img.shields.io/github/go-mod/go-version/lace-ai/gai" style="margin: 0 6px;"> </a> <a href="https://github.com/lace-ai/gai/actions"> <img alt="CI" src="https://img.shields.io/badge/ci-passing-brightgreen.svg" style="margin: 0 6px;"> </a> <a href="https://github.com/lace-ai/gai/blob/main/LICENSE"> <img alt="License" src="https://img.shields.io/badge/license-LGPL-informational.svg" style="margin: 0 6px;"> </a> <a href="https://pkg.go.dev/github.com/lace-ai/gai"><img src="https://pkg.go.dev/badge/github.com/lace-ai/gai.svg" alt="Go Reference"></a> </p> <p></p>
GAI is a flexible Go framework for building agent-style applications on top of LLMs. It provides a generic interface for providers and models, prompt and context implementations, and a loop for agentic-calling workflows.
The library is organized around three ideas:
ai defines the core provider, model, request, and response abstractions.context builds rendered prompts from system instructions, runtime context sources, conversation messages, and a user prompt.loop runs iterative model and tool execution when a model returns a tool call.And:
agent packages a model, tools, prompt factory, tokenizer, and loop limits into a reusable definition.1.26.x or newergo get github.com/lace-ai/gai
</summary>
context.New creates a Builder from a Definition. The definition supplies the renderer, system instructions, context sources, structured prompt input, token budget, output reserve, tokenizer, and optional debug sink.
builder := gaictx.New(gaictx.Definition{
Renderer: &gaictx.XMLRenderer{},
SystemInstructions: []gaictx.Part{
gaictx.NewTextPart("Follow the system policy."),
},
ContextSources: []gaictx.ContextSource{
history.NewHistory(sessionID, historyStore),
},
PromptInput: gaictx.PromptInput{
User: gaictx.NewTextContent("Summarize the project status."),
},
TokenBudget: 128000,
OutputTokenReserve: 4096,
Tokenizer: model.Tokenizer(),
})
The builder has two phases:
BuildContext calls each ContextSource in order. A source receives the remaining token budget and returns one Part.BuildPrompt renders system instructions, built context sources, input context parts, current user content, and non-user messages from the loop conversation into one string.Part is the unit of token counting and rendering. Built-in parts include TextPart, NamedPart, MessagePart, and SystemPart; NewJSONPart creates named structured JSON context. Custom parts implement Name, Tokens, and Render. XMLRenderer is the default, or provide another Renderer in the definition.
When TokenBudget is positive, the available context budget is TokenBudget - OutputTokenReserve - system instruction tokens. The active tokenizer is passed automatically to context sources that implement TokenizerSetter. A builder created by an agent.Agent also receives the agent tokenizer override, or the model tokenizer when no override is configured.
Use AppendSystemInstructions, AppendContextSource, and SetInput when the prompt needs to be changed after construction. SetDebugSink enables prompt-build diagnostics.
</details>
<details>
<summary>
The shortest path is to create a provider model, define an agent, and start a run. Import GAI's context package with an alias so it does not conflict with the standard library package.
provider := gemini.New(os.Getenv("GEMINI_API_KEY"), nil)
model, err := provider.Model("gemini-3-flash-preview")
assistant := agent.New(agent.Definition{
Name: "assistant",
Model: model,
Prompt: func(ctx context.Context, input agent.RunInput) (gaictx.PromptBuilder, error) {
return gaictx.New(gaictx.Definition{
SystemInstructions: []gaictx.Part{
gaictx.NewTextPart("You are a concise, helpful assistant."),
},
}), nil
},
})
workflow, err := assistant.NewRun(ctx, agent.RunInput{
Prompt: gaictx.PromptInput{
User: gaictx.NewTextContent("What is the capital of France?"),
},
})
tokens, statuses, errs := workflow.Run(ctx)
go func() {
for range statuses {
}
}()
for token := range tokens {
fmt.Print(token.Text)
}
for err := range errs {
if err != nil {
panic(err)
}
}
Agents can include stream middleware in their definition. An input mapper can project the typed upstream workflow result into the ordinary RunInput accepted by the nested agent. This memory agent records its own output while passing the assistant response through unchanged.
memoryAgent := agent.New(agent.Definition{
Name: "memory",
Model: model,
Tools: []loop.Tool{saveMemoryTool},
Prompt: func(ctx context.Context, input agent.RunInput) (gaictx.PromptBuilder, error) {
return memoryPrompt(input), nil
},
})
assistant := agent.New(agent.Definition{
Name: "assistant",
Model: model,
Prompt: assistantPrompt,
Middleware: []agent.Middleware{
agent.NewAgentMiddleware(memoryAgent, agent.AgentMiddlewareConfig{
Output: agent.PreserveOutput,
ErrorPolicy: agent.RecordError,
MapInput: func(ctx context.Context, result agent.WorkflowResult) (agent.RunInput, error) {
observation, err := buildMemoryObservation(ctx, result)
if err != nil {
return agent.RunInput{}, err
}
observationPart, err := gaictx.NewJSONPart("memory_observation", observation)
if err != nil {
return agent.RunInput{}, err
}
return agent.RunInput{
ID: result.Input.ID,
Prompt: gaictx.PromptInput{
Context: []gaictx.Part{observationPart},
},
Meta: result.Input.Meta,
}, nil
},
}),
},
})
workflow, err := assistant.NewRun(ctx, agent.RunInput{
Prompt: gaictx.PromptInput{
User: gaictx.NewTextContent("What is the capital of France?"),
},
Meta: map[string]any{"session_id": sessionID},
})
tokens, statuses, errs := workflow.Run(ctx)
go func() {
for range statuses {
}
}()
for token := range tokens {
fmt.Print(token.Text)
}
for err := range errs {
if err != nil {
panic(err)
}
}
result := workflow.Result()
fmt.Printf("memory stage output: %s\n", result.Stages[0].Result.Text)
For a single non-agent request, call the model directly with model.Generate(ctx, ai.AIRequest{Prompt: "...", MaxTokens: 100}).
</summary>
Tools must implement:
type Tool interface {
Name() string
Description() string
Params() ai.ToolParameters
Function(ctx context.Context, req *ai.ToolCall) *ToolResponse
}
Params returns a structured object schema. The runtime serializes it to JSON Schema for provider-native tool calling and for the prompt fallback:
func (t *SaveMemoryTool) Params() ai.ToolParameters {
return ai.ToolParameters{
Strict: true,
Properties: []ai.ToolParameter{
{
Name: "memory",
Type: ai.ToolParameterString,
Description: "The memory text to save.",
Required: true,
},
},
}
}
Tool calls are expected to arrive as JSON with this shape:
{
"type": "function",
"name": "tool_name",
"arguments": {
"some": "value"
}
}
Tool call IDs are generated internally by the runtime and are not model-controlled. When a provider supports native tool calling, the loop sends tool definitions through AIRequest.Tools. Prompt-rendered JSON tool calls are retained as a fallback compatibility protocol.
</details>
<details>
<summary>
agent/ Reusable agent definitions and built-in components such as the summary agent.
ai/ Provider, model, tokenizer, request, and response abstractions, plus Gemini and Mistral.
context/ Prompt construction, parts, rendering, messages, and conversation interfaces.
context/history Persisted history sources and optional history summarization.
loop/ Model/tool execution loop and tool helpers.
testutil/ Mocks used by tests.
</summary>
The agent package turns reusable configuration into independent loop runs:
Definition combines a name, model, tools, prompt factory, limits, optional tokenizer override, optional tool-response preprocessor, and ordered stream middleware.tool_definitions source placed before application context sources.Prompt builds a context.PromptBuilder for one RunInput.RunInput carries an ID, structured PromptInput, per-run output-token override, and metadata. PromptInput separates genuine user content from named machine context.Limits configures maximum loop iterations, retries, and default output tokens.Agent is created with agent.New; NewRun returns a Workflow, and Workflow.Run streams the loop through each configured middleware.AgentMiddleware adapts an ordinary agent with preserve, append, or replace output behavior. Workflow.Result exposes the primary result, final output, and named middleware stages.The agent/summary package is a built-in component. summary.Definition returns a reusable agent definition, while summary.New returns a Summarizer that runs that agent and can be attached to a history source.
</details>
<details>
<summary>
</summary>
Agent.NewRun creates a single-use Workflow. Calling Workflow.Run starts the primary loop and passes its stream through every entry in Definition.Middleware in declaration order. Callers must consume the token, status, and error channels. After they close, Workflow.Result() contains the immutable primary result, the final visible output, accumulated errors, and named middleware stages.
An ordinary agent can become middleware with NewAgentMiddleware. By default it receives the current visible text as named upstream_output context, plus the original run ID and metadata. Set AgentMiddlewareConfig.MapInput to deliberately project the typed upstream WorkflowResult into a different RunInput:
- PreserveOutput streams the upstream output unchanged and keeps the nested agent result only in WorkflowResult.Stages. - AppendOutput streams the upstream output, then emits the nested agent output after that stage completes successfully. - ReplaceOutput buffers the upstream output and emits the nested agent output only after the stage completes successfully.
Failed append and replace stages leave the upstream output unchanged. An agent used through NewAgentMiddleware cannot define middleware of its own; compose stages on the parent workflow instead.
Agent middleware runs only after a successful upstream result by default. Set AgentMiddlewareConfig.ShouldRun to implement policies such as failure auditing. Nested-agent errors are sent through the workflow error channel by default. Set ErrorPolicy: RecordError for best-effort stages whose failures should remain in StageResult.Result.Errors without failing the surrounding workflow.
For transformations that do not require another agent, use MiddlewareFunc:
passthrough := agent.MiddlewareFunc(func(
ctx context.Context,
run *agent.MiddlewareContext,
upstream agent.Stream,
) agent.Stream {
// A custom middleware owns all three streams. Returning upstream is a
// zero-overhead pass-through; a transformer may return replacement channels.
return upstream
})
assistant := agent.New(agent.Definition{
Name: "assistant",
Model: model,
Prompt: assistantPrompt,
Middleware: []agent.Middleware{passthrough},
})
MiddlewareContext.Result() returns a concurrency-safe snapshot for custom middleware. Complete becomes true only after the final workflow streams close.
Set Definition.DebugSink to receive structured agent lifecycle events for run creation, workflow start/completion, primary completion, and middleware start/skip/success/failure. Agent execution also emits agent.run.create, agent.workflow.run, and agent.middleware.run OpenTelemetry spans. Event payloads contain counts and policy names by default; input and output text are included only when DebugSink.IncludeSensitiveData() returns true.
</details>
<details>
<summary>
高质量的AI工作流框架,易于使用
该工具使用 LGPL-2.1 协议,商用场景请仔细阅读协议条款,必要时咨询法律意见。
AI Skill Hub 为第三方内容聚合平台,本页面信息基于公开数据整理,不对工具功能和质量作任何法律背书。
建议在沙箱或测试环境中充分验证后,再部署至生产环境,并做好必要的安全评估。
⚠️ LGPL 2.1 — 弱 Copyleft,可动态链接到商业软件,但修改库本身须开源。
经综合评估,GAI 在Agent工作流赛道中表现稳健,质量优秀。如果你已有明确的使用需求,可以直接上手体验;如果还在评估阶段,建议对比同类工具后再做决策。
| 原始名称 | gai |
| 原始描述 | 开源AI工作流:🤖 GAI is a flexible Go framework for building agent-style applications on top o。⭐8 · Go |
| Topics | AIGo工作流 |
| GitHub | https://github.com/lace-ai/gai |
| License | LGPL-2.1 |
| 语言 | Go |
收录时间:2026-06-03 · 更新时间:2026-06-05 · License:LGPL-2.1 · AI Skill Hub 不对第三方内容的准确性作法律背书。
选择 Agent 类型,复制安装指令后粘贴到对应客户端