Clouade did up to this point
This commit is contained in:
53
main.go
53
main.go
@@ -8,11 +8,6 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
const systemPrompt = `You are a coding assistant running inside a CLI. You have file tools scoped
|
||||
to the current project directory. All paths are relative to the project root; absolute paths
|
||||
and paths that escape the root (via "..") will be rejected. Prefer listing and reading before
|
||||
editing. Keep replies concise.`
|
||||
|
||||
func main() {
|
||||
root, err := os.Getwd()
|
||||
if err != nil {
|
||||
@@ -35,12 +30,10 @@ func main() {
|
||||
}
|
||||
|
||||
client := NewClient(baseURL, apiKey, model)
|
||||
tools := toolDefinitions()
|
||||
orch := NewOrchestrator(client, root)
|
||||
|
||||
messages := []Message{{Role: "system", Content: systemPrompt}}
|
||||
|
||||
fmt.Printf("NyxTex agent — model=%s root=%s\n", model, root)
|
||||
fmt.Println("Type your request. Empty line to submit. Ctrl+D or /exit to quit.")
|
||||
fmt.Printf("NyxTex agent (manager + programmer + qa) — model=%s root=%s\n", model, root)
|
||||
fmt.Println("Type your request. Ctrl+D or /exit to quit.")
|
||||
|
||||
reader := bufio.NewReader(os.Stdin)
|
||||
for {
|
||||
@@ -58,10 +51,14 @@ func main() {
|
||||
return
|
||||
}
|
||||
|
||||
messages = append(messages, Message{Role: "user", Content: input})
|
||||
|
||||
if err := runTurn(context.Background(), client, tools, root, &messages); err != nil {
|
||||
reply, err := orch.Handle(context.Background(), input)
|
||||
if err != nil {
|
||||
fmt.Fprintln(os.Stderr, "error:", err)
|
||||
continue
|
||||
}
|
||||
if strings.TrimSpace(reply) != "" {
|
||||
fmt.Println()
|
||||
fmt.Println(reply)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -74,36 +71,6 @@ func readUserInput(r *bufio.Reader) (string, error) {
|
||||
return line, nil
|
||||
}
|
||||
|
||||
// runTurn sends the conversation and handles any tool-call loop until the
|
||||
// assistant produces a plain text reply.
|
||||
func runTurn(ctx context.Context, client *Client, tools []Tool, root string, messages *[]Message) error {
|
||||
for {
|
||||
msg, err := client.Chat(ctx, *messages, tools)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
*messages = append(*messages, msg)
|
||||
|
||||
if len(msg.ToolCalls) == 0 {
|
||||
if strings.TrimSpace(msg.Content) != "" {
|
||||
fmt.Println(msg.Content)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
for _, tc := range msg.ToolCalls {
|
||||
fmt.Printf(" [tool] %s %s\n", tc.Function.Name, tc.Function.Arguments)
|
||||
result := runTool(root, tc.Function.Name, tc.Function.Arguments)
|
||||
*messages = append(*messages, Message{
|
||||
Role: "tool",
|
||||
ToolCallID: tc.ID,
|
||||
Name: tc.Function.Name,
|
||||
Content: result,
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func getEnvDefault(key, def string) string {
|
||||
if v := os.Getenv(key); v != "" {
|
||||
return v
|
||||
|
||||
Reference in New Issue
Block a user