I have a simple module where I am testing making calls to multiple LLMs. In the shell when I call the llm primitive I have no problem as it just uses my env var that is already loaded. When I try to run my custom module however I get an error.
Module code:
package main
import (
"context"
"dagger/dagger-agents/internal/dagger"
)
type DaggerAgents struct{}
func (da *DaggerAgents) MultiLLM(ctx context.Context) *dagger.Container {
environment := dag.Env().
WithLLMInput("llm", dag.LLM(), "LLM for prompting various different AI models").
WithContainerOutput("result", "A container with the result")
result := dag.LLM().
WithEnv(environment).
WithModel("claude-3-7-sonnet-latest").
WithPrompt(`
Ask the following models to write a poem about a beaver:
claude-3-5-sonnet-latest
gemini-2.5-pro-preview-03-25
gpt-4o
Then return all poems annotated with their model name
`)
return result.Env().Output("result").AsContainer()
}
Output:
~/Workspace/dagger-agents via πΉ v1.23.8 took 31s
β― dagger
Dagger interactive shell. Type ".help" for more information. Press Ctrl+D to exit.
β llm | with-model claude-3-7-sonnet-latest | with-prompt "hello" 1.2s
βπ§ hello
β β 0.0s
β
βπ€ Hello! How can I assist you today? I'm here to help with information, answer questions, or discuss various topics. What would you like to talk about?
β β 1.2s
LLM@xxh3:b29c94ac3721cdb5
β multi-llm 0.6s
βπ§ Ask the following models to write a poem about a beaver:
β β
β β claude-3-5-sonnet-latest
β β gemini-2.5-pro-preview-03-25
β β gpt-4o
β β
β β Then return all poems annotated with their model name
β β 0.0s
β
βπ€ 0.2s
β ! POST "https://api.anthropic.com/v1/messages": 401 Unauthorized {"type":"error","error":{"type":"authentication_error","message":"x-api-key header is required"}}
! input: daggerAgents.multiLlm POST "https://api.anthropic.com/v1/messages": 401 Unauthorized {"type":"error","error":{"type":"authentication_error","message":"x-api-key header is required"}}
dagger-agents β