Repository navigation
Expand file tree
/
Copy pathmain.go
More file actions
120 lines (95 loc) · 3.38 KB
/
Copy pathmain.go
File metadata and controls
120 lines (95 loc) · 3.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
package main
import (
"context"
"flag"
"time"
"github.com/bzfq21/Go-ComputerUseAgent/internal/config"
"github.com/bzfq21/Go-ComputerUseAgent/internal/core/llm"
"github.com/bzfq21/Go-ComputerUseAgent/internal/core/rpa"
core "github.com/bzfq21/Go-ComputerUseAgent/internal/core/workflow"
"github.com/bzfq21/Go-ComputerUseAgent/internal/models"
"github.com/bzfq21/Go-ComputerUseAgent/internal/utils"
)
var version = "dev"
var buildTime = "unknown"
var binaryName = "agent"
type WorkContext = core.WorkContext
type Agent = core.Agent
func NewAgent(ctx *WorkContext, llmClient llm.LLMClient, rpaServer *rpa.Server) *Agent {
return core.NewAgent(ctx, llmClient, rpaServer)
}
func WithParam(parent context.Context, param map[any]any) *WorkContext {
return core.WithParam(parent, param)
}
func main() {
// Initialize overlay manager early to avoid CGO crashes
// This starts the NSApplication event loop in a dedicated thread
rpa.InitOverlay()
agentConfig, err := config.LoadConfig()
if err != nil {
utils.Error("Failed to load config: %v", err)
return
}
help := flag.Bool("help", false, "Show help information")
showVersion := flag.Bool("version", false, "Show version information")
taskDesc := flag.String("task", agentConfig.App.Task, "Task description to execute")
isPlan := flag.Bool("plan", agentConfig.App.IsPlan, "Enable planning mode")
isEval := flag.Bool("eval", agentConfig.App.IsEvaluation, "Enable evaluation mode")
maxSteps := flag.Int("max-steps", agentConfig.App.MaxSteps, "Maximum steps to execute")
screenIndex := flag.Int("screen-index", agentConfig.App.ScreenIndex, "Screen index to work on")
flag.Parse()
if *help {
flag.PrintDefaults()
return
}
if *showVersion {
utils.Info("%s version: %s", binaryName, version)
utils.Info("build time: %s", buildTime)
return
}
if *taskDesc == "" {
utils.Error("Task is required. Use -task flag to specify the task")
return
}
// Initialize logger from config
utils.InitLoggerFromConfig(utils.LogConfig{
Level: agentConfig.App.GetLogLevel(agentConfig.Log.Level),
Format: agentConfig.Log.Format,
Output: agentConfig.Log.Output,
})
if agentConfig.App.IsDevelopment() {
utils.Debug("Running in development mode")
}
llmClient := llm.NewClientFromAppConfig(agentConfig)
utils.Info("Checking LLM API endpoint connectivity...")
if err := llmClient.HealthCheck(context.Background()); err != nil {
utils.Error("LLM API endpoint health check failed: %v", err)
utils.Error("Please check your LLM configuration and ensure the API endpoint is accessible")
utils.Error("Configured endpoint: %s", agentConfig.LLM.BaseURL)
utils.Error("Model: %s", agentConfig.LLM.Model)
return
}
utils.Info("LLM API endpoint is accessible")
rpaServer := rpa.NewServerFromAgentConfig(agentConfig)
if agentConfig.App.IsDevelopment() {
rpaServer.UpdateConfig("enable_logging", true)
}
task := &models.Task{
Description: *taskDesc,
Status: "pending",
IsPlan: *isPlan,
IsEvaluation: *isEval,
WorkScreenIndex: *screenIndex,
MaxSteps: *maxSteps,
CreatedAt: time.Now(),
UpdatedAt: time.Now(),
}
ctx := WithParam(context.Background(), map[any]any{"task": task})
agentFlow := NewAgent(ctx, llmClient, rpaServer)
result, err := agentFlow.Run(ctx)
if err != nil {
utils.Error("Agent flow failed: %v", err)
return
}
utils.Info("Agent flow completed successfully %v", result)
}