All posts
· 2 min read

Architecting a Socratic AI CLI Tool with Go

How to build a terminal-based Socratic tutor in Go that guides developers by asking the right questions instead of giving direct answers.

Go AI CLI Socratic

Why Socratic AI?

Most AI coding assistants do the thinking for you. They output a chunk of copy-pasteable code, which you dump into your editor without truly understanding.

What if, instead of handing you the answer, your assistant acted like Socrates? A tutor that asks questions to guide you toward discovering the solution yourself.

In this post, we’ll build a Socratic AI assistant in Go that runs directly in your terminal. We will use the Gemini API to power the reasoning engine.

The Architecture

Here is the basic layout of our CLI application. We will use cobra for command-line parsing and promptui for terminal UI interaction.

package main

import (
	"context"
	"fmt"
	"log"
	"os"

	"github.com/google/generative-ai-go/genai"
	"google.golang.org/api/option"
)

func main() {
	ctx := context.Background()
	apiKey := os.Getenv("GEMINI_API_KEY")
	if apiKey == "" {
		log.Fatal("GEMINI_API_KEY environment variable is required")
	}

	client, err := genai.NewClient(ctx, option.WithAPIKey(apiKey))
	if err != nil {
		log.Fatalf("Failed to create Gemini client: %v", err)
	}
	defer client.Close()

	model := client.GenerativeModel("gemini-1.5-flash")
	
	// Instruct the model to act Socratic
	model.SystemInstruction = &genai.Content{
		Parts: []genai.Part{
			genai.Text("You are Socrates. Do not give direct code answers. Ask questions that guide the user."),
		},
	}

	fmt.Println("Socratic Assistant is ready. What are you building today?")
}

Running the CLI

Because this is an MDX file, we can test custom components if we want, but even simple inline code like go run main.go should render beautifully with the new theme-adaptive settings.

Let’s test our inline code contrast: Socratic CLI is powered by the Go standard library.

Happy coding!