@@ -37,7 +37,7 @@ func BeforeModelCallback(ctx agent.CallbackContext, req *model.LLMRequest) (*mod
3737 // Create a unique filename for the image.
3838 fileName := fmt .Sprintf ("user_image_%d.%s" , i , strings .Split (part .InlineData .MIMEType , "/" )[1 ])
3939 // Save the image as an artifact.
40- if err := artifacts .Save (fileName , * part ); err != nil {
40+ if _ , err := artifacts .Save (ctx , fileName , part ); err != nil {
4141 log .Printf ("[WARN] Failed to save user image: %v\n " , err )
4242 } else {
4343 log .Printf ("[INFO] Saved user image artifact: %s\n " , fileName )
@@ -69,7 +69,7 @@ func configureRunner() {
6969 Model : model ,
7070 Name : "artifact_user_agent" ,
7171 Instruction : "You are an agent that describes images." ,
72- BeforeModel : []llmagent.BeforeModelCallback {
72+ BeforeModelCallbacks : []llmagent.BeforeModelCallback {
7373 BeforeModelCallback ,
7474 },
7575 })
@@ -125,12 +125,14 @@ func loadArtifactsCallback(ctx agent.CallbackContext, req *model.LLMRequest) (*m
125125 const filenameToLoad = "generated_report.pdf"
126126
127127 // Load the artifact from the artifact service.
128- loadedPart , err := ctx .Artifacts ().Load (filenameToLoad )
128+ loadedPartResponse , err := ctx .Artifacts ().Load (ctx , filenameToLoad )
129129 if err != nil {
130130 log .Printf ("Callback could not load artifact '%s': %v" , filenameToLoad , err )
131131 return nil , nil // File not found or error, continue to model.
132132 }
133133
134+ loadedPart := loadedPartResponse .Part
135+
134136 log .Printf ("Callback successfully loaded artifact '%s'." , filenameToLoad )
135137
136138 // Ensure there's at least one content in the request to append to.
@@ -142,7 +144,7 @@ func loadArtifactsCallback(ctx agent.CallbackContext, req *model.LLMRequest) (*m
142144
143145 // Add the loaded artifact to the request for the model.
144146 lastContent := req .Contents [len (req .Contents )- 1 ]
145- lastContent .Parts = append (lastContent .Parts , & loadedPart )
147+ lastContent .Parts = append (lastContent .Parts , loadedPart )
146148 log .Printf ("Added artifact '%s' to LLM request." , filenameToLoad )
147149
148150 // Return nil to continue to the next callback or the model.
@@ -240,7 +242,7 @@ func saveReportCallback(ctx agent.CallbackContext, req *model.LLMRequest) (*mode
240242 // Set the filename for the artifact.
241243 filename := "generated_report.pdf"
242244 // Save the artifact to the artifact service.
243- err = ctx .Artifacts ().Save (filename , * reportArtifact )
245+ _ , err = ctx .Artifacts ().Save (ctx , filename , reportArtifact )
244246 if err != nil {
245247 log .Printf ("An unexpected error occurred during Go artifact save: %v" , err )
246248 // Depending on requirements, you might want to return an error to the user.
@@ -259,12 +261,14 @@ func saveReportCallback(ctx agent.CallbackContext, req *model.LLMRequest) (*mode
259261func listUserFilesCallback (ctx agent.CallbackContext , req * model.LLMRequest ) (* model.LLMResponse , error ) {
260262 log .Println ("[Callback] listUserFilesCallback triggered." )
261263 // List the available artifacts from the artifact service.
262- availableFiles , err := ctx .Artifacts ().List ()
264+ listResponse , err := ctx .Artifacts ().List (ctx )
263265 if err != nil {
264266 log .Printf ("An unexpected error occurred during Go artifact list: %v" , err )
265267 return nil , nil // Continue, but log the error.
266268 }
267269
270+ availableFiles := listResponse .FileNames
271+
268272 log .Printf ("Found %d available files." , len (availableFiles ))
269273
270274 // If there are available files, add them to the LLM request.
@@ -325,7 +329,7 @@ func main() {
325329 Model : model ,
326330 Name : "reporting_agent" ,
327331 Instruction : "You are a reporting agent. You can see available files and their contents if they are loaded for you. Summarize any provided files." ,
328- BeforeModel : []llmagent.BeforeModelCallback {
332+ BeforeModelCallbacks : []llmagent.BeforeModelCallback {
329333 saveReportCallback , // Saves report from state
330334 listUserFilesCallback , // Lists available files and adds to prompt
331335 loadArtifactsCallback , // Loads a specific file and adds to prompt
@@ -356,13 +360,13 @@ func main() {
356360 log .Println ("\n --- Agent Run 1: Triggering callbacks ---" )
357361 log .Println ("This run will trigger `saveReportCallback` (from session state), `listUserFilesCallback` (will see the newly saved file), and `loadArtifactsCallback` (will load it)." )
358362 userInput := & genai.Content {Parts : []* genai.Part {genai .NewPartFromText ("Please summarize the report for me." )}}
359- for event , err := range r .Run (ctx , session .Session .UserID (), session .Session .ID (), userInput , & agent.RunConfig {
363+ for event , err := range r .Run (ctx , session .Session .UserID (), session .Session .ID (), userInput , agent.RunConfig {
360364 StreamingMode : agent .StreamingModeSSE ,
361365 }) {
362366 if err != nil {
363367 log .Printf ("AGENT ERROR: %v\n " , err )
364- } else if event . LLMResponse != nil && event . LLMResponse .Content != nil {
365- for _ , p := range event .LLMResponse . Content .Parts {
368+ } else if event != nil && event .Content != nil {
369+ for _ , p := range event .Content .Parts {
366370 fmt .Print (string (p .Text ))
367371 }
368372 }
0 commit comments