77 "io"
88 "net/http"
99 "os"
10+ "slices"
1011 "sort"
1112 "strings"
1213 "sync"
@@ -162,8 +163,12 @@ func (s *server) execHandler(w http.ResponseWriter, r *http.Request) {
162163 reqObject .ChatState = "null"
163164 }
164165
165- // Append a prompt URL for this run.
166- reqObject .Env = append (reqObject .Env , fmt .Sprintf ("%s=http://%s/prompt/%s" , types .PromptURLEnvVar , s .address , runID ))
166+ reqObject .Env = append (os .Environ (), reqObject .Env ... )
167+ // Don't overwrite the PromptURLEnvVar if it is already set in the environment.
168+ if ! slices .ContainsFunc (reqObject .Env , func (s string ) bool { return strings .HasPrefix (s , types .PromptURLEnvVar + "=" ) }) {
169+ // Append a prompt URL for this run.
170+ reqObject .Env = append (reqObject .Env , fmt .Sprintf ("%s=http://%s/prompt/%s" , types .PromptURLEnvVar , s .address , runID ))
171+ }
167172
168173 logger .Debugf ("executing tool: %+v" , reqObject )
169174 var (
@@ -179,7 +184,7 @@ func (s *server) execHandler(w http.ResponseWriter, r *http.Request) {
179184
180185 opts := & gptscript.Options {
181186 Cache : reqObject .Options ,
182- Env : append ( os . Environ (), reqObject .Env ... ) ,
187+ Env : reqObject .Env ,
183188 Workspace : reqObject .Workspace ,
184189 CredentialContext : reqObject .CredentialContext ,
185190 Runner : runner.Options {
0 commit comments