Copilot commented on code in PR #1319:
URL: https://github.com/apache/dubbo-admin/pull/1319#discussion_r2313943736


##########
ai/internal/manager/manager.go:
##########
@@ -0,0 +1,124 @@
+package manager
+
+import (
+       "context"
+       "dubbo-admin-ai/config"
+       "dubbo-admin-ai/plugins/siliconflow"
+       "dubbo-admin-ai/utils"
+       "fmt"
+       "log"
+       "log/slog"
+       "os"
+       "path/filepath"
+       "strings"
+       "time"
+
+       "github.com/firebase/genkit/go/core/logger"
+       "github.com/firebase/genkit/go/genkit"
+       "github.com/firebase/genkit/go/plugins/googlegenai"
+       "github.com/joho/godotenv"
+       "github.com/lmittmann/tint"
+)
+
+var (
+       globalGenkit *genkit.Genkit
+       rootContext  *context.Context
+       globalLogger *slog.Logger
+)
+
+func InitGlobalGenkit(defaultModel string) (err error) {
+       ctx := context.Background()
+       if rootContext == nil {
+               rootContext = &ctx
+       }
+       g, err := genkit.Init(*rootContext,
+               genkit.WithPlugins(
+                       &siliconflow.SiliconFlow{
+                               APIKey: config.SILICONFLOW_API_KEY,
+                       },
+                       &googlegenai.GoogleAI{
+                               APIKey: config.GEMINI_API_KEY,
+                       },
+               ),
+               genkit.WithDefaultModel(defaultModel),
+               genkit.WithPromptDir(config.PROMPT_DIR_PATH),
+       )
+
+       if g == nil {
+               return fmt.Errorf("fail to initialize global genkit")
+       }
+
+       globalGenkit = g
+       return err
+}
+
+func InitLogger() {
+       logLevel := slog.LevelInfo
+       if envLevel := config.LOG_LEVEL; envLevel != "" {
+               switch strings.ToUpper(envLevel) {
+               case "DEBUG":
+                       logLevel = slog.LevelDebug
+               case "INFO":
+                       logLevel = slog.LevelInfo
+               case "WARN", "WARNING":
+                       logLevel = slog.LevelWarn
+               case "ERROR":
+                       logLevel = slog.LevelError
+               }
+       }
+       logger.SetLevel(logLevel)
+
+       slog.SetDefault(
+               slog.New(
+                       tint.NewHandler(os.Stderr, &tint.Options{
+                               Level:      slog.LevelDebug,
+                               AddSource:  true,
+                               TimeFormat: time.Kitchen,
+                       }),
+               ),
+       )
+       globalLogger = slog.Default()
+}
+
+func GetGlobalGenkit() (*genkit.Genkit, error) {
+       var err error
+       if globalGenkit == nil {
+               err = InitGlobalGenkit(config.DEFAULT_MODEL)
+               if err != nil {
+                       log.Fatalf("Failed to initialize global genkit: %v", 
err)
+               }
+       }
+       return globalGenkit, err
+}
+
+func GetLogger() *slog.Logger {
+       if globalLogger == nil {
+               InitLogger()
+       }
+       return globalLogger
+}
+
+func GetRootContext() context.Context {
+       ctx := context.Background()
+       if rootContext == nil {
+               rootContext = &ctx
+       }
+       return *rootContext
+}
+
+// Load environment variables from PROJECT_ROOT/.env file
+func LoadEnvVars() (err error) {
+       dotEnvFilePath := filepath.Join(config.PROJECT_ROOT, ".env")
+       dotEnvExampleFilePath := filepath.Join(config.PROJECT_ROOT, 
".env.example")
+
+       // Check if the .env file exists,if not, copy .env.example to .env

Review Comment:
   Mixed punctuation style - there's a Chinese comma (,) followed by English 
text. Should be: 'Check if the .env file exists, if not, copy .env.example to 
.env'
   ```suggestion
        // Check if the .env file exists, if not, copy .env.example to .env
   ```



##########
ai/internal/agent/flow.go:
##########
@@ -0,0 +1,178 @@
+package agent
+
+import (
+       "context"
+       "dubbo-admin-ai/config"
+       "dubbo-admin-ai/internal/manager"
+       "dubbo-admin-ai/internal/schema"
+       "dubbo-admin-ai/internal/tools"
+       "errors"
+       "fmt"
+       "log"
+       "os"
+
+       "github.com/firebase/genkit/go/core/logger"
+
+       "github.com/firebase/genkit/go/ai"
+       "github.com/firebase/genkit/go/core"
+       "github.com/firebase/genkit/go/genkit"
+)
+
+// 公开的 Flow 变量,以便在编排器中调用
+var (
+       ReActFlow    *core.Flow[schema.ReActIn, schema.ReActOut, struct{}]
+       ThinkingFlow *core.Flow[schema.ThinkIn, *schema.ThinkOut, struct{}]
+       ActFlow      *core.Flow[*schema.ActIn, schema.ActOut, struct{}]
+
+       ThinkPrompt *ai.Prompt
+)
+
+var g *genkit.Genkit
+
+// The order of initialization cannot change
+func InitAgent() (err error) {
+       if err = manager.LoadEnvVars(); err != nil {
+               return err
+       }
+
+       manager.InitLogger()
+
+       if g, err = manager.GetGlobalGenkit(); err != nil {
+               return err
+       }
+
+       tools.RegisterAllMockTools(g)
+
+       if err = InitFlows(g); err != nil {
+               return err
+       }
+
+       return nil
+}
+
+func InitFlows(registry *genkit.Genkit) error {
+       if registry == nil {
+               return fmt.Errorf("registry is nil")
+       }
+       g = registry
+
+       data, err := os.ReadFile(config.PROMPT_DIR_PATH + "/agentSystem.prompt")
+       if err != nil {
+               return fmt.Errorf("failed to read agentSystem prompt: %w", err)
+       }
+       systemPromptText := string(data)
+
+       mockTools, err := tools.AllMockToolRef()
+       if err != nil {
+               log.Fatalf("failed to get mock mock_tools: %v", err)
+       }
+       ThinkPrompt, err = genkit.DefinePrompt(g, "agentThinking",
+               ai.WithSystem(systemPromptText),
+               ai.WithInputType(schema.ThinkIn{}),
+               ai.WithOutputType(schema.ThinkOut{}),
+               ai.WithPrompt("{{userInput}}"),
+               ai.WithTools(mockTools...),
+       )
+
+       if err != nil {
+               return fmt.Errorf("failed to define agentThink prompt: %w", err)
+       }
+
+       ReActFlow = genkit.DefineFlow(g, "reAct", reAct)
+       ThinkingFlow = genkit.DefineFlow(g, "thinking", thinking)
+       ActFlow = genkit.DefineFlow(g, "act", act)
+
+       return nil
+}
+
+// Flow 的核心函数实现 `fn` (不对外导出)
+// ----------------------------------------------------------------------------
+// 1. agentOrchestrator: 总指挥/编排器的核心逻辑
+// ----------------------------------------------------------------------------
+func reAct(ctx context.Context, reActInput schema.ReActIn) (reActOut 
schema.ReActOut, err error) {
+       //TODO: 输入数据意图解析
+
+       thinkingInput := reActInput
+       // 主协调循环 (Reconciliation Loop)
+       for range config.MAX_REACT_ITERATIONS {

Review Comment:
   [nitpick] Using an unnamed range variable in the loop makes the iteration 
count implicit. Consider using a named variable to make the iteration logic 
more explicit: `for i := 0; i < config.MAX_REACT_ITERATIONS; i++`
   ```suggestion
        for i := 0; i < config.MAX_REACT_ITERATIONS; i++ {
   ```



##########
ai/prompts/agentThink.prompt:
##########
@@ -0,0 +1,110 @@
+---
+# -------------------------------------------------------------
+# Agent "Brain" Prompt - agentThink.prompt
+# -------------------------------------------------------------
+# This prompt is the core reasoning engine for our ReAct agent.
+# It takes the current state and decides the next action or provides the final 
answer.
+# -------------------------------------------------------------
+
+# model: googleai/gemini-2.5-pro
+model: siliconflow/deepseek-ai/DeepSeek-V3

Review Comment:
   The model specification appears to have inconsistent naming. Based on the 
plugin configuration, it should be 'siliconflow/deepseek-ai/DeepSeek-V3' but 
verify this matches the actual model identifier used by the SiliconFlow API.
   ```suggestion
   model: siliconflow/deepseek-ai/deepseek-v3
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to