micro--go-micro
9bed04ced0
Run Tests / Unit Tests (push) Has been cancelled
Run Tests / Etcd Integration Tests (push) Has been cancelled
goreleaser / goreleaser (push) Has been cancelled
* perf: compress hero image — 1.4MB to 80KB Resized from 1536px to 1200px, converted to JPEG at quality 80. 80KB loads instantly vs 1.4MB stalling on slower connections. https://claude.ai/code/session_01QTp4SshuVmLAvvEGJe4TJd * docs: micro run drops into interactive console One command does everything — generate, start, and chat. No separate micro chat step. The landing page shows micro run dropping straight into the > prompt. https://claude.ai/code/session_01QTp4SshuVmLAvvEGJe4TJd * feat: interactive console in micro run, -d for detached mode micro run now drops into an interactive chat console after services start. The console discovers services, exposes them as tools, and lets you talk to them through an LLM — same as micro chat but built into the run experience. - Detects MICRO_AI_PROVIDER and MICRO_AI_API_KEY from environment - Falls back to provider-specific env vars (ANTHROPIC_API_KEY, etc.) - If no API key, prints hint and blocks on Ctrl-C (no console) - -d / --detach flag skips the console (background mode) - Ctrl-C always shuts everything down Removed adopters section from README. https://claude.ai/code/session_01QTp4SshuVmLAvvEGJe4TJd --------- Co-authored-by: Claude <noreply@anthropic.com>
214 行
6.1 KiB
Markdown
214 行
6.1 KiB
Markdown
---
|
|
layout: default
|
|
---
|
|
|
|
# Getting Started
|
|
|
|
<img src="/images/generated/getting-started.png" alt="Getting started with Go Micro" style="width: 100%; border-radius: 8px; margin-bottom: 1.5rem;" />
|
|
|
|
Go Micro has three core abstractions:
|
|
|
|
| Abstraction | What | Constructor |
|
|
|-------------|------|-------------|
|
|
| **Service** | Capability — endpoints, data, business logic | `micro.New("task")` |
|
|
| **Agent** | Intelligence — manages services with an LLM | `micro.NewAgent("task-mgr")` |
|
|
| **Flow** | Orchestration — event-driven LLM triggers | `micro.NewFlow("onboard")` |
|
|
|
|
## Install
|
|
|
|
```bash
|
|
# Binary (no Go required)
|
|
curl -fsSL https://go-micro.dev/install.sh | sh
|
|
|
|
# Or with Go
|
|
go install go-micro.dev/v5/cmd/micro@v5.25.0
|
|
```
|
|
|
|
## Quick Start: Generate from a Prompt
|
|
|
|
Describe what you need. The AI designs services, writes handlers, compiles, and starts them:
|
|
|
|
```bash
|
|
micro run --prompt "task management system"
|
|
```
|
|
|
|
You'll see the design, confirm, and services + agent start:
|
|
|
|
```text
|
|
Services:
|
|
● task — Core task management
|
|
● project — Project organization
|
|
|
|
Generate? [Y/n]
|
|
|
|
Micro
|
|
Services:
|
|
● task
|
|
● project
|
|
Agents:
|
|
◆ agent
|
|
```
|
|
|
|
The interactive console lets you talk to your services immediately:
|
|
|
|
```text
|
|
> Create a project called Launch, then add a task called 'Write docs'
|
|
|
|
→ project_Project_Create({"name":"Launch"})
|
|
← {"record":{"id":"p1..."},"success":true}
|
|
→ task_Task_Create({"title":"Write docs","project_id":"p1..."})
|
|
|
|
Created project Launch and added task 'Write docs' to it.
|
|
```
|
|
|
|
The console discovers services from the registry and orchestrates across them via the agent. Use `micro run -d` for detached mode without the console, or `micro chat` as a standalone command.
|
|
|
|
## Quick Start: Write a Service
|
|
|
|
Create and run a service manually:
|
|
|
|
```bash
|
|
micro new helloworld
|
|
cd helloworld
|
|
micro run
|
|
```
|
|
|
|
Open http://localhost:8080 to see the dashboard, call endpoints, and chat with your service.
|
|
|
|
A service is a Go struct with methods. Doc comments and `@example` tags become tool descriptions for AI agents:
|
|
|
|
```go
|
|
package main
|
|
|
|
import "go-micro.dev/v5"
|
|
|
|
type Request struct {
|
|
Name string `json:"name"`
|
|
}
|
|
|
|
type Response struct {
|
|
Message string `json:"message"`
|
|
}
|
|
|
|
type Say struct{}
|
|
|
|
// Hello greets a person by name.
|
|
// @example {"name": "Alice"}
|
|
func (h *Say) Hello(ctx context.Context, req *Request, rsp *Response) error {
|
|
rsp.Message = "Hello " + req.Name
|
|
return nil
|
|
}
|
|
|
|
func main() {
|
|
service := micro.New("greeter")
|
|
service.Handle(new(Say))
|
|
service.Run()
|
|
}
|
|
```
|
|
|
|
`micro run` gives you:
|
|
- **Dashboard** at `http://localhost:8080`
|
|
- **API Gateway** at `http://localhost:8080/api/{service}/{method}`
|
|
- **Agent Playground** at `http://localhost:8080/agent`
|
|
- **MCP Tools** at `http://localhost:8080/mcp/tools`
|
|
- **Hot Reload** — auto-rebuild on file changes
|
|
|
|
Templates are available for common patterns:
|
|
|
|
```bash
|
|
micro new contacts --template crud
|
|
micro new events --template pubsub
|
|
micro new gateway --template api
|
|
```
|
|
|
|
## Building Agents
|
|
|
|
An Agent is an intelligent layer that manages one or more services:
|
|
|
|
```go
|
|
package main
|
|
|
|
import "go-micro.dev/v5"
|
|
|
|
func main() {
|
|
agent := micro.NewAgent("task-mgr",
|
|
micro.AgentServices("task", "project"),
|
|
micro.AgentPrompt("You manage tasks and projects. You understand deadlines, priorities, and assignments."),
|
|
micro.AgentProvider("anthropic"),
|
|
micro.AgentAPIKey("sk-ant-..."),
|
|
)
|
|
agent.Run()
|
|
}
|
|
```
|
|
|
|
An agent is a service — it has a proto-defined `Agent.Chat` RPC endpoint and registers in the registry like everything else. It:
|
|
- Discovers its services from the registry
|
|
- Only sees endpoints from its assigned services (scoped tools)
|
|
- Maintains conversation memory in the store (persists across restarts)
|
|
- Is callable via `micro call`, the interactive console, or any go-micro client
|
|
|
|
Use it programmatically:
|
|
|
|
```go
|
|
resp, _ := agent.Ask(ctx, "What tasks are overdue for Alice?")
|
|
fmt.Println(resp.Reply)
|
|
```
|
|
|
|
Or via the CLI:
|
|
|
|
```bash
|
|
micro agent list # list registered agents
|
|
micro call task-mgr Agent.Chat '{"message": "What tasks are overdue?"}'
|
|
```
|
|
|
|
When multiple agents are registered, the console routes to the right agent automatically.
|
|
|
|
## Event-Driven Flows
|
|
|
|
A Flow subscribes to a broker topic and triggers an LLM when events arrive. You can define flows in code or run them from the CLI.
|
|
|
|
**In code:**
|
|
|
|
```go
|
|
f := micro.NewFlow("onboard-user",
|
|
micro.FlowTrigger("events.user.created"),
|
|
micro.FlowPrompt("New user created: {{.Data}}. Send welcome email and create workspace."),
|
|
micro.FlowProvider("anthropic"),
|
|
micro.FlowAPIKey(os.Getenv("MICRO_AI_API_KEY")),
|
|
)
|
|
f.Register(service.Options().Registry, service.Options().Broker, service.Client())
|
|
```
|
|
|
|
**From the CLI:**
|
|
|
|
```bash
|
|
micro flow run --trigger events.user.created --prompt "New user: {{.Data}}. Send welcome email."
|
|
micro flow exec --prompt "Summarize all open tickets and email the report."
|
|
```
|
|
|
|
The flow discovers all services as tools and lets the LLM decide which RPCs to call in response to the event.
|
|
|
|
## CLI Workflow
|
|
|
|
| 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 flow run --trigger <topic>` | Run an event-driven flow |
|
|
| `micro flow exec --prompt "..."` | Execute a one-shot flow |
|
|
| `micro new myservice` | Scaffold a service |
|
|
| `micro call service endpoint '{}'` | Call a service or agent |
|
|
| `micro build` | Compile production binaries |
|
|
| `micro deploy user@server` | Deploy via SSH + systemd |
|
|
|
|
## Next Steps
|
|
|
|
- [AI Integration](ai-integration.html) — how services, agents, MCP, and LLMs fit together
|
|
- [Agent Design](https://github.com/micro/go-micro/blob/master/internal/docs/AGENT_DESIGN.md) — the full agent interface specification
|
|
- [MCP & AI Agents](mcp.html) — MCP gateway, tool discovery, and auth
|
|
- [Data Model](model.html) — typed persistence with CRUD and queries
|
|
- [Deployment](deployment.html) — deploy via SSH + systemd
|