diff --git a/mindsdb_sdk/utils/agents.py b/mindsdb_sdk/utils/agents.py index e35fd39..7c64265 100644 --- a/mindsdb_sdk/utils/agents.py +++ b/mindsdb_sdk/utils/agents.py @@ -79,17 +79,10 @@ def stream_and_parse_sql_query(self, completion_stream: Generator[Dict[str, Any] for message in chunk['messages']: if message.get('role') == 'assistant': self.logger.info(f"Assistant message: {message.get('content', '')}") + if chunk.get('type') == 'sql': + sql_query = chunk['content'] + self.logger.info(f"Generated SQL: {sql_query}") - if 'actions' in chunk and chunk['actions']: - self.logger.info(f"Chunk contains {len(chunk['actions'])} actions") - for action in chunk['actions']: - if 'tool' in action and 'sql_db_query' in action['tool']: - match = re.search(r'tool_input="(.*?)"', action['tool']) - if match and not sql_query_found: - sql_query = match.group(1).replace("\\'", "'") - sql_query_found = True - self.logger.info(f"SQL query found: {sql_query}") - break elif isinstance(chunk, str): output = chunk self.logger.info(f"String chunk received: {chunk}")