Skip to content

Commit 9159d86

Browse files
committed
refactor: Update Go configuration to use 'version' instead of 'goVersion'
goVersion is redundant since it's already under language.go Signed-off-by: Eden Reich <eden.reich@gmail.com>
1 parent fca4c7b commit 9159d86

File tree

13 files changed

+108
-89
lines changed

13 files changed

+108
-89
lines changed

README.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,10 @@ spec:
145145
port: 8080
146146
debug: false
147147

148-
go:
149-
module: "github.com/example/weather-agent"
150-
goVersion: "1.21"
148+
language:
149+
go:
150+
module: "github.com/example/weather-agent"
151+
version: "1.24"
151152
```
152153
153154
### ADL Schema
@@ -159,7 +160,7 @@ The complete ADL schema includes:
159160
- **agent**: AI provider configuration (OpenAI, Anthropic, etc.)
160161
- **tools**: Function definitions with JSON schemas
161162
- **server**: HTTP server configuration
162-
- **go**: Go-specific settings
163+
- **language**: Programming language-specific settings (Go, TypeScript, etc.)
163164
164165
## Generated Project Structure
165166
@@ -277,4 +278,4 @@ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file
277278

278279
---
279280

280-
> 🤖 Powered by the [A2A (Agent-to-Agent) framework](https://github.com/inference-gateway/a2a)
281+
> 🤖 Powered by the [A2A (Agent-to-Agent) framework](https://github.com/inference-gateway/a2a)

cmd/init.go

Lines changed: 76 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -35,39 +35,39 @@ func runInit(cmd *cobra.Command, args []string) error {
3535
fmt.Println("=====================================")
3636
fmt.Println()
3737

38-
// Project name
3938
var projectName string
4039
if len(args) > 0 {
4140
projectName = args[0]
4241
} else {
4342
projectName = promptString(scanner, "Project name", "my-agent")
4443
}
4544

46-
// Create project directory
4745
projectDir := filepath.Join(".", projectName)
4846
if err := os.MkdirAll(projectDir, 0755); err != nil {
4947
return fmt.Errorf("failed to create project directory: %w", err)
5048
}
5149

52-
// Collect information interactively
5350
adl := collectADLInfo(scanner, projectName)
5451

55-
// Write ADL file
5652
adlFile := filepath.Join(projectDir, "agent.yaml")
5753
if err := writeADLFile(adl, adlFile); err != nil {
5854
return fmt.Errorf("failed to write ADL file: %w", err)
5955
}
6056

6157
fmt.Printf("\n✅ ADL file created: %s\n", adlFile)
6258

63-
// Generate project
6459
fmt.Println("🔨 Generating project structure...")
65-
66-
// Use the generate command to create the project
67-
generateCmd.Flags().Set("file", adlFile)
68-
generateCmd.Flags().Set("output", projectDir)
69-
generateCmd.Flags().Set("template", adl.getTemplate())
70-
60+
61+
if err := generateCmd.Flags().Set("file", adlFile); err != nil {
62+
return fmt.Errorf("failed to set file flag: %w", err)
63+
}
64+
if err := generateCmd.Flags().Set("output", projectDir); err != nil {
65+
return fmt.Errorf("failed to set output flag: %w", err)
66+
}
67+
if err := generateCmd.Flags().Set("template", adl.getTemplate()); err != nil {
68+
return fmt.Errorf("failed to set template flag: %w", err)
69+
}
70+
7171
if err := runGenerate(generateCmd, []string{}); err != nil {
7272
return fmt.Errorf("failed to generate project: %w", err)
7373
}
@@ -95,9 +95,9 @@ type adlData struct {
9595
} `yaml:"metadata"`
9696
Spec struct {
9797
Capabilities *struct {
98-
Streaming bool `yaml:"streaming"`
99-
PushNotifications bool `yaml:"pushNotifications"`
100-
StateTransitionHistory bool `yaml:"stateTransitionHistory"`
98+
Streaming bool `yaml:"streaming"`
99+
PushNotifications bool `yaml:"pushNotifications"`
100+
StateTransitionHistory bool `yaml:"stateTransitionHistory"`
101101
} `yaml:"capabilities,omitempty"`
102102
Agent *struct {
103103
Provider string `yaml:"provider"`
@@ -112,13 +112,15 @@ type adlData struct {
112112
Schema map[string]interface{} `yaml:"schema"`
113113
} `yaml:"tools,omitempty"`
114114
Server struct {
115-
Port int `yaml:"port"`
115+
Port int `yaml:"port"`
116116
Debug bool `yaml:"debug"`
117117
} `yaml:"server"`
118-
Go struct {
119-
Module string `yaml:"module"`
120-
GoVersion string `yaml:"goVersion"`
121-
} `yaml:"go"`
118+
Language *struct {
119+
Go *struct {
120+
Module string `yaml:"module"`
121+
Version string `yaml:"version"`
122+
} `yaml:"go,omitempty"`
123+
} `yaml:"language,omitempty"`
122124
} `yaml:"spec"`
123125
}
124126

@@ -142,16 +144,14 @@ func collectADLInfo(scanner *bufio.Scanner, projectName string) *adlData {
142144
adl.Metadata.Description = promptString(scanner, "Agent description", "A helpful AI agent")
143145
adl.Metadata.Version = promptString(scanner, "Version", "1.0.0")
144146

145-
// Agent type
146147
fmt.Println("\n🤖 Agent Type")
147148
fmt.Println("--------------")
148149
agentType := promptChoice(scanner, "Agent type", []string{"ai-powered", "minimal"}, "ai-powered")
149150

150151
if agentType == "ai-powered" {
151-
// AI configuration
152152
fmt.Println("\n🧠 AI Configuration")
153153
fmt.Println("-------------------")
154-
154+
155155
adl.Spec.Agent = &struct {
156156
Provider string `yaml:"provider"`
157157
Model string `yaml:"model"`
@@ -176,39 +176,45 @@ func collectADLInfo(scanner *bufio.Scanner, projectName string) *adlData {
176176
}
177177

178178
adl.Spec.Agent.Model = promptString(scanner, "Model", defaultModel)
179-
adl.Spec.Agent.SystemPrompt = promptString(scanner, "System prompt (optional)", "")
180-
179+
180+
for {
181+
systemPrompt := promptString(scanner, "System prompt", "You are a helpful AI assistant.")
182+
if systemPrompt != "" {
183+
adl.Spec.Agent.SystemPrompt = systemPrompt
184+
break
185+
}
186+
fmt.Println("⚠️ System prompt is required for AI-powered agents. Please provide a system prompt.")
187+
}
188+
181189
if maxTokensStr := promptString(scanner, "Max tokens (optional, press enter to skip)", ""); maxTokensStr != "" {
182190
if maxTokens, err := strconv.Atoi(maxTokensStr); err == nil {
183191
adl.Spec.Agent.MaxTokens = maxTokens
184192
}
185193
}
186-
194+
187195
if tempStr := promptString(scanner, "Temperature (0.0-2.0, optional)", ""); tempStr != "" {
188196
if temp, err := strconv.ParseFloat(tempStr, 64); err == nil {
189197
adl.Spec.Agent.Temperature = temp
190198
}
191199
}
192200
}
193201

194-
// Capabilities
195202
fmt.Println("\n⚡ Capabilities")
196203
fmt.Println("---------------")
197204
adl.Spec.Capabilities = &struct {
198-
Streaming bool `yaml:"streaming"`
199-
PushNotifications bool `yaml:"pushNotifications"`
200-
StateTransitionHistory bool `yaml:"stateTransitionHistory"`
205+
Streaming bool `yaml:"streaming"`
206+
PushNotifications bool `yaml:"pushNotifications"`
207+
StateTransitionHistory bool `yaml:"stateTransitionHistory"`
201208
}{}
202209

203210
adl.Spec.Capabilities.Streaming = promptBool(scanner, "Enable streaming", true)
204211
adl.Spec.Capabilities.PushNotifications = promptBool(scanner, "Enable push notifications", false)
205212
adl.Spec.Capabilities.StateTransitionHistory = promptBool(scanner, "Enable state transition history", false)
206213

207-
// Tools
208214
fmt.Println("\n🔧 Tools")
209215
fmt.Println("--------")
210-
addTools := promptBool(scanner, "Add tools to your agent", true)
211-
216+
addTools := promptBool(scanner, "Add tools to your agent", false)
217+
212218
if addTools {
213219
for {
214220
tool := struct {
@@ -221,10 +227,9 @@ func collectADLInfo(scanner *bufio.Scanner, projectName string) *adlData {
221227
if tool.Name == "" {
222228
break
223229
}
224-
230+
225231
tool.Description = promptString(scanner, "Tool description", "")
226-
227-
// Simple schema for now
232+
228233
tool.Schema = map[string]interface{}{
229234
"type": "object",
230235
"properties": map[string]interface{}{
@@ -244,7 +249,6 @@ func collectADLInfo(scanner *bufio.Scanner, projectName string) *adlData {
244249
}
245250
}
246251

247-
// Server configuration
248252
fmt.Println("\n🌐 Server Configuration")
249253
fmt.Println("-----------------------")
250254
portStr := promptString(scanner, "Server port", "8080")
@@ -255,11 +259,23 @@ func collectADLInfo(scanner *bufio.Scanner, projectName string) *adlData {
255259
}
256260
adl.Spec.Server.Debug = promptBool(scanner, "Enable debug mode", false)
257261

258-
// Go configuration
259262
fmt.Println("\n🐹 Go Configuration")
260263
fmt.Println("-------------------")
261-
adl.Spec.Go.Module = promptString(scanner, "Go module", fmt.Sprintf("github.com/example/%s", adl.Metadata.Name))
262-
adl.Spec.Go.GoVersion = promptString(scanner, "Go version", "1.21")
264+
265+
adl.Spec.Language = &struct {
266+
Go *struct {
267+
Module string `yaml:"module"`
268+
Version string `yaml:"version"`
269+
} `yaml:"go,omitempty"`
270+
}{}
271+
272+
adl.Spec.Language.Go = &struct {
273+
Module string `yaml:"module"`
274+
Version string `yaml:"version"`
275+
}{}
276+
277+
adl.Spec.Language.Go.Module = promptString(scanner, "Go module", fmt.Sprintf("github.com/example/%s", adl.Metadata.Name))
278+
adl.Spec.Language.Go.Version = promptString(scanner, "Go version", "1.24")
263279

264280
return adl
265281
}
@@ -270,10 +286,10 @@ func promptString(scanner *bufio.Scanner, prompt, defaultValue string) string {
270286
} else {
271287
fmt.Printf("%s: ", prompt)
272288
}
273-
289+
274290
scanner.Scan()
275291
input := strings.TrimSpace(scanner.Text())
276-
292+
277293
if input == "" {
278294
return defaultValue
279295
}
@@ -285,42 +301,49 @@ func promptBool(scanner *bufio.Scanner, prompt string, defaultValue bool) bool {
285301
if defaultValue {
286302
defaultStr = "y"
287303
}
288-
289-
fmt.Printf("%s [%s/n]: ", prompt, defaultStr)
304+
305+
fmt.Printf("%s [y/n] (default: %s): ", prompt, defaultStr)
290306
scanner.Scan()
291307
input := strings.ToLower(strings.TrimSpace(scanner.Text()))
292-
308+
293309
if input == "" {
294310
return defaultValue
295311
}
296-
312+
297313
return input == "y" || input == "yes"
298314
}
299315

300316
func promptChoice(scanner *bufio.Scanner, prompt string, choices []string, defaultValue string) string {
301317
fmt.Printf("%s (%s) [%s]: ", prompt, strings.Join(choices, "/"), defaultValue)
302318
scanner.Scan()
303319
input := strings.TrimSpace(scanner.Text())
304-
320+
305321
if input == "" {
306322
return defaultValue
307323
}
308-
309-
// Validate choice
324+
310325
for _, choice := range choices {
311326
if input == choice {
312327
return input
313328
}
314329
}
315-
330+
316331
return defaultValue
317332
}
318333

319334
func writeADLFile(adl *adlData, filePath string) error {
320-
data, err := yaml.Marshal(adl)
321-
if err != nil {
335+
var buf strings.Builder
336+
encoder := yaml.NewEncoder(&buf)
337+
encoder.SetIndent(2)
338+
339+
if err := encoder.Encode(adl); err != nil {
340+
_ = encoder.Close()
322341
return err
323342
}
324-
325-
return os.WriteFile(filePath, data, 0644)
343+
344+
if err := encoder.Close(); err != nil {
345+
return err
346+
}
347+
348+
return os.WriteFile(filePath, []byte(buf.String()), 0644)
326349
}

examples/enterprise-agent.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,4 +93,4 @@ spec:
9393
language:
9494
go:
9595
module: "github.com/company/enterprise-agent"
96-
goVersion: "1.24"
96+
version: "1.24"

examples/minimal-agent.yaml

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,11 @@ metadata:
44
name: simple-api
55
description: "A minimal HTTP API server without AI capabilities"
66
version: "1.0.0"
7-
87
spec:
98
capabilities:
109
streaming: false
1110
pushNotifications: false
1211
stateTransitionHistory: false
13-
1412
tools:
1513
- name: health_check
1614
description: "Perform health check of the system"
@@ -21,7 +19,6 @@ spec:
2119
type: string
2220
description: "Component to check (optional)"
2321
required: []
24-
2522
- name: echo
2623
description: "Echo back the input message"
2724
schema:
@@ -31,12 +28,10 @@ spec:
3128
type: string
3229
description: "Message to echo back"
3330
required: [message]
34-
3531
server:
3632
port: 3000
3733
debug: true
38-
3934
language:
4035
go:
4136
module: "github.com/example/simple-api"
42-
goVersion: "1.24"
37+
version: "1.24"

examples/weather-agent.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,4 @@ spec:
6060
language:
6161
go:
6262
module: "github.com/example/weather-agent"
63-
goVersion: "1.24"
63+
version: "1.24"

internal/generator/generator.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,8 @@ func (g *Generator) validateADL(adl *schema.ADL) error {
121121
if adl.Spec.Language.Go.Module == "" {
122122
return fmt.Errorf("spec.language.go.module is required")
123123
}
124-
if adl.Spec.Language.Go.GoVersion == "" {
125-
return fmt.Errorf("spec.language.go.goVersion is required")
124+
if adl.Spec.Language.Go.Version == "" {
125+
return fmt.Errorf("spec.language.go.version is required")
126126
}
127127
}
128128
if adl.Spec.Language.TypeScript != nil {

0 commit comments

Comments
 (0)