docs: make Chinese README the default
govulncheck / govulncheck (push) Has been cancelled
Harness (E2E) / Harnesses (mock LLM) (push) Has been cancelled
Harness (E2E) / Provider harnesses (live LLM conformance) (push) Has been cancelled
Lint / golangci-lint (push) Has been cancelled
Run Tests / Etcd Integration Tests (push) Has been cancelled
Run Tests / Unit Tests (push) Has been cancelled
govulncheck / govulncheck (push) Has been cancelled
Harness (E2E) / Harnesses (mock LLM) (push) Has been cancelled
Harness (E2E) / Provider harnesses (live LLM conformance) (push) Has been cancelled
Lint / golangci-lint (push) Has been cancelled
Run Tests / Etcd Integration Tests (push) Has been cancelled
Run Tests / Unit Tests (push) Has been cancelled
This commit is contained in:
@@ -1,14 +1,20 @@
|
||||
<!-- WEHUB_ZH_README -->
|
||||
> [!NOTE]
|
||||
> 本文档由 WeHub 基于上游 README 翻译整理,属于社区翻译,非官方中文文档。
|
||||
> [English](./README.en.md) · [原始项目](https://github.com/micro/go-micro) · [上游 README](https://github.com/micro/go-micro/blob/HEAD/README.md)
|
||||
> 原作者、版权与许可证归属以原始项目及本仓库 LICENSE 文件为准。
|
||||
|
||||
# Go Micro [](https://pkg.go.dev/go-micro.dev/v6?tab=doc) [](https://discord.gg/G8Gk5j3uXr)
|
||||
|
||||
Go Micro is an **agent harness** and service framework for Go.
|
||||
Go Micro 是一个面向 Go 的 **agent harness(智能体运行时框架)** 与服务框架。
|
||||
|
||||
**Community:** questions, ideas, or just want to build alongside us? [Join the Discord](https://discord.gg/G8Gk5j3uXr).
|
||||
**社区:** 有问题、有想法,或想与我们一起构建?[加入 Discord](https://discord.gg/G8Gk5j3uXr).
|
||||
|
||||
A harness is the runtime around an agent: the tools it can call, the memory it keeps, the guardrails that bound it, the workflows that trigger it, the services it depends on, and the protocols other agents use to reach it.
|
||||
Harness 是围绕智能体的运行时:它能调用的工具、它保留的记忆、约束它的护栏、触发它的工作流、它依赖的服务,以及其他智能体与之通信所使用的协议。
|
||||
|
||||
Go Micro gives you the harness as Go code. Build an agent and it gets a model, memory, tools, planning, delegation, guardrails, and service discovery; it is reachable over [MCP](https://modelcontextprotocol.io/) and [A2A](https://a2a-protocol.org). Write services and every endpoint becomes an AI-callable tool. Orchestrate the deterministic parts with durable flows. Agents, services, and flows share one runtime because an agent is a distributed system, and building one is building a service.
|
||||
Go Micro 以 Go 代码的形式提供该 harness。构建一个智能体即可获得模型、记忆、工具、规划、委派、护栏与服务发现;可通过 [MCP](https://modelcontextprotocol.io/) 和 [A2A](https://a2a-protocol.org). 被访问。编写服务后,每个端点都会成为 AI 可调用的工具。用持久化 flow 编排确定性部分。智能体、服务与 flow 共享同一运行时,因为智能体本质上是一个分布式系统,构建智能体就是在构建服务。
|
||||
|
||||
## Sponsors
|
||||
## 赞助商
|
||||
|
||||
<a href="https://go-micro.dev/blog/3"><img src="https://upload.wikimedia.org/wikipedia/commons/7/78/Anthropic_logo.svg" height="26" /></a>
|
||||
|
||||
@@ -16,32 +22,32 @@ Go Micro gives you the harness as Go code. Build an agent and it gets a model, m
|
||||
|
||||
<a href="https://go-micro.dev/blog/8"><img src="https://www.atlascloud.ai/logo.svg" height="26" /></a>
|
||||
|
||||
**Want to support Go Micro and see your logo here?** [Become a sponsor](https://discord.gg/G8Gk5j3uXr) — reach out on Discord.
|
||||
**想支持 Go Micro 并在此展示你的 logo?** [成为赞助商](https://discord.gg/G8Gk5j3uXr) — 可通过 Discord 联系。
|
||||
|
||||
## Commercial Support
|
||||
## 商业支持
|
||||
|
||||
Running Go Micro in production, or building on it and want help? Paid **support, consulting, training, and retainers** are available directly from the maintainer — and they're what keep the project maintained. See [**Support**](SUPPORT.md) for the tiers, or [open a request](https://github.com/micro/go-micro/issues/new?template=commercial_support.md).
|
||||
要在生产环境运行 Go Micro,或基于它进行开发并需要帮助?可直接向维护者购买 **支持、咨询、培训与 retainer(长期服务)** — 这些也是项目得以持续维护的支撑。详见 [**Support**](SUPPORT.md) 中的层级说明,或 [提交请求](https://github.com/micro/go-micro/issues/new?template=commercial_support.md).
|
||||
|
||||
## Contents
|
||||
## 目录
|
||||
|
||||
- [Quick Start](#quick-start)
|
||||
- [First agent on-ramp](#first-agent-on-ramp)
|
||||
- [Why an Agent Harness](#why-an-agent-harness)
|
||||
- [Writing Services](#writing-services)
|
||||
- [Building Agents](#building-agents) — [Plan & Delegate](#plan--delegate), [Pluggable](#batteries-included-pluggable), [Paid tools (x402)](#paid-tools-x402), [A2A](#reachable-by-other-agents-a2a)
|
||||
- [Features](#features)
|
||||
- [快速开始](#quick-start)
|
||||
- [首个智能体入门路径](#first-agent-on-ramp)
|
||||
- [为何需要 Agent Harness](#why-an-agent-harness)
|
||||
- [编写服务](#writing-services)
|
||||
- [构建智能体](#building-agents) — [规划与委派](#plan--delegate)、[可插拔](#batteries-included-pluggable)、[付费工具 (x402)](#paid-tools-x402)、[A2A](#reachable-by-other-agents-a2a)
|
||||
- [功能特性](#features)
|
||||
- [CLI](#cli)
|
||||
- [Autonomous improvement loop](#autonomous-improvement-loop)
|
||||
- [Multi-Service Projects](#multi-service-projects)
|
||||
- [Data Model](#data-model)
|
||||
- [AI Providers](#ai-providers)
|
||||
- [Examples](#examples)
|
||||
- [Commercial Support](#commercial-support)
|
||||
- [Docs](#docs)
|
||||
- [自主改进循环](#autonomous-improvement-loop)
|
||||
- [多服务项目](#multi-service-projects)
|
||||
- [数据模型](#data-model)
|
||||
- [AI 提供商](#ai-providers)
|
||||
- [示例](#examples)
|
||||
- [商业支持](#commercial-support)
|
||||
- [文档](#docs)
|
||||
|
||||
## Quick Start
|
||||
## 快速开始
|
||||
|
||||
Install the CLI:
|
||||
安装 CLI:
|
||||
|
||||
```bash
|
||||
# Binary (no Go required)
|
||||
@@ -51,11 +57,11 @@ curl -fsSL https://go-micro.dev/install.sh | sh
|
||||
go install go-micro.dev/v6/cmd/micro@latest
|
||||
```
|
||||
|
||||
If install or `PATH` checks fail, use the [install troubleshooting guide](internal/website/docs/guides/install-troubleshooting.md) before scaffolding your first service.
|
||||
如果安装或 `PATH` 检查失败,在搭建第一个服务之前,请先参阅 [安装故障排除指南](internal/website/docs/guides/install-troubleshooting.md)。
|
||||
|
||||
### Fastest start — no API key
|
||||
### 最快上手 — 无需 API key
|
||||
|
||||
Scaffold a service, run it, call it:
|
||||
搭建服务、运行并调用:
|
||||
|
||||
```bash
|
||||
micro new helloworld
|
||||
@@ -63,95 +69,85 @@ cd helloworld
|
||||
micro run
|
||||
```
|
||||
|
||||
Then in another terminal:
|
||||
然后在另一个终端中:
|
||||
|
||||
```bash
|
||||
curl -X POST http://localhost:8080/api/helloworld/Helloworld.Call \
|
||||
-H 'Content-Type: application/json' -d '{"name":"World"}'
|
||||
```
|
||||
|
||||
This install → scaffold → run → call path is covered by no-secret CI harnesses. To
|
||||
verify just the local installer and first-run CLI boundaries without network
|
||||
access or provider keys, use:
|
||||
这条 安装 → 搭建 → 运行 → 调用 路径由无密钥 CI harness 覆盖。若要在无网络访问或提供商密钥的情况下,仅验证本地安装器与首次运行 CLI 边界,请使用:
|
||||
|
||||
```bash
|
||||
make install-smoke
|
||||
```
|
||||
|
||||
To verify the focused CLI inner-loop contract — scaffold → run/chat/inspect → deploy dry-run — use:
|
||||
若要验证聚焦的 CLI 内循环契约 — 搭建 → 运行/聊天/检查 → 部署 dry-run — 请使用:
|
||||
|
||||
```bash
|
||||
make inner-loop
|
||||
```
|
||||
|
||||
To run only the ordered [0→hero services → agents → workflows transcript](internal/website/docs/guides/zero-to-hero.md) that CI guards, use:
|
||||
若仅运行 CI 守护的有序 [0→hero 服务 → 智能体 → 工作流 脚本](internal/website/docs/guides/zero-to-hero.md),请使用:
|
||||
|
||||
```bash
|
||||
make zero-to-hero-transcript
|
||||
```
|
||||
|
||||
To run the broader local contract (including that transcript, chat/inspect CLI boundaries, and deploy dry-run), use:
|
||||
若要运行更广泛的本地契约(包括该脚本、聊天/检查 CLI 边界以及部署 dry-run),请使用:
|
||||
|
||||
```bash
|
||||
make harness
|
||||
```
|
||||
|
||||
### First agent on-ramp
|
||||
### 首个智能体入门路径
|
||||
|
||||
After install and the first `micro new`/`micro run` smoke check, take the
|
||||
walkable agent path in this order:
|
||||
完成安装并进行首次 `micro new`/`micro run` 冒烟检查后,按以下顺序走可逐步跟进的智能体路径:
|
||||
|
||||
1. [Install troubleshooting](internal/website/docs/guides/install-troubleshooting.md) — verify the binary installer or `go install`, `PATH`, `micro --version`, and the no-secret smoke path before agent work.
|
||||
1. [安装故障排除](internal/website/docs/guides/install-troubleshooting.md) — 在开始智能体相关工作前,验证二进制安装器或 `go install`、`PATH`、`micro --version`,以及无密钥冒烟路径。
|
||||
|
||||
Run `make docs-wayfinding` to verify the focused no-secret docs/CLI contract that keeps these README and website commands aligned with the installed CLI.
|
||||
运行 `make docs-wayfinding` 以验证聚焦的无密钥 docs/CLI 契约,确保本 README 与网站命令与已安装的 CLI 保持一致。
|
||||
|
||||
2. `micro agent demo` — print the provider-free first-agent demo command and next docs steps from the installed CLI.
|
||||
3. `micro agent quickcheck` (or `micro agent debug`) — when scaffold → run → chat → inspect stalls, print the short recovery map before you dive into the full debugging guide.
|
||||
4. `micro examples` — print the maintained provider-free runnable examples in copy/paste order.
|
||||
5. `micro zero-to-hero` — print the maintained one-command no-secret lifecycle harness and runnable examples.
|
||||
6. [Examples wayfinding index](examples/INDEX.md) — choose the smallest no-secret first-agent, maintained [0→hero support reference](examples/support/), and next interop examples from one map.
|
||||
7. [Smallest first-agent example](examples/first-agent/) — run one service-backed agent with a mock model and no provider key.
|
||||
8. [No-secret first-agent transcript](internal/website/docs/guides/no-secret-first-agent.md) — run the
|
||||
maintained support agent with a mock model and see services → agents → workflows succeed without a key.
|
||||
9. [Your First Agent](internal/website/docs/guides/your-first-agent.md) — build a
|
||||
service-backed agent and talk to it with `micro chat`.
|
||||
10. [Debugging your agent](internal/website/docs/guides/debugging-agents.md) — use
|
||||
`micro agent preflight` before `micro run`, `micro agent doctor` after `micro run`,
|
||||
then `micro chat` and `micro inspect agent <name>` to recover run history, memory,
|
||||
and provider checks when the first conversation does something unexpected.
|
||||
11. [0→hero Reference](internal/website/docs/guides/zero-to-hero.md) — complete the
|
||||
services → agents → workflows loop with scaffold, run, chat, inspect, flow
|
||||
history, and deploy dry-run commands that match the maintained harness.
|
||||
2. `micro agent demo` — 从已安装的 CLI 打印无需提供商的首个智能体演示命令及后续文档步骤。
|
||||
3. `micro agent quickcheck`(或 `micro agent debug`)— 当 搭建 → 运行 → 聊天 → 检查 流程卡住时,在深入完整调试指南前,先打印简短恢复路线图。
|
||||
4. `micro examples` — 按可复制/粘贴顺序打印维护中的、无需提供商的可运行示例。
|
||||
5. `micro zero-to-hero` — 打印维护中的一条命令无密钥生命周期 harness 与可运行示例。
|
||||
6. [示例导航索引](examples/INDEX.md) — 从一张地图中选择最小的无密钥首个智能体示例、维护中的 [0→hero 支持参考](examples/support/),以及后续互操作示例。
|
||||
7. [最小首个智能体示例](examples/first-agent/) — 使用 mock 模型且无需提供商密钥,运行一个由服务支撑的智能体。
|
||||
8. [无密钥首个智能体脚本](internal/website/docs/guides/no-secret-first-agent.md) — 使用 mock 模型运行维护中的支持智能体,在无密钥情况下见证 服务 → 智能体 → 工作流 成功。
|
||||
9. [你的第一个智能体](internal/website/docs/guides/your-first-agent.md) — 构建一个由服务支撑的智能体,并通过 `micro chat` 与之对话。
|
||||
10. [调试你的智能体](internal/website/docs/guides/debugging-agents.md) — 在 `micro run` 之前使用 `micro agent preflight`,在 `micro run` 之后使用 `micro agent doctor`,
|
||||
然后使用 `micro chat` 和 `micro inspect agent <name>` 恢复运行历史、记忆
|
||||
以及提供商检查,以应对首次对话出现意外行为的情况。
|
||||
11. [0→hero 参考](internal/website/docs/guides/zero-to-hero.md) — 通过与服务维护 harness 一致的 搭建、运行、聊天、检查、flow
|
||||
历史与部署 dry-run 命令,完成 服务 → 智能体 → 工作流 循环。
|
||||
|
||||
### Autonomous improvement loop
|
||||
### 自主改进循环
|
||||
|
||||
Want the same services → agents → workflows lifecycle applied to your
|
||||
repository? `micro loop` scaffolds the autonomous improvement loop used by Go
|
||||
Micro itself: a North Star, ranked issue queue, role prompts, GitHub Actions
|
||||
workflows, and verification for CI-gated PRs.
|
||||
想将同样的 服务 → 智能体 → 工作流 生命周期应用到你的仓库?`micro loop` 会搭建 Go
|
||||
Micro 自身使用的自主改进循环:North Star、排序后的问题队列、角色提示词、GitHub Actions
|
||||
工作流,以及面向 CI 门禁 PR 的验证。
|
||||
|
||||
```bash
|
||||
micro loop init --roles all
|
||||
micro loop verify
|
||||
```
|
||||
|
||||
Before turning on the schedule, configure a dispatch token such as
|
||||
`CODEX_TRIGGER_TOKEN`, protect the default branch with required CI checks
|
||||
(`go build ./...`, `go test ./...`, and `golangci-lint run ./...` for this
|
||||
repository), and seed `.github/loop/PRIORITIES.md` with one scoped issue per
|
||||
increment. See the [`micro loop` quickstart](internal/website/docs/guides/micro-loop.md)
|
||||
for the setup checklist and operating model.
|
||||
在启用定时任务之前,请配置 dispatch token,例如
|
||||
`CODEX_TRIGGER_TOKEN`,用必需的 CI 检查保护默认分支
|
||||
(对本仓库为 `go build ./...`、`go test ./...` 和 `golangci-lint run ./...`),
|
||||
并在每个增量中为 `.github/loop/PRIORITIES.md` 填入一个范围明确的问题。设置清单与运行模型请参阅 [`micro loop` 快速开始](internal/website/docs/guides/micro-loop.md)。
|
||||
|
||||
### Generate from a prompt — with an LLM key
|
||||
### 通过提示词生成 — 需要 LLM key
|
||||
|
||||
Set a provider key, describe what you want, and the AI designs services, writes handlers, compiles, and starts them:
|
||||
设置提供商密钥,描述你的需求,AI 会设计服务、编写 handler、编译并启动它们:
|
||||
|
||||
```bash
|
||||
export ANTHROPIC_API_KEY=sk-ant-... # or OPENAI_API_KEY, GEMINI_API_KEY, ...
|
||||
micro run --prompt "a task management system with categories" --provider anthropic
|
||||
```
|
||||
|
||||
The AI designs the architecture, you review it, then it generates handlers with real business logic, compiles them, and starts them:
|
||||
AI 设计架构,你进行评审,随后它会生成包含真实业务逻辑的 handler、编译并启动:
|
||||
|
||||
```
|
||||
Services:
|
||||
@@ -168,7 +164,7 @@ Micro
|
||||
◆ agent
|
||||
```
|
||||
|
||||
Then talk to your services from the console:
|
||||
然后在控制台中与你的服务对话:
|
||||
|
||||
```
|
||||
> Create a project called Launch, then add three tasks to it
|
||||
@@ -182,7 +178,7 @@ Then talk to your services from the console:
|
||||
Created project Launch and added three tasks to it.
|
||||
```
|
||||
|
||||
When you need a capability that doesn't exist, the agent generates a new service mid-conversation:
|
||||
当你需要尚不存在的能力时,代理会在对话过程中生成一项新服务:
|
||||
|
||||
```
|
||||
> I need to track shipping. Create a shipment for order 123 to London.
|
||||
@@ -195,25 +191,25 @@ When you need a capability that doesn't exist, the agent generates a new service
|
||||
Created shipment for order 123 going to London.
|
||||
```
|
||||
|
||||
Edit the generated code by hand at any time — re-running preserves your changes. [Read more](https://go-micro.dev/blog/13).
|
||||
你可以随时手动编辑生成的代码——重新运行会保留你的修改。[了解更多](https://go-micro.dev/blog/13).
|
||||
|
||||
## Why an Agent Harness
|
||||
## 为何需要 Agent Harness
|
||||
|
||||
The first wave of agent frameworks helped developers put a model in a loop. The next problem is operating that loop: connecting it to real tools, scoping what it can touch, preserving state, routing work to specialists, recovering from failures, observing what happened, and letting other agents call it. That is harness work.
|
||||
第一波代理框架帮助开发者让模型进入循环。下一个问题是如何运营这个循环:将其连接到真实工具、限定可触及范围、保留状态、将工作路由给专家、从故障中恢复、观测发生了什么,并让其他代理调用它。这就是 harness 工作。
|
||||
|
||||
Go Micro's answer is to make the harness the same thing you already deploy:
|
||||
Go Micro 的答案是:让 harness 与你已部署的东西合二为一:
|
||||
|
||||
- **Tools are services** — endpoint metadata becomes tool schema; RPC executes the call.
|
||||
- **Agents are services** — they register, discover, load-balance, and expose `Agent.Chat`.
|
||||
- **Workflows are durable code paths** — use flows when the path is known; dispatch to agents when it is not.
|
||||
- **Safety lives at execution** — `MaxSteps`, `LoopLimit`, `ApproveTool`, and tool wrappers run where actions happen.
|
||||
- **Interop is built in** — MCP for tools, A2A for agents, x402 for paid tools.
|
||||
- **工具即服务** — 端点元数据成为工具 schema;RPC 执行调用。
|
||||
- **代理即服务** — 它们注册、发现、负载均衡,并暴露 `Agent.Chat`。
|
||||
- **工作流即持久化代码路径** — 路径已知时使用 flows;未知时分派给代理。
|
||||
- **安全落在执行层** — `MaxSteps`、`LoopLimit`、`ApproveTool` 以及工具包装器在动作发生处运行。
|
||||
- **互操作内置** — 工具用 MCP,代理用 A2A,付费工具用 x402。
|
||||
|
||||
Use Go Micro when the agent has to operate a system, not just answer a prompt.
|
||||
当代理需要操作系统而不仅是回答提示时,使用 Go Micro。
|
||||
|
||||
## Writing Services
|
||||
## 编写服务
|
||||
|
||||
Under the hood, a service is a struct with methods. Doc comments and `@example` tags become tool descriptions for AI agents automatically.
|
||||
底层而言,服务是带方法的 struct。文档注释和 `@example` 标签会自动成为 AI 代理的工具描述。
|
||||
|
||||
```go
|
||||
package main
|
||||
@@ -248,7 +244,7 @@ func main() {
|
||||
}
|
||||
```
|
||||
|
||||
Run it and everything is accessible — REST, gRPC, MCP, agent playground:
|
||||
运行后一切皆可访问——REST、gRPC、MCP、agent playground:
|
||||
|
||||
```bash
|
||||
micro run
|
||||
@@ -258,16 +254,16 @@ micro run
|
||||
# MCP Tools: http://localhost:8080/mcp/tools
|
||||
```
|
||||
|
||||
You can also scaffold a service from a template:
|
||||
你也可以从模板脚手架生成服务:
|
||||
|
||||
```bash
|
||||
micro new helloworld
|
||||
micro new contacts --template crud
|
||||
```
|
||||
|
||||
## Building Agents
|
||||
## 构建代理
|
||||
|
||||
An Agent is a service with an LLM inside it. It has a proto-defined `Agent.Chat` RPC endpoint, registers in the registry, and is callable like any service:
|
||||
代理是内置 LLM 的服务。它拥有 proto 定义的 `Agent.Chat` RPC 端点,在 registry 中注册,并可像任何服务一样被调用:
|
||||
|
||||
```go
|
||||
agent := micro.NewAgent("task-mgr",
|
||||
@@ -278,7 +274,7 @@ agent := micro.NewAgent("task-mgr",
|
||||
agent.Run()
|
||||
```
|
||||
|
||||
The agent discovers its services from the registry, scopes its tools to their endpoints, and maintains conversation memory in the store. It registers itself so `micro chat` and other agents can find it.
|
||||
代理从 registry 发现其服务,将工具限定到对应端点,并在 store 中维护对话记忆。它会自我注册,以便 `micro chat` 及其他代理能找到它。
|
||||
|
||||
```go
|
||||
// Programmatic interaction
|
||||
@@ -286,21 +282,21 @@ resp, _ := agent.Ask(ctx, "What tasks are overdue?")
|
||||
fmt.Println(resp.Reply)
|
||||
```
|
||||
|
||||
Multiple agents coordinate via RPC — each is a service with an `Agent.Chat` endpoint. `micro chat` routes to the right one.
|
||||
多个代理通过 RPC 协调——每个都是带有 `Agent.Chat` 端点的服务。`micro chat` 会路由到正确的那一个。
|
||||
|
||||
```bash
|
||||
micro agent list # list registered agents
|
||||
micro call task-mgr Agent.Chat '{"message": "What tasks are overdue?"}'
|
||||
```
|
||||
|
||||
### Plan & Delegate
|
||||
### 规划与委托(Plan & Delegate)
|
||||
|
||||
Every agent gets two built-in harness capabilities, exposed as tools — no extra setup or separate graph runtime:
|
||||
每个代理都具备两种内置 harness 能力,以工具形式暴露——无需额外设置或独立的图运行时:
|
||||
|
||||
- **`plan`** — for multi-step work, the agent records an ordered plan in its store-backed memory and stays oriented across turns.
|
||||
- **`delegate`** — the agent hands a self-contained subtask to another agent. If a registered agent already owns the relevant services, the hand-off goes over RPC to that agent; otherwise a focused, short-lived sub-agent is created for the subtask with its own isolated context.
|
||||
- **`plan`** — 对于多步骤工作,代理在其 store 支撑的记忆中记录有序计划,并在多轮对话中保持方向。
|
||||
- **`delegate`** — 代理将自包含的子任务交给另一个代理。若已注册的代理已拥有相关服务,则通过 RPC 交接给该代理;否则会为该子任务创建一个专注、短命的子代理,并配备独立隔离的上下文。
|
||||
|
||||
This keeps intelligence distributed: an agent doesn't need to know *how* to do everything, only *who* does. See [examples/agent-plan-delegate](examples/agent-plan-delegate/).
|
||||
这让智能保持分布式:代理不必知道*如何*完成一切,只需知道*谁*来做。参见 [examples/agent-plan-delegate](examples/agent-plan-delegate/)。
|
||||
|
||||
```go
|
||||
// A sub-agent is just an agent — created with New, talked to with Ask.
|
||||
@@ -308,9 +304,9 @@ This keeps intelligence distributed: an agent doesn't need to know *how* to do e
|
||||
resp, _ := agent.Ask(ctx, "Plan the launch, create the tasks, and have comms notify the owner.")
|
||||
```
|
||||
|
||||
### Batteries included, pluggable
|
||||
### 开箱即用,可插拔
|
||||
|
||||
Just as a service composes pluggable abstractions (registry, broker, store), an agent composes a **model**, **memory**, and **tools** — sane defaults out of the box, each swappable.
|
||||
正如服务组合可插拔抽象(registry、broker、store),代理组合 **model**、**memory** 和 **tools**——开箱即用的合理默认,每一项都可替换。
|
||||
|
||||
```go
|
||||
agent := micro.NewAgent("assistant",
|
||||
@@ -325,11 +321,11 @@ agent := micro.NewAgent("assistant",
|
||||
)
|
||||
```
|
||||
|
||||
**Memory** is durable and store-backed by default (Postgres, NATS KV, or file), so an agent picks up where it left off after a restart — or supply your own with `AgentMemory`. Long-running agents can opt into `AgentCompactMemory(maxMessages, keepRecent)`: older turns are collapsed into a deterministic summary, recent turns stay verbatim, and relevant archived turns are recalled on future asks without replaying the whole conversation. **Tools** are your services automatically, plus any function you register with `AgentTool`.
|
||||
**Memory(记忆)** 默认持久且由 store 支撑(Postgres、NATS KV 或 file),因此代理在重启后可从上次停下的地方继续——也可用 `AgentMemory` 提供你自己的实现。长期运行的代理可选用 `AgentCompactMemory(maxMessages, keepRecent)`:较早轮次被折叠为确定性摘要,最近轮次保持原文,相关归档轮次在未来请求时被召回,而无需重放整段对话。**Tools(工具)** 自动就是你的服务,加上你用 `AgentTool` 注册的任何函数。
|
||||
|
||||
### Paid tools (x402)
|
||||
### 付费工具(x402)
|
||||
|
||||
Every endpoint is an AI-callable tool — and it can be a *paid* tool. Go Micro supports [x402](https://x402.org), the HTTP 402 payment standard for agents, so a tool can require a stablecoin payment and an agent can settle it autonomously. It's opt-in and carries no crypto in the framework: verification is delegated to a pluggable facilitator (Coinbase, Alchemy, self-hosted), so Base and Solana are just different facilitators.
|
||||
每个端点都是 AI 可调用的工具——而且可以是*付费*工具。Go Micro 支持 [x402](https://x402.org), 面向代理的 HTTP 402 支付标准,因此工具可要求稳定币支付,代理可自主结算。这是可选功能,框架本身不携带加密货币逻辑:验证委托给可插拔的 facilitator(Coinbase、Alchemy、自托管),因此 Base 和 Solana 只是不同的 facilitator。
|
||||
|
||||
```bash
|
||||
# Charge for tool calls at the MCP gateway (off unless you set a pay-to address)
|
||||
@@ -338,84 +334,84 @@ micro mcp serve --x402_pay_to 0xYourAddress --x402_network solana --x402_amount
|
||||
micro mcp serve --x402_config x402.json
|
||||
```
|
||||
|
||||
See the [Payments (x402) guide](internal/website/docs/guides/x402-payments.md).
|
||||
参见 [Payments (x402) guide](internal/website/docs/guides/x402-payments.md)。
|
||||
|
||||
### Reachable by other agents (A2A)
|
||||
### 可被其他代理访问(A2A)
|
||||
|
||||
Within a Go Micro system, agents reach each other over RPC. To make them reachable by agents on *other* frameworks, Go Micro speaks the [Agent2Agent (A2A) protocol](https://a2a-protocol.org). The A2A gateway discovers your agents from the registry, generates an Agent Card for each from its metadata — the same way the MCP gateway derives tools from service endpoints — and translates incoming A2A tasks to the agent's `Agent.Chat` RPC. No per-agent code: register an agent and it's reachable over A2A.
|
||||
在 Go Micro 系统内,代理通过 RPC 相互访问。要让*其他*框架上的代理也能访问它们,Go Micro 使用 [Agent2Agent (A2A) protocol](https://a2a-protocol.org). A2A 网关从 registry 发现你的代理,根据其元数据为每个代理生成 Agent Card——与 MCP 网关从服务端点派生工具的方式相同——并将传入的 A2A 任务翻译为代理的 `Agent.Chat` RPC。无需为每个代理编写代码:注册代理即可通过 A2A 访问。
|
||||
|
||||
```bash
|
||||
micro a2a serve --address :4000 # gateway: expose every registered agent over A2A
|
||||
micro a2a list # agents and their Agent Card URLs
|
||||
```
|
||||
|
||||
Or skip the gateway entirely — an agent can serve its own A2A endpoint directly, handling tasks in-process:
|
||||
或者完全跳过网关——代理可直接提供自己的 A2A 端点,在进程内处理任务:
|
||||
|
||||
```go
|
||||
micro.NewAgent("task-mgr", micro.AgentServices("task"), micro.AgentA2A(":4000"))
|
||||
```
|
||||
|
||||
It works both ways. To call an agent on another framework, an `a2a.Client` is wired into the two places that hand off work: `flow.A2A(url)` as a workflow step (the cross-framework `Dispatch`), and `delegate` to an `http(s)` URL from inside an agent.
|
||||
双向皆可。要调用其他框架上的代理,`a2a.Client` 会接入两处交接工作的地方:作为工作流步骤的 `flow.A2A(url)`(跨框架的 `Dispatch`),以及从代理内部向 `http(s)` URL 发起的 `delegate`。
|
||||
|
||||
MCP exposes your services as tools; A2A exposes your agents as agents. See the [A2A guide](internal/website/docs/guides/a2a-protocol.md).
|
||||
MCP 将你的服务暴露为工具;A2A 将你的代理暴露为代理。参见 [A2A guide](internal/website/docs/guides/a2a-protocol.md)。
|
||||
|
||||
## Features
|
||||
## 功能特性
|
||||
|
||||
### AI
|
||||
|
||||
| Feature | Details |
|
||||
| 功能 | 详情 |
|
||||
|---------|---------|
|
||||
| Agents | `micro.NewAgent()` — intelligent layer that manages services |
|
||||
| Plan & delegate | Built-in agent tools — plan multi-step work, delegate subtasks to other agents |
|
||||
| Pluggable memory | Durable store-backed conversation memory by default; swap with `AgentMemory` |
|
||||
| Custom tools | `AgentTool` — give an agent any function as a tool, beyond its services |
|
||||
| Guardrails | `MaxSteps` (stop on count), `LoopLimit` (stop repeated no-progress calls), `ApproveTool` (human-in-the-loop) |
|
||||
| Tool middleware | `AgentWrapTool` — wrap tool execution for logging, metrics, or retries (like client/server wrappers) |
|
||||
| Workflows | `micro.NewFlow()` — event-driven; one step, ordered durable steps, or triggers an agent |
|
||||
| Durable execution | Checkpointed flow steps survive a crash and resume where they stopped; store-backed by default, pluggable backend |
|
||||
| MCP gateway | Every endpoint is an AI tool automatically |
|
||||
| A2A gateway | Every agent is reachable over the Agent2Agent protocol; cards generated from the registry (`micro a2a`) |
|
||||
| Payments (x402) | Opt-in per-call payments for tools via the x402 standard; pluggable facilitator (Base, Solana, …) |
|
||||
| 9 LLM providers | Anthropic, OpenAI, Gemini, Groq, Mistral, Together, Atlas Cloud, MiniMax, Ollama (local + cloud) |
|
||||
| Interactive console | `micro run` includes a chat console for talking to services |
|
||||
| Service generation | `micro run --prompt` — describe a system, get running services |
|
||||
| Agents(智能体) | `micro.NewAgent()` — 管理服务的智能层 |
|
||||
| Plan & delegate(规划与委派) | 内置 agent 工具 — 规划多步骤工作,将子任务委派给其他 agent |
|
||||
| Pluggable memory(可插拔记忆) | 默认基于持久化存储的对话记忆;可通过 `AgentMemory` 替换 |
|
||||
| Custom tools(自定义工具) | `AgentTool` — 为 agent 提供除服务之外的任意函数作为工具 |
|
||||
| Guardrails(护栏) | `MaxSteps`(按次数停止)、`LoopLimit`(停止重复的无进展调用)、`ApproveTool`(human-in-the-loop,人在回路) |
|
||||
| Tool middleware(工具中间件) | `AgentWrapTool` — 包装工具执行以实现日志、指标或重试(类似 client/server wrappers) |
|
||||
| Workflows(工作流) | `micro.NewFlow()` — 事件驱动;单步、有序持久化步骤,或触发 agent |
|
||||
| Durable execution(持久化执行) | 带检查点的流程步骤可在崩溃后存活并从停止处恢复;默认基于存储,后端可插拔 |
|
||||
| MCP gateway | 每个 endpoint 自动成为 AI 工具 |
|
||||
| A2A gateway | 每个 agent 均可通过 Agent2Agent 协议访问;卡片由 registry(`micro a2a`)生成 |
|
||||
| Payments (x402) | 通过 x402 标准按调用选择性为工具付费;facilitator 可插拔(Base、Solana 等) |
|
||||
| 9 个 LLM 提供商 | Anthropic、OpenAI、Gemini、Groq、Mistral、Together、Atlas Cloud、MiniMax、Ollama(本地 + 云端) |
|
||||
| Interactive console(交互式控制台) | `micro run` 包含与服务对话的聊天控制台 |
|
||||
| Service generation(服务生成) | `micro run --prompt` — 描述系统即可获得运行中的服务 |
|
||||
|
||||
### Framework
|
||||
### 框架
|
||||
|
||||
| Feature | Details |
|
||||
| 功能 | 详情 |
|
||||
|---------|---------|
|
||||
| Service registry | mDNS (default), Consul, etcd |
|
||||
| RPC client/server | gRPC transport, load balancing, streaming |
|
||||
| Pub/sub events | NATS, RabbitMQ, HTTP broker |
|
||||
| Key-value store | File (bbolt), Postgres, NATS KV |
|
||||
| Typed model layer | CRUD + queries, SQLite/Postgres backends |
|
||||
| Everything swappable | All abstractions are Go interfaces |
|
||||
| Service registry(服务注册) | mDNS(默认)、Consul、etcd |
|
||||
| RPC client/server | gRPC 传输、负载均衡、流式传输 |
|
||||
| Pub/sub events(发布/订阅事件) | NATS、RabbitMQ、HTTP broker |
|
||||
| Key-value store(键值存储) | File (bbolt)、Postgres、NATS KV |
|
||||
| Typed model layer(类型化模型层) | CRUD + 查询,SQLite/Postgres 后端 |
|
||||
| Everything swappable(一切皆可替换) | 所有抽象均为 Go interface |
|
||||
|
||||
### Developer experience & deployment
|
||||
### 开发者体验与部署
|
||||
|
||||
| Feature | Details |
|
||||
| 功能 | 详情 |
|
||||
|---------|---------|
|
||||
| Hot reload | `micro run` watches files, rebuilds on change |
|
||||
| Templates | `micro new --template crud/pubsub/api` |
|
||||
| One-command deploy | `micro deploy user@server` — SSH + systemd, no Docker |
|
||||
| Hot reload(热重载) | `micro run` 监听文件变更并重新构建 |
|
||||
| Templates(模板) | `micro new --template crud/pubsub/api` |
|
||||
| One-command deploy(一键部署) | `micro deploy user@server` — SSH + systemd,无需 Docker |
|
||||
|
||||
## CLI
|
||||
|
||||
| Command | Purpose |
|
||||
| 命令 | 用途 |
|
||||
|---------|---------|
|
||||
| `micro run --prompt "..."` | Generate services + agent, start with interactive console |
|
||||
| `micro run` | Dev mode: hot reload, gateway, interactive console |
|
||||
| `micro run -d` | Detached mode (no console) |
|
||||
| `micro chat` | Standalone chat (when not using micro run) |
|
||||
| `micro agent list` | List registered agents |
|
||||
| `micro new myservice` | Scaffold a service |
|
||||
| `micro call service endpoint '{}'` | Call a service or agent from the CLI |
|
||||
| `micro build` | Compile production binaries |
|
||||
| `micro deploy user@server` | Deploy via SSH + systemd |
|
||||
| `micro run --prompt "..."` | 生成服务与 agent,并启动交互式控制台 |
|
||||
| `micro run` | 开发模式:热重载、gateway、交互式控制台 |
|
||||
| `micro run -d` | 分离模式(无控制台) |
|
||||
| `micro chat` | 独立聊天(未使用 micro run 时) |
|
||||
| `micro agent list` | 列出已注册的 agent |
|
||||
| `micro new myservice` | 脚手架生成服务 |
|
||||
| `micro call service endpoint '{}'` | 从 CLI 调用服务或 agent |
|
||||
| `micro build` | 编译生产二进制文件 |
|
||||
| `micro deploy user@server` | 通过 SSH + systemd 部署 |
|
||||
|
||||
## Multi-Service Projects
|
||||
## 多服务项目
|
||||
|
||||
Run multiple services together:
|
||||
同时运行多个服务:
|
||||
|
||||
```go
|
||||
users := micro.NewService("users", micro.Address(":9001"))
|
||||
@@ -428,7 +424,7 @@ g := micro.NewGroup(users, orders)
|
||||
g.Run()
|
||||
```
|
||||
|
||||
Or use a `micro.mu` config file:
|
||||
或使用 `micro.mu` 配置文件:
|
||||
|
||||
```
|
||||
service users
|
||||
@@ -439,9 +435,9 @@ service orders
|
||||
depends users
|
||||
```
|
||||
|
||||
## Data Model
|
||||
## 数据模型
|
||||
|
||||
Typed persistence with CRUD and queries:
|
||||
类型化持久化,支持 CRUD 与查询:
|
||||
|
||||
```go
|
||||
type User struct {
|
||||
@@ -458,13 +454,13 @@ var results []*User
|
||||
db.List(ctx, &results, model.Where("email", "alice@example.com"))
|
||||
```
|
||||
|
||||
Backends: memory (default), SQLite, Postgres.
|
||||
后端:memory(默认)、SQLite、Postgres。
|
||||
|
||||
## AI Providers
|
||||
## AI 提供商
|
||||
|
||||
Swap providers with a single import — same interface everywhere:
|
||||
单次 import 即可切换提供商 — 各处使用相同 interface:
|
||||
|
||||
| Provider | Default Model |
|
||||
| 提供商 | 默认模型 |
|
||||
|----------|---------------|
|
||||
| Anthropic | `claude-sonnet-4-20250514` |
|
||||
| OpenAI | `gpt-4o` |
|
||||
@@ -481,34 +477,34 @@ m := ai.New("anthropic", ai.WithAPIKey(key))
|
||||
resp, _ := m.Generate(ctx, &ai.Request{Prompt: "hello"})
|
||||
```
|
||||
|
||||
## Examples
|
||||
## 示例
|
||||
|
||||
New to agents? Follow the [first-agent on-ramp](#first-agent-on-ramp), then use the [examples index](examples/README.md) for the full services → agents → workflows map.
|
||||
初次接触 agent?请跟随 [first-agent on-ramp](#first-agent-on-ramp),然后使用 [examples index](examples/README.md) 查看完整的 services → agents → workflows 映射。
|
||||
|
||||
- [hello-world](examples/hello-world/) — Basic RPC service
|
||||
- [multi-service](examples/multi-service/) — Multiple services in one binary
|
||||
- [mcp](examples/mcp/) — MCP integration with AI agents
|
||||
- [first-agent](examples/first-agent/) — Smallest provider-free service-backed agent
|
||||
- [agent-plan-delegate](examples/agent-plan-delegate/) — Agent planning and multi-agent delegation
|
||||
- [agent-durable](examples/agent-durable/) — Checkpoint and resume an agent run without replaying completed tool side effects
|
||||
- [grpc-interop](examples/grpc-interop/) — Call go-micro from any gRPC client
|
||||
- [hello-world](examples/hello-world/) — 基础 RPC 服务
|
||||
- [multi-service](examples/multi-service/) — 单个二进制文件中运行多个服务
|
||||
- [mcp](examples/mcp/) — 与 AI agent 的 MCP 集成
|
||||
- [first-agent](examples/first-agent/) — 最小化、无需 provider 的服务支撑型 agent
|
||||
- [agent-plan-delegate](examples/agent-plan-delegate/) — Agent 规划与多 agent 委派
|
||||
- [agent-durable](examples/agent-durable/) — 检查点与恢复 agent 运行,无需重放已完成的工具副作用
|
||||
- [grpc-interop](examples/grpc-interop/) — 从任意 gRPC 客户端调用 go-micro
|
||||
|
||||
See [all examples](examples/README.md).
|
||||
查看 [all examples](examples/README.md)。
|
||||
|
||||
## Docs
|
||||
## 文档
|
||||
|
||||
- [Getting Started](internal/website/docs/getting-started.md)
|
||||
- [AI Integration](internal/website/docs/ai-integration.md)
|
||||
- [Your First Agent](internal/website/docs/guides/your-first-agent.md)
|
||||
- [0→hero Reference](internal/website/docs/guides/zero-to-hero.md)
|
||||
- [Agents and Workflows](internal/website/docs/guides/agents-and-workflows.md)
|
||||
- [Agent Design](internal/docs/AGENT_DESIGN.md)
|
||||
- [Plan & Delegate](internal/website/docs/guides/plan-delegate.md)
|
||||
- [Agent Guardrails](internal/website/docs/guides/agent-guardrails.md)
|
||||
- [Payments (x402)](internal/website/docs/guides/x402-payments.md)
|
||||
- [MCP & AI Agents](internal/website/docs/mcp.md)
|
||||
- [Data Model](internal/website/docs/model.md)
|
||||
- [Deployment](internal/website/docs/deployment.md)
|
||||
- [Plugins](internal/website/docs/plugins.md)
|
||||
- [入门指南](internal/website/docs/getting-started.md)
|
||||
- [AI 集成](internal/website/docs/ai-integration.md)
|
||||
- [你的第一个 Agent](internal/website/docs/guides/your-first-agent.md)
|
||||
- [0→hero 参考](internal/website/docs/guides/zero-to-hero.md)
|
||||
- [Agent 与工作流](internal/website/docs/guides/agents-and-workflows.md)
|
||||
- [Agent 设计](internal/docs/AGENT_DESIGN.md)
|
||||
- [规划与委派](internal/website/docs/guides/plan-delegate.md)
|
||||
- [Agent 护栏](internal/website/docs/guides/agent-guardrails.md)
|
||||
- [支付(x402)](internal/website/docs/guides/x402-payments.md)
|
||||
- [MCP 与 AI Agent](internal/website/docs/mcp.md)
|
||||
- [数据模型](internal/website/docs/model.md)
|
||||
- [部署](internal/website/docs/deployment.md)
|
||||
- [插件](internal/website/docs/plugins.md)
|
||||
|
||||
Package reference: https://pkg.go.dev/go-micro.dev/v6
|
||||
包参考:https://pkg.go.dev/go-micro.dev/v6
|
||||
|
||||
Reference in New Issue
Block a user