Enhance AI service generation with prompt-based architecture and logic#2926
Merged
Conversation
Add AI-powered service generation: describe a system in natural
language and get real go-micro services with proto definitions,
handlers, doc comments, and MCP support.
micro new --prompt "a contact book with notes and tags" \
--provider anthropic
Generates:
contacts/ — CRUD service with name, email, phone fields
notes/ — notes linked to contacts
tags/ — tagging system
Each service gets:
proto/{name}.proto — domain model + CRUD endpoints
handler/{name}.go — in-memory store, @example tags for MCP
main.go — MCP-enabled, proper imports
go.mod + Makefile — compiles with go mod tidy + make proto
micro run --prompt does the same then starts all services.
The LLM designs the architecture (service names, fields, endpoints,
descriptions) and returns structured JSON. Code generation uses
the existing template patterns — the output is standard go-micro
code that compiles, runs, and is immediately callable via MCP
and micro chat. No AI dependency at runtime.
Rebuild the generate package so the LLM writes actual handler code with business logic, not just CRUD scaffolding. The flow is now: 1. LLM designs architecture (service names, fields, endpoints) → returns structured JSON 2. Proto, main.go, go.mod, Makefile generated deterministically from the design (guaranteed to be correct) 3. go mod tidy + make proto compiles the protos 4. LLM generates handler code with REAL business logic → given the proto, endpoint descriptions, and go-micro patterns 5. go build — does it compile? 6. If no: feed errors back to LLM, get fixed code (up to 3 attempts) 7. If yes: service is ready The handler prompt instructs the LLM to: - Use sync.RWMutex for thread-safe in-memory state - Include validation, edge cases, meaningful errors - Write doc comments with @example tags for MCP - Implement actual domain logic, not just map operations Proto generation still uses deterministic templates (CRUD + custom endpoints from the design spec) to guarantee correctness. The compile-fix loop catches LLM mistakes automatically. Both micro new --prompt and micro run --prompt use this flow.
- Fix PATH for protoc-gen-micro in child processes - Handle existing directories: skip structural files (main.go, go.mod, Makefile) if dir exists, always regenerate proto, only write placeholder handler if none exists - Allow re-running micro new --prompt on same directory to iterate on business logic without clobbering user edits Tested end-to-end: "a simple todo list with tasks and categories" generates 2 services (task-service, category-service) with real business logic (validation, toggle complete, etc.), compiles after 1 fix iteration, and runs with 6 MCP tools discovered.
Instead of requiring a --keep-handlers flag, the generate package now tracks a SHA-256 hash of each generated handler in a .micro metadata file. On re-run, if the user has edited the handler since generation, it's left untouched. Unmodified handlers are regenerated normally. https://claude.ai/code/session_01QTp4SshuVmLAvvEGJe4TJd
- Add 12 tests covering helpers, proto generation, hash tracking - Fix go.mod: write minimal module file, let go mod tidy resolve deps - Add .gitignore to prompt-generated services - Protect user-edited proto files (same hash tracking as handlers) - Add spinner during LLM calls so it doesn't look hung https://claude.ai/code/session_01QTp4SshuVmLAvvEGJe4TJd
- Ctrl+C during generation now cancels LLM calls immediately via signal-aware context; re-run picks up where it left off - Design() scans for existing services in the working directory and includes their proto definitions in the prompt, so the LLM extends the system rather than redesigning from scratch - Updated --prompt help text with usage examples on both new and run - Listed all supported providers in flag descriptions - Added discoverExisting test https://claude.ai/code/session_01QTp4SshuVmLAvvEGJe4TJd
Print endpoint names and descriptions when designing services so users see what was built. Add a micro chat hint to the run banner so users know how to interact with their services after startup. https://claude.ai/code/session_01QTp4SshuVmLAvvEGJe4TJd
go 1.22 with no explicit require caused Go to resolve sub-packages (gateway/mcp, client, server) as separate modules, hitting stale v1.18 tags. Pin to go 1.24 + require go-micro.dev/v5 v5.24.0 so go mod tidy resolves all sub-packages from the root module correctly. Tested end-to-end: 4 services generated and compiled successfully. https://claude.ai/code/session_01QTp4SshuVmLAvvEGJe4TJd
Compare proto hash before and after structure generation. If the proto didn't change and the handler wasn't edited by the user, skip go mod tidy, make proto, LLM handler generation, and compile-fix entirely. Prints "(unchanged)" instead. Reduces re-run of 4-service project from ~2 minutes to ~10 seconds. https://claude.ai/code/session_01QTp4SshuVmLAvvEGJe4TJd
Show the service design (names, endpoints) and prompt "Generate? [Y/n]" before spending LLM time on handler generation. Applies to both micro new --prompt and micro run --prompt. Default is yes (enter). https://claude.ai/code/session_01QTp4SshuVmLAvvEGJe4TJd
Each generated service had mcp.WithMCP(":3001") hardcoded, causing
port conflicts when running multiple services. Use :0 to auto-assign
a free port. micro run's central gateway handles unified MCP access.
https://claude.ai/code/session_01QTp4SshuVmLAvvEGJe4TJd
- Detect truncated LLM responses (unbalanced braces, doesn't end with '}') and retry with a conciseness hint before falling through to compile-fix - Show tool call results in micro chat output (← for success, ✗ for errors) so users can see what the LLM did - Add Result/Error fields to ToolCall, populated by Anthropic provider after tool execution - Add isTruncated tests Tested end-to-end with Anthropic: services generate, compile, start, register, respond to RPC calls, and micro chat discovers and calls tools correctly. https://claude.ai/code/session_01QTp4SshuVmLAvvEGJe4TJd
Anthropic provider: - Fix tool execution loop to properly iterate (was re-processing all tool calls instead of only new ones each round) - Clean assistant content blocks before sending back (strip 'id' from text blocks that Anthropic rejects on input) - Include tools in follow-up requests so model can make additional calls - Loop up to 10 rounds until model responds with text only Service naming: - Strip '-service' suffix from micro.New() name so services register as 'task', 'category' instead of 'taskservice', 'categoryservice' Chat: - Show tool results (← for success) and errors (✗) in chat output Tested end-to-end: create task → list tasks works as multi-step orchestration through micro chat with Anthropic Claude. https://claude.ai/code/session_01QTp4SshuVmLAvvEGJe4TJd
Covers the full micro run --prompt flow: design, generate, compile-fix, run, and chat orchestration. Positions agent-as-orchestrator as the answer to service coordination. https://claude.ai/code/session_01QTp4SshuVmLAvvEGJe4TJd
- Add 60s timeout on design, 90s on handler generation, 60s on compile-fix LLM calls so hung providers don't block forever - Bump Anthropic max_tokens from 4096 to 8192 to reduce truncation - Add TTY detection: spinner prints static message in non-TTY (CI/pipes) instead of ANSI escape codes - Tighten prompts: max 200 lines per handler, 2-4 services, 5-8 fields, explicit "services don't call each other" rule https://claude.ai/code/session_01QTp4SshuVmLAvvEGJe4TJd
Update system prompt with the list of available services. When the user asks for something no existing service can handle, the agent explains what's available and suggests the exact micro new --prompt command to create the missing service. This is the natural evolution path: start with a few services, talk to them via chat, and when the domain grows, the agent tells you what to add. Each service stays small and focused. https://claude.ai/code/session_01QTp4SshuVmLAvvEGJe4TJd
Chat agent now has a micro_generate_service tool. When the user asks for a capability that doesn't exist, the agent generates the service, compiles it, starts it as a background process, waits for registration, re-discovers tools, and uses the new endpoints immediately — all within the conversation. Service naming: design prompt now instructs LLM to return names without '-service' suffix (e.g. 'task' not 'task-service'). buildMain keeps TrimSuffix as safety net for backward compatibility. Spawned processes are cleaned up when chat exits. https://claude.ai/code/session_01QTp4SshuVmLAvvEGJe4TJd
Updated to reflect the full UX: services generate and start within the chat conversation. Added the shipping example showing the agent creating a service mid-conversation. Removed -service suffix from all examples. Tightened the narrative around agent-as-orchestrator. https://claude.ai/code/session_01QTp4SshuVmLAvvEGJe4TJd
Storage: generated handlers now use go-micro's store package instead of in-memory maps. Data persists across restarts. The handler prompt includes store API examples so the LLM generates correct store usage. README: added "Generate From a Prompt" section with micro run --prompt and micro chat examples, linking to blog post 13. Watcher: micro run now scans for new service directories every 5s. When micro chat generates a service, micro run detects the new directory, builds it, starts it, and adds it to the watcher — fully automatic. Added AddDir/Dirs methods to the watcher. Blog: updated post 13 with persistent storage example and watcher note. https://claude.ai/code/session_01QTp4SshuVmLAvvEGJe4TJd
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.