From e08b7f4432cef851aeda6ee08326727d2aab810f Mon Sep 17 00:00:00 2001 From: Dinesh Yeduguru Date: Wed, 8 Jan 2025 17:47:29 -0800 Subject: [PATCH] move _interpret_content_as_attachment to outside --- .../agents/meta_reference/agent_instance.py | 31 ++++++++++--------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/llama_stack/providers/inline/agents/meta_reference/agent_instance.py b/llama_stack/providers/inline/agents/meta_reference/agent_instance.py index 52293182c..b72856674 100644 --- a/llama_stack/providers/inline/agents/meta_reference/agent_instance.py +++ b/llama_stack/providers/inline/agents/meta_reference/agent_instance.py @@ -679,21 +679,7 @@ class ChatAgent(ShieldRunnerMixin): # TODO: add tool-input touchpoint and a "start" event for this step also # but that needs a lot more refactoring of Tool code potentially - def interpret_content_as_attachment( - content: str, - ) -> Optional[Attachment]: - match = re.search(TOOLS_ATTACHMENT_KEY_REGEX, content) - if match: - snippet = match.group(1) - data = json.loads(snippet) - return Attachment( - url=URL(uri="file://" + data["filepath"]), - mime_type=data["mimetype"], - ) - - return None - - if out_attachment := interpret_content_as_attachment( + if out_attachment := _interpret_content_as_attachment( result_message.content ): # NOTE: when we push this message back to the model, the model may ignore the @@ -974,3 +960,18 @@ async def execute_tool_call_maybe( content=result.content, ) ] + + +def _interpret_content_as_attachment( + content: str, +) -> Optional[Attachment]: + match = re.search(TOOLS_ATTACHMENT_KEY_REGEX, content) + if match: + snippet = match.group(1) + data = json.loads(snippet) + return Attachment( + url=URL(uri="file://" + data["filepath"]), + mime_type=data["mimetype"], + ) + + return None