|
| 1 | +package main |
| 2 | + |
| 3 | +import ( |
| 4 | + "context" |
| 5 | + "fmt" |
| 6 | + "log" |
| 7 | + |
| 8 | + "github.com/Protocol-Lattice/go-agent" |
| 9 | + "github.com/Protocol-Lattice/go-agent/src/adk" |
| 10 | + "github.com/Protocol-Lattice/go-agent/src/adk/modules" |
| 11 | + "github.com/Protocol-Lattice/go-agent/src/memory" |
| 12 | + "github.com/Protocol-Lattice/go-agent/src/memory/engine" |
| 13 | + "github.com/Protocol-Lattice/go-agent/src/models" |
| 14 | + "github.com/universal-tool-calling-protocol/go-utcp" |
| 15 | +) |
| 16 | + |
| 17 | +func main() { |
| 18 | + ctx := context.Background() |
| 19 | + |
| 20 | + // 1. Initialise a UTCP client – this is the shared tool bus. |
| 21 | + client, err := utcp.NewUTCPClient(ctx, &utcp.UtcpClientConfig{}, nil, nil) |
| 22 | + if err != nil { |
| 23 | + log.Fatalf("Failed to create UTCP client: %v", err) |
| 24 | + } |
| 25 | + |
| 26 | + // 2. Create a specialist agent that will be exposed as a UTCP tool. |
| 27 | + // Use a real Gemini model |
| 28 | + specialistModel, err := models.NewGeminiLLM(ctx, "gemini-3-pro-preview", "You are a specialist that can answer trivia questions.") |
| 29 | + if err != nil { |
| 30 | + log.Fatalf("Failed to create specialist model: %v", err) |
| 31 | + } |
| 32 | + |
| 33 | + specialist, err := agent.New(agent.Options{ |
| 34 | + Model: specialistModel, |
| 35 | + Memory: memory.NewSessionMemory(memory.NewMemoryBankWithStore(memory.NewInMemoryStore()), 8), |
| 36 | + SystemPrompt: "You are a versatile specialist agent that can help with various tasks.", |
| 37 | + }) |
| 38 | + if err != nil { |
| 39 | + log.Fatalf("Failed to create specialist agent: %v", err) |
| 40 | + } |
| 41 | + |
| 42 | + // 3. Register the specialist as a UTCP provider. |
| 43 | + err = specialist.RegisterAsUTCPProvider(ctx, client, "specialist", "Answers trivia via UTCP") |
| 44 | + if err != nil { |
| 45 | + log.Fatalf("Failed to register specialist: %v", err) |
| 46 | + } |
| 47 | + fmt.Println("✅ Registered specialist as UTCP tool 'specialist'") |
| 48 | + |
| 49 | + // 4. Build an orchestrator agent with CodeMode enabled. |
| 50 | + |
| 51 | + // Use a real Gemini model for the orchestrator |
| 52 | + orchestratorModel, err := models.NewGeminiLLM(ctx, "gemini-3-pro-preview", "You orchestrate workflows using CodeMode. Generate ONLY valid Go code. Do not include package main or imports. Use codemode.CallTool to invoke tools.") |
| 53 | + if err != nil { |
| 54 | + log.Fatalf("Failed to create orchestrator model: %v", err) |
| 55 | + } |
| 56 | + |
| 57 | + memOpts := engine.DefaultOptions() |
| 58 | + kit, err := adk.New(ctx, |
| 59 | + adk.WithDefaultSystemPrompt("You orchestrate workflows using CodeMode. Generate ONLY valid Go code. Do not include package main or imports. Use codemode.CallTool to invoke tools."), |
| 60 | + adk.WithModules( |
| 61 | + modules.NewModelModule("model", func(_ context.Context) (models.Agent, error) { return orchestratorModel, nil }), |
| 62 | + modules.InMemoryMemoryModule(10000, memory.AutoEmbedder(), &memOpts), |
| 63 | + ), |
| 64 | + // Enable CodeMode – it will generate calls to codemode.CallTool which under the hood uses the UTCP client. |
| 65 | + adk.WithCodeModeUtcp(client, orchestratorModel), |
| 66 | + ) |
| 67 | + if err != nil { |
| 68 | + log.Fatalf("Failed to initialise ADK: %v", err) |
| 69 | + } |
| 70 | + orchestrator, err := kit.BuildAgent(ctx) |
| 71 | + if err != nil { |
| 72 | + log.Fatalf("Failed to build orchestrator: %v", err) |
| 73 | + } |
| 74 | + fmt.Println("✅ Orchestrator with CodeMode ready") |
| 75 | + |
| 76 | + // Register the orchestrator itself as a UTCP provider so it can be called recursively or for summarization |
| 77 | + err = orchestrator.RegisterAsUTCPProvider(ctx, client, "orchestrator", "Orchestrates workflows and summarizes information") |
| 78 | + if err != nil { |
| 79 | + log.Fatalf("Failed to register orchestrator: %v", err) |
| 80 | + } |
| 81 | + fmt.Println("✅ Registered orchestrator as UTCP tool 'orchestrator'") |
| 82 | + |
| 83 | + // 5. Run a natural‑language request that the orchestrator will turn into a CodeMode workflow. |
| 84 | + // This prompt describes a multi-step process that the agent would convert into a Go script |
| 85 | + // calling the respective UTCP tools (e.g. http.echo, http.timestamp, etc.). |
| 86 | + userPrompt := ` |
| 87 | +Step 1: Ask for a fun fact about the Eiffel Tower using the specialist tool. |
| 88 | +Step 2: Ask for a fun fact about the Great Wall of China using the specialist tool. |
| 89 | +Step 3: Use the orchestrator tool to summarize the facts from Step 1 and Step 2. |
| 90 | +` |
| 91 | + fmt.Printf("\nUser Prompt:\n%s\n", userPrompt) |
| 92 | + |
| 93 | + // Invoke the orchestrator. |
| 94 | + // In a real scenario, the Orchestrator (powered by an LLM) would generate Go code |
| 95 | + // to execute these steps sequentially, passing data between them. |
| 96 | + resp, err := orchestrator.Generate(ctx, "session-orchestrator", userPrompt) |
| 97 | + if err != nil { |
| 98 | + log.Fatalf("Orchestrator failed: %v", err) |
| 99 | + } |
| 100 | + fmt.Printf("Orchestrator response: %v\n", resp) |
| 101 | +} |
0 commit comments