Execute a tool and return raw output with an external context
(
&self,
name: &str,
args: &serde_json::Value,
ctx: &ToolContext,
)
| 252 | |
| 253 | /// Execute a tool and return raw output with an external context |
| 254 | pub async fn execute_raw_with_context( |
| 255 | &self, |
| 256 | name: &str, |
| 257 | args: &serde_json::Value, |
| 258 | ctx: &ToolContext, |
| 259 | ) -> Result<Option<ToolOutput>> { |
| 260 | let tool = self.get(name); |
| 261 | |
| 262 | match tool { |
| 263 | Some(tool) => { |
| 264 | let mut output = tool.execute(args, ctx).await?; |
| 265 | let original_content = output.content.clone(); |
| 266 | let truncated = truncate_tool_output_with_artifact(name, &output.content); |
| 267 | output.content = truncated.content; |
| 268 | if let Some(artifact) = truncated.artifact { |
| 269 | self.store_tool_artifact(name, &original_content, &artifact); |
| 270 | output.metadata = Some(merge_tool_output_artifact_metadata( |
| 271 | output.metadata, |
| 272 | &artifact, |
| 273 | )); |
| 274 | } |
| 275 | Ok(Some(output)) |
| 276 | } |
| 277 | None => Ok(None), |
| 278 | } |
| 279 | } |
| 280 | |
| 281 | fn store_tool_artifact(&self, tool_name: &str, content: &str, artifact: &ToolOutputArtifact) { |
| 282 | self.artifact_store.put(ToolArtifact { |
no test coverage detected