feat: initial scaffold with context adapters and litellm pkg
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
88
cmd/__PROJECT_NAME__/main.go
Normal file
88
cmd/__PROJECT_NAME__/main.go
Normal file
@@ -0,0 +1,88 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"google.golang.org/adk/agent"
|
||||
"google.golang.org/adk/agent/llmagent"
|
||||
"google.golang.org/adk/runner"
|
||||
"google.golang.org/adk/session"
|
||||
"google.golang.org/genai"
|
||||
|
||||
"__MODULE_PATH__/pkg/litellm"
|
||||
)
|
||||
|
||||
func main() {
|
||||
ctx := context.Background()
|
||||
|
||||
shutdown, err := litellm.SetupTelemetry(ctx)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "telemetry: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
defer shutdown(ctx)
|
||||
|
||||
llm := litellm.New(
|
||||
env("LITELLM_MODEL", "berget/llama-3.3-70b"),
|
||||
env("LITELLM_BASE_URL", "https://llm-api.d-ma.be/v1"),
|
||||
mustEnv("LITELLM_API_KEY"),
|
||||
)
|
||||
|
||||
ag, err := llmagent.New(llmagent.Config{
|
||||
Name: "__PROJECT_NAME__",
|
||||
Description: "TODO: describe what this agent does",
|
||||
Model: llm,
|
||||
Instruction: "You are a helpful assistant.",
|
||||
})
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "agent: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
r, err := runner.New(runner.Config{
|
||||
AppName: "__PROJECT_NAME__",
|
||||
Agent: ag,
|
||||
SessionService: session.InMemoryService(),
|
||||
AutoCreateSession: true,
|
||||
})
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "runner: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
msg := genai.NewContentFromText("Hello!", "user")
|
||||
events := r.Run(ctx, "user-1", "session-1", msg, agent.RunConfig{})
|
||||
|
||||
for ev, err := range events {
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "run: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
if ev == nil || ev.Content == nil {
|
||||
continue
|
||||
}
|
||||
for _, p := range ev.Content.Parts {
|
||||
if p != nil && p.Text != "" {
|
||||
fmt.Println(p.Text)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func env(key, fallback string) string {
|
||||
if v := os.Getenv(key); v != "" {
|
||||
return v
|
||||
}
|
||||
return fallback
|
||||
}
|
||||
|
||||
func mustEnv(key string) string {
|
||||
v := os.Getenv(key)
|
||||
if v == "" {
|
||||
fmt.Fprintf(os.Stderr, "required env var %s not set\n", key)
|
||||
os.Exit(1)
|
||||
}
|
||||
return v
|
||||
}
|
||||
Reference in New Issue
Block a user