MCPcopy
hub / github.com/agent0ai/agent-zero / after_execution

Method after_execution

tools/vision_load.py:132–181  ·  view source on GitHub ↗
(self, response: Response, **kwargs)

Source from the content-addressed store, hash-verified

130 return value
131
132 async def after_execution(self, response: Response, **kwargs):
133
134 # build image data messages for LLMs, or error message
135 content = []
136 loaded_count = len(self.loaded_paths)
137 skipped_count = len(self.skipped_paths)
138 loaded_summary = "\n".join(self.loaded_paths) if self.loaded_paths else "none"
139 skipped_summary = "\n".join(self.skipped_paths) if self.skipped_paths else "none"
140 summary = (
141 f"Loaded images: {loaded_count}\n"
142 f"Loaded images:\n{loaded_summary}\n\n"
143 f"Skipped images: {skipped_count}\n"
144 f"Skipped images (max {self._get_max_embeds()} loaded at a time according to model configuration):\n{skipped_summary}"
145 )
146 if self.images_dict:
147 self.agent.hist_add_tool_result(self.name, summary, id=self.log.id if self.log else "")
148 for path, image_path in self.images_dict.items():
149 if image_path:
150 content.append(
151 {
152 "type": "image_url",
153 "image_url": {"url": image_path},
154 }
155 )
156 else:
157 content.append(
158 {
159 "type": "text",
160 "text": "Error processing image " + path,
161 }
162 )
163 # append as raw message content for LLMs with vision tokens estimate
164 msg = history.RawMessage(raw_content=content, preview="<Image attachments loaded by path>")
165 self.agent.hist_add_message(
166 False, content=msg, tokens=TOKENS_ESTIMATE * len(content)
167 )
168 else:
169 self.agent.hist_add_tool_result(self.name, summary if self.skipped_paths else "No images processed", id=self.log.id if self.log else "")
170
171 # print and log short version
172 message = (
173 "No images processed"
174 if not self.images_dict and not self.skipped_paths
175 else f"{loaded_count} images loaded, {skipped_count} skipped"
176 )
177 PrintStyle(
178 font_color="#1B4F72", background_color="white", padding=True, bold=True
179 ).print(f"{self.agent.agent_name}: Response from tool '{self.name}'")
180 PrintStyle(font_color="#85C1E9").print(message)
181 self.log.update(result=message)

Calls 7

_get_max_embedsMethod · 0.95
PrintStyleClass · 0.90
hist_add_messageMethod · 0.80
joinMethod · 0.45
hist_add_tool_resultMethod · 0.45
printMethod · 0.45
updateMethod · 0.45