e071084ebe
govulncheck / govulncheck (push) Has been cancelled
Lint / golangci-lint (push) Has been cancelled
Run Tests / Unit Tests (push) Has been cancelled
Run Tests / Etcd Integration Tests (push) Has been cancelled
Harness (E2E) / Harnesses (mock LLM) (push) Has been cancelled
Harness (E2E) / Provider harnesses (live LLM conformance) (push) Has been cancelled
184 lines
5.5 KiB
Markdown
184 lines
5.5 KiB
Markdown
---
|
|
layout: blog
|
|
title: "micro chat: Talk to Your Services"
|
|
permalink: /blog/10
|
|
description: "Introducing micro chat — an interactive CLI that discovers your services, turns them into tools, and lets you orchestrate them through natural language."
|
|
---
|
|
|
|
# micro chat: Talk to Your Services
|
|
|
|
<img src="/images/generated/developer-experience.jpg" alt="micro chat terminal" style="width: 100%; border-radius: 8px; margin: 1rem 0 1.5rem;" />
|
|
|
|
*May 29, 2026 • By the Go Micro Team*
|
|
|
|
We built `micro chat` — a CLI that lets you talk to your microservices through an LLM. It discovers every service in the registry, exposes each endpoint as a tool, and lets a model decide which RPCs to call based on what you ask.
|
|
|
|
```bash
|
|
ANTHROPIC_API_KEY=sk-ant-... micro chat --provider anthropic
|
|
|
|
> list all users
|
|
→ called users_Users_List({})
|
|
There are 3 users: Alice, Bob, and Charlie.
|
|
|
|
> send a welcome email to Alice
|
|
→ called email_Email_Send({"to":"alice@example.com","template":"welcome"})
|
|
Done, welcome email sent to Alice.
|
|
|
|
> how many orders were placed this week?
|
|
→ called orders_Orders_Count({"since":"2026-05-22"})
|
|
There were 47 orders placed this week.
|
|
```
|
|
|
|
No glue code. No API wrappers. No tool definitions. You write normal Go services with doc comments, and `micro chat` turns them into things an LLM can call.
|
|
|
|
## How It Works
|
|
|
|
Three building blocks, stacked:
|
|
|
|
**1. `ai.Tools`** discovers services from the registry and creates typed tool definitions:
|
|
|
|
```go
|
|
tools := ai.NewTools(service.Registry())
|
|
discovered, _ := tools.Discover()
|
|
// discovered = []ai.Tool with name, description, parameters for each endpoint
|
|
```
|
|
|
|
**2. `ai.History`** tracks the conversation across turns so the LLM has context:
|
|
|
|
```go
|
|
hist := ai.NewHistory(50)
|
|
resp, _ := m.Generate(ctx, &ai.Request{Prompt: "list all users", Tools: discovered, Messages: hist.Messages()})
|
|
// Next prompt remembers this exchange
|
|
```
|
|
|
|
**3. `ai.Model`** calls the LLM. Seven providers, same interface:
|
|
|
|
```go
|
|
m := ai.New("anthropic", ai.WithAPIKey(key))
|
|
// or: "openai", "gemini", "atlascloud", "groq", "mistral", "together"
|
|
```
|
|
|
|
`micro chat` just wires these together with a REPL loop. The whole command is ~170 lines.
|
|
|
|
## Multi-Turn Conversations
|
|
|
|
`micro chat` remembers context across turns. You can ask follow-up questions without repeating yourself:
|
|
|
|
```
|
|
> list all users
|
|
There are 3 users: Alice (admin), Bob (user), Charlie (user).
|
|
|
|
> which ones are admins?
|
|
Alice is the only admin.
|
|
|
|
> change Bob's role to admin too
|
|
→ called users_Users_Update({"id":"bob-123","role":"admin"})
|
|
Done. Bob is now an admin.
|
|
```
|
|
|
|
Type `reset` to clear the conversation history and start fresh. The history limit is 50 messages by default — old messages are dropped FIFO when you hit the limit.
|
|
|
|
## Using It
|
|
|
|
Install or update the CLI:
|
|
|
|
```bash
|
|
go install go-micro.dev/v5/cmd/micro@latest
|
|
```
|
|
|
|
Start your services:
|
|
|
|
```bash
|
|
micro run
|
|
```
|
|
|
|
Chat with them:
|
|
|
|
```bash
|
|
# With Anthropic Claude
|
|
ANTHROPIC_API_KEY=sk-ant-... micro chat --provider anthropic
|
|
|
|
# With OpenAI
|
|
OPENAI_API_KEY=sk-... micro chat --provider openai
|
|
|
|
# With Atlas Cloud
|
|
ATLASCLOUD_API_KEY=... micro chat --provider atlascloud
|
|
|
|
# With any provider via base URL
|
|
micro chat --provider openai --base_url https://api.groq.com/openai --api_key $KEY
|
|
```
|
|
|
|
### Single Prompt Mode
|
|
|
|
For scripting or one-shot queries, use `--prompt`:
|
|
|
|
```bash
|
|
micro chat --provider anthropic --prompt "list all services"
|
|
```
|
|
|
|
### Environment Variables
|
|
|
|
If you don't want to pass flags every time:
|
|
|
|
```bash
|
|
export MICRO_AI_PROVIDER=anthropic
|
|
export ANTHROPIC_API_KEY=sk-ant-...
|
|
micro chat
|
|
```
|
|
|
|
## What Makes It Work
|
|
|
|
The key insight is that go-micro services are **already described**. The registry stores endpoint names, request/response types, and field metadata. Doc comments on handlers become tool descriptions. `@example` tags provide usage hints to the LLM.
|
|
|
|
```go
|
|
// CreateUser creates a new user account with the given details.
|
|
// @example {"name": "Alice", "email": "alice@example.com", "role": "admin"}
|
|
func (h *Users) CreateUser(ctx context.Context, req *pb.CreateRequest, rsp *pb.CreateResponse) error {
|
|
// ...
|
|
}
|
|
```
|
|
|
|
The `ai.Tools` package reads all of this from the registry and translates it into the tool format that LLMs understand. The better your doc comments, the better the LLM uses your services.
|
|
|
|
## Using It Programmatically
|
|
|
|
`micro chat` is a CLI, but the building blocks work in your own code:
|
|
|
|
```go
|
|
import (
|
|
"go-micro.dev/v5/ai"
|
|
|
|
_ "go-micro.dev/v5/ai/anthropic"
|
|
)
|
|
|
|
tools := ai.NewTools(service.Registry())
|
|
discovered, _ := tools.Discover()
|
|
|
|
m := ai.New("anthropic",
|
|
ai.WithAPIKey(key),
|
|
ai.WithTools(tools),
|
|
)
|
|
|
|
hist := ai.NewHistory(50)
|
|
resp, _ := m.Generate(ctx, &ai.Request{Prompt: userInput, Tools: discovered, Messages: hist.Messages()})
|
|
fmt.Println(resp.Answer)
|
|
```
|
|
|
|
This is the same code `micro chat` runs internally. Use it to add LLM-powered orchestration to any service.
|
|
|
|
## What's Next
|
|
|
|
`micro chat` is the interactive version. `micro flow` is the event-driven version — same building blocks, but triggered by broker events instead of human input. See the [flows blog post](/blog/9) for that story.
|
|
|
|
Both are experiments in what happens when services are composable by agents, not just by code. The framework provides the building blocks. You decide how to use them.
|
|
|
|
---
|
|
|
|
*Go Micro is an open source framework for distributed systems development. [Star us on GitHub](https://github.com/micro/go-micro).*
|
|
|
|
<div class="post-nav">
|
|
<div><a href="/blog/9">← From Chat to Flows</a></div>
|
|
<div><a href="/blog/">All Posts</a></div>
|
|
<div><a href="/blog/11">Build Your Own →</a></div>
|
|
</div>
|