Lee-W commented on code in PR #76799:
URL: https://github.com/apache/airflow/pull/76799#discussion_r4597320874


##########
providers/common/ai/src/airflow/providers/common/ai/toolsets/sql.py:
##########
@@ -554,23 +623,106 @@ def add(schema: str | None, name: str, display: str) -> 
None:
         if self._include_default_schema:
             for name in inspector.get_table_names(schema=self._schema):
                 add(self._schema, name, name)
+        return tables
+
+    def _list_tables(self) -> str:
+        tables = self._find_allowed_tables()
+        if self._search_backend is not None and len(tables) > 
self._max_listed_tables:
+            return dumps_masked(
+                {
+                    "table_count": len(tables),
+                    "hint": (
+                        f"There are {len(tables)} tables, too many to list 
(the limit is "
+                        f"{self._max_listed_tables}). Use 
{self._build_tool_name('search_tables')} to find the ones you need."
+                    ),
+                }
+            )
+        if not self._include_table_comments:
+            return dumps_masked([display for _, _, display in tables])
+        return dumps_masked(
+            [
+                {"name": name, **({"comment": comment} if comment else {})}
+                for name, comment in self._get_table_entries(tables)
+            ]
+        )
+
+    def _get_table_entries(self, tables: list[tuple[str | None, str, str]]) -> 
list[TableEntry]:
+        """Pair each table's display name with its comment, capped, read once 
per schema."""
+        inspector = self._get_inspector()
+        comments = {
+            table_schema: self._get_table_comments(inspector, table_schema)
+            for table_schema in {table_schema for table_schema, _, _ in tables}
+        }
+        return [
+            (display, truncate_comment(comment) if (comment := 
comments[table_schema].get(name)) else None)

Review Comment:
   Change the the catalog to keep the full comment now and the cut happens only 
when a result goes back to the agent. The full text is masked first, since the 
catalog is also what a custom backend receives.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to