micro--go-micro
cb33decd97
* feat: add plan and delegate as built-in agent tools Give agents two self-capabilities, expressed as plain tools wired into the existing tool handler — no harness or graph, consistent with "services are the only abstraction": - plan: record/update an ordered plan, persisted to store-backed memory and surfaced in the system prompt on later turns (externalized planning). - delegate: hand a self-contained subtask to another agent. Delegate-first — if the target names a registered agent it is called via RPC; otherwise a focused ephemeral sub-agent is created with agent.New + Ask in a fresh, isolated context (loads/persists no history, no built-in tools, so it cannot re-delegate). Both are added automatically to any non-ephemeral agent, so existing micro.NewAgent services and micro chat routing get them for free. Tests are hermetic (memory store + memory registry). * feat: add agent-plan-delegate example and document plan/delegate - examples/agent-plan-delegate: coordinator that plans multi-step work, creates tasks with its own tools, and delegates notification to a separate registered comms agent over RPC. - integration tests driving the full Ask loop through a fake provider: plan tool exposure + persistence, ephemeral delegation with isolated context, delegate-first RPC routing to a registered agent. - docs: README (Building Agents + features + examples), AGENT_DESIGN (Built-in Capabilities), agent-patterns guide (Pattern 9), CLAUDE.md. * docs: blog post and guide for plan & delegate - blog/17: "Plan & Delegate: Deep Agents in Go" — what the feature is, how plan and delegate work, and a runnable getting-started path. - guides/plan-delegate: reference guide with the smallest-agent snippet, plan/delegate semantics, and the multi-agent example; linked in nav. - example: auto-detect provider/key from common env vars (ANTHROPIC_API_KEY, OPENAI_API_KEY, ...) so 'export KEY && go run main.go' just works. - onboarding: getting-started paths now include go mod init / go get and a clone-and-run path, so a reader can actually run it from a cold start. * refactor: reframe plan/delegate blog and clean up sub-agent construction - blog/17 retitled "Agents That Plan and Delegate" and reframed around intent (plan = state intent, delegate = direct it), positioned as the next beat after blog 15/16 and tied to the existing store + agent RPC rather than re-announcing them. "Deep agents" now a single in-passing nod, matching how blog 14 references LangChain. - agent: add unexported newEphemeral constructor for sub-agents instead of type-asserting the public Agent interface to set an internal field; matches the options-only construction idiom used elsewhere. * feat: expose plan & delegate in the micro chat fallback Add agent.Builtins(opts...) — returns the built-in tools plus a handler, so the plan/delegate capabilities can be wired into a tool loop that isn't a running Agent. micro chat's direct-service fallback now reuses it (single source of truth, no duplicated handler logic), so planning and delegation are available there too, not just for registered agents. Adds a test for the accessor; notes CLI availability in the guide. --------- Co-authored-by: Claude <noreply@anthropic.com>
95 行
2.7 KiB
Markdown
95 行
2.7 KiB
Markdown
# Go Micro Examples
|
|
|
|
This directory contains runnable examples demonstrating various go-micro features and patterns.
|
|
|
|
## Quick Start
|
|
|
|
Each example can be run with `go run .` from its directory.
|
|
|
|
## Examples
|
|
|
|
### [hello-world](./hello-world/)
|
|
Basic RPC service demonstrating core concepts:
|
|
- Service creation and registration
|
|
- Handler implementation
|
|
- Client calls
|
|
- Health checks
|
|
|
|
**Run it:**
|
|
```bash
|
|
cd hello-world
|
|
go run .
|
|
```
|
|
|
|
### [web-service](./web-service/)
|
|
HTTP web service with service discovery:
|
|
- HTTP handlers
|
|
- Service registration
|
|
- Health checks
|
|
- JSON REST API
|
|
|
|
**Run it:**
|
|
```bash
|
|
cd web-service
|
|
go run .
|
|
```
|
|
|
|
### [multi-service](./multi-service/)
|
|
Multiple services in a single binary — the modular monolith pattern:
|
|
- Isolated server, client, store, and cache per service
|
|
- Shared registry and broker for inter-service communication
|
|
- Coordinated lifecycle with `service.Group`
|
|
- Start monolith, split later when you need to scale independently
|
|
|
|
**Run it:**
|
|
```bash
|
|
cd multi-service
|
|
go run .
|
|
```
|
|
|
|
### [deployment](./deployment/)
|
|
Docker Compose deployment with MCP gateway, Consul registry, and Jaeger tracing:
|
|
- Production-like architecture in one `docker-compose up`
|
|
- Standalone MCP gateway connected to service registry
|
|
- Distributed tracing with OpenTelemetry + Jaeger
|
|
|
|
### MCP Examples
|
|
|
|
See the [mcp/](./mcp/) directory for AI agent integration examples:
|
|
- **[hello](./mcp/hello/)** - Minimal MCP service (start here)
|
|
- **[crud](./mcp/crud/)** - CRUD contact book with full agent documentation
|
|
- **[workflow](./mcp/workflow/)** - Cross-service orchestration via AI agents
|
|
- **[documented](./mcp/documented/)** - All MCP features with auth scopes
|
|
|
|
### [agent-demo](./agent-demo/)
|
|
Multi-service project management app (Projects, Tasks, Team) with seed data and agent playground integration.
|
|
|
|
### [agent-plan-delegate](./agent-plan-delegate/)
|
|
The two built-in agent capabilities in a small multi-agent system:
|
|
- **plan** — an agent records an ordered plan in its store-backed memory before doing multi-step work
|
|
- **delegate** — an agent hands a subtask to another agent (over RPC if it's registered, else to an ephemeral sub-agent)
|
|
|
|
## Coming Soon
|
|
|
|
- **pubsub-events** - Event-driven architecture with NATS
|
|
- **grpc-integration** - Using go-micro with gRPC
|
|
|
|
## Prerequisites
|
|
|
|
Some examples require external dependencies:
|
|
|
|
- **NATS**: `docker run -p 4222:4222 nats:latest`
|
|
- **Consul**: `docker run -p 8500:8500 consul:latest agent -dev -ui -client=0.0.0.0`
|
|
- **Redis**: `docker run -p 6379:6379 redis:latest`
|
|
|
|
## Contributing
|
|
|
|
To add a new example:
|
|
|
|
1. Create a new directory
|
|
2. Add a descriptive README.md
|
|
3. Include working code with comments
|
|
4. Add to this index
|
|
5. Ensure it runs with `go run .`
|
|
|