From e3b6c14104c8de9afa5e0d4883be828514552e09 Mon Sep 17 00:00:00 2001 From: IA-domcom Date: Sat, 3 Jan 2026 09:52:32 -0600 Subject: [PATCH] =?UTF-8?q?Se=20cre=C3=B3=20con=20Colab?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Untitled1.ipynb | 1539 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 1539 insertions(+) create mode 100644 Untitled1.ipynb diff --git a/Untitled1.ipynb b/Untitled1.ipynb new file mode 100644 index 00000000..5e2cb3e2 --- /dev/null +++ b/Untitled1.ipynb @@ -0,0 +1,1539 @@ +{ + "nbformat": 4, + "nbformat_minor": 0, + "metadata": { + "colab": { + "provenance": [], + "authorship_tag": "ABX9TyP8XKapzxIea8RHHYkcjDu/", + "include_colab_link": true + }, + "kernelspec": { + "name": "python3", + "display_name": "Python 3" + }, + "language_info": { + "name": "python" + } + }, + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "id": "view-in-github", + "colab_type": "text" + }, + "source": [ + "\"Open" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 494 + }, + "id": "eSGeOEQiivlh", + "outputId": "c201c88f-b4ef-4345-99ce-7e1289b0eb92" + }, + "outputs": [ + { + "output_type": "error", + "ename": "NameError", + "evalue": "name 'Python' is not defined", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)", + "\u001b[0;32m/tmp/ipython-input-2787836168.py\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mPython\u001b[0m\u001b[0;31m# --- CÓDIGO CLAVE DEL DIRECTOR ---\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 2\u001b[0m \u001b[0;32mfrom\u001b[0m \u001b[0mlangchain\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0magents\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0minitialize_agent\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mAgentType\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mTool\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 3\u001b[0m \u001b[0;32mfrom\u001b[0m \u001b[0mlangchain_openai\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0mChatOpenAI\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 4\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 5\u001b[0m \u001b[0mllm\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mChatOpenAI\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mtemperature\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;36m0.0\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mmodel\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m\"gpt-4\"\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;31m# El cerebro\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;31mNameError\u001b[0m: name 'Python' is not defined" + ] + } + ], + "source": [ + "Python# --- CÓDIGO CLAVE DEL DIRECTOR ---\n", + "from langchain.agents import initialize_agent, AgentType, Tool\n", + "from langchain_openai import ChatOpenAI\n", + "\n", + "llm = ChatOpenAI(temperature=0.0, model=\"gpt-4\") # El cerebro\n", + "tools = [tool_documentos, tool_web_search] # Las herramientas\n", + "\n", + "# Inicializa el Agente Director\n", + "agent_director = initialize_agent(\n", + " tools,\n", + " llm,\n", + " agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION, # Le permite razonar y elegir\n", + " verbose=True, # ¡Esto es CLAVE! Muestra el CoT.\n", + " handle_parsing_errors=True\n", + ")\n", + "\n", + "# La Pregunta que requiere a AMBOS Agentes:\n", + "pregunta_compleja = \"Necesito saber qué es JAX (usa el compendio) y cuál es el precio aproximado de la GPU H100 (usa la web), dame una conclusión combinada.\"\n", + "\n", + "agent_director.run(pregunta_compleja)" + ] + }, + { + "cell_type": "code", + "source": [ + "from google.colab import auth\n", + "auth.authenticate_user()\n", + "\n", + "# Define tu ID de proyecto de Google Cloud\n", + "project_id = 'TU_PROJECT_ID_AQUI'\n", + "\n", + "!gcloud config set project {project_id}\n", + "print(f\"Configurado para el proyecto: {project_id}\")" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "aUfLb6hahtlf", + "outputId": "4daf75d6-cfdf-433a-cfc0-f28f98f6ab20" + }, + "execution_count": null, + "outputs": [ + { + "metadata": { + "tags": null + }, + "name": "stdout", + "output_type": "stream", + "text": [ + "\u001b[1;33mWARNING:\u001b[0m INVALID_ARGUMENT: Request contains an invalid argument.\n", + "Are you sure you wish to set property [core/project] to TU_PROJECT_ID_AQUI?\n", + "\n", + "Do you want to continue (Y/n)? " + ] + } + ] + }, + { + "cell_type": "code", + "source": [ + "Aquí tienes el código completo para copiar y pegar:\n", + "\n", + "```jsx\n", + "import React, { useState } from 'react';\n", + "import { Send, Plus, Trash2, Calendar, Hash, Image, FileText, CheckCircle, Clock, AlertCircle } from 'lucide-react';\n", + "\n", + "const MultiPlatformAgent = () => {\n", + " const [posts, setPosts] = useState([]);\n", + " const [currentPost, setCurrentPost] = useState({\n", + " content: '',\n", + " platforms: [],\n", + " schedule: '',\n", + " hashtags: '',\n", + " mediaType: 'text'\n", + " });\n", + "\n", + " const platforms = [\n", + " { id: 'twitter', name: 'Twitter/X', color: 'bg-black', maxChars: 280 },\n", + " { id: 'instagram', name: 'Instagram', color: 'bg-gradient-to-r from-purple-500 to-pink-500', maxChars: 2200 },\n", + " { id: 'facebook', name: 'Facebook', color: 'bg-blue-600', maxChars: 63206 },\n", + " { id: 'linkedin', name: 'LinkedIn', color: 'bg-blue-700', maxChars: 3000 },\n", + " { id: 'tiktok', name: 'TikTok', color: 'bg-black', maxChars: 2200 }\n", + " ];\n", + "\n", + " const togglePlatform = (platformId) => {\n", + " setCurrentPost(prev => ({\n", + " ...prev,\n", + " platforms: prev.platforms.includes(platformId)\n", + " ? prev.platforms.filter(p => p !== platformId)\n", + " : [...prev.platforms, platformId]\n", + " }));\n", + " };\n", + "\n", + " const addPost = () => {\n", + " if (!currentPost.content.trim() || currentPost.platforms.length === 0) {\n", + " alert('Agrega contenido y selecciona al menos una plataforma');\n", + " return;\n", + " }\n", + "\n", + " const newPost = {\n", + " ...currentPost,\n", + " id: Date.now(),\n", + " status: currentPost.schedule ? 'scheduled' : 'draft',\n", + " createdAt: new Date().toISOString()\n", + " };\n", + "\n", + " setPosts([...posts, newPost]);\n", + " setCurrentPost({\n", + " content: '',\n", + " platforms: [],\n", + " schedule: '',\n", + " hashtags: '',\n", + " mediaType: 'text'\n", + " });\n", + " };\n", + "\n", + " const deletePost = (id) => {\n", + " setPosts(posts.filter(post => post.id !== id));\n", + " };\n", + "\n", + " const publishPost = (id) => {\n", + " setPosts(posts.map(post =>\n", + " post.id === id ? { ...post, status: 'published' } : post\n", + " ));\n", + " };\n", + "\n", + " const getStatusIcon = (status) => {\n", + " switch(status) {\n", + " case 'published': return ;\n", + " case 'scheduled': return ;\n", + " default: return ;\n", + " }\n", + " };\n", + "\n", + " const getCharLimit = () => {\n", + " if (currentPost.platforms.length === 0) return null;\n", + " const limits = currentPost.platforms.map(p =>\n", + " platforms.find(pl => pl.id === p)?.maxChars || 0\n", + " );\n", + " return Math.min(...limits);\n", + " };\n", + "\n", + " const charLimit = getCharLimit();\n", + " const isOverLimit = charLimit && currentPost.content.length > charLimit;\n", + "\n", + " return (\n", + "
\n", + "
\n", + "
\n", + "

\n", + " 🤖 Agente Multiplataforma\n", + "

\n", + "

Automatiza tu contenido en todas las redes

\n", + "
\n", + "\n", + "
\n", + " {/* Panel de Creación */}\n", + "
\n", + "

Crear Contenido

\n", + "\n", + " {/* Selección de Plataformas */}\n", + "
\n", + " \n", + "
\n", + " {platforms.map(platform => (\n", + " togglePlatform(platform.id)}\n", + " className={`px-4 py-2 rounded-lg font-medium transition-all ${\n", + " currentPost.platforms.includes(platform.id)\n", + " ? `${platform.color} text-white shadow-lg scale-105`\n", + " : 'bg-white/20 text-white hover:bg-white/30'\n", + " }`}\n", + " >\n", + " {platform.name}\n", + " \n", + " ))}\n", + "
\n", + "
\n", + "\n", + " {/* Tipo de Contenido */}\n", + "
\n", + " \n", + "
\n", + " {[\n", + " { id: 'text', icon: FileText, label: 'Texto' },\n", + " { id: 'image', icon: Image, label: 'Imagen' },\n", + " { id: 'video', icon: FileText, label: 'Video' }\n", + " ].map(type => (\n", + " setCurrentPost({ ...currentPost, mediaType: type.id })}\n", + " className={`flex items-center gap-2 px-4 py-2 rounded-lg transition-all ${\n", + " currentPost.mediaType === type.id\n", + " ? 'bg-purple-600 text-white'\n", + " : 'bg-white/20 text-white hover:bg-white/30'\n", + " }`}\n", + " >\n", + " \n", + " {type.label}\n", + " \n", + " ))}\n", + "
\n", + "
\n", + "\n", + " {/* Contenido */}\n", + "
\n", + " \n", + " setCurrentPost({ ...currentPost, content: e.target.value })}\n", + " placeholder=\"Escribe tu contenido aquí...\"\n", + " className=\"w-full h-32 bg-white/20 text-white placeholder-white/50 rounded-lg p-3 border border-white/30 focus:border-purple-400 focus:outline-none\"\n", + " />\n", + " {charLimit && (\n", + "
\n", + " {currentPost.content.length} / {charLimit} caracteres\n", + " {isOverLimit && ' (Excede el límite)'}\n", + "
\n", + " )}\n", + "
\n", + "\n", + " {/* Hashtags */}\n", + "
\n", + " \n", + " setCurrentPost({ ...currentPost, hashtags: e.target.value })}\n", + " placeholder=\"#marketing #contenido #social\"\n", + " className=\"w-full bg-white/20 text-white placeholder-white/50 rounded-lg p-3 border border-white/30 focus:border-purple-400 focus:outline-none\"\n", + " />\n", + "
\n", + "\n", + " {/* Programación */}\n", + "
\n", + " \n", + " setCurrentPost({ ...currentPost, schedule: e.target.value })}\n", + " className=\"w-full bg-white/20 text-white rounded-lg p-3 border border-white/30 focus:border-purple-400 focus:outline-none\"\n", + " />\n", + "
\n", + "\n", + " \n", + " \n", + " Agregar a la Cola\n", + " \n", + "
\n", + "\n", + " {/* Panel de Posts */}\n", + "
\n", + "

\n", + " Posts ({posts.length})\n", + "

\n", + "\n", + "
\n", + " {posts.length === 0 ? (\n", + "
\n", + " No hay posts aún\n", + "
\n", + " ) : (\n", + " posts.map(post => (\n", + "
\n", + "
\n", + "
\n", + " {getStatusIcon(post.status)}\n", + " \n", + " {post.status}\n", + " \n", + "
\n", + " deletePost(post.id)}\n", + " className=\"text-red-400 hover:text-red-300\"\n", + " >\n", + " \n", + " \n", + "
\n", + "\n", + "

\n", + " {post.content}\n", + "

\n", + "\n", + " {post.hashtags && (\n", + "

\n", + " {post.hashtags}\n", + "

\n", + " )}\n", + "\n", + "
\n", + " {post.platforms.map(platformId => {\n", + " const platform = platforms.find(p => p.id === platformId);\n", + " return (\n", + " \n", + " {platform.name}\n", + " \n", + " );\n", + " })}\n", + "
\n", + "\n", + " {post.schedule && (\n", + "

\n", + " 📅 {new Date(post.schedule).toLocaleString('es-ES')}\n", + "

\n", + " )}\n", + "\n", + " {post.status !== 'published' && (\n", + " publishPost(post.id)}\n", + " className=\"w-full bg-green-600 text-white py-2 rounded text-sm font-medium hover:bg-green-500 transition-colors flex items-center justify-center gap-2\"\n", + " >\n", + " \n", + " Publicar Ahora\n", + " \n", + " )}\n", + "
\n", + " ))\n", + " )}\n", + "
\n", + "
\n", + "
\n", + "\n", + " {/* Estadísticas */}\n", + "
\n", + " {[\n", + " { label: 'Total Posts', value: posts.length, color: 'from-blue-500 to-blue-600' },\n", + " { label: 'Publicados', value: posts.filter(p => p.status === 'published').length, color: 'from-green-500 to-green-600' },\n", + " { label: 'Programados', value: posts.filter(p => p.status === 'scheduled').length, color: 'from-purple-500 to-purple-600' },\n", + " { label: 'Borradores', value: posts.filter(p => p.status === 'draft').length, color: 'from-gray-500 to-gray-600' }\n", + " ].map(stat => (\n", + "
\n", + "
{stat.label}
\n", + "
{stat.value}
\n", + "
\n", + " ))}\n", + "
\n", + "
\n", + "
\n", + " )Aquí tienes el código completo para copiar y pegar:\n", + "\n", + "```jsx\n", + "import React, { useState } from 'react';\n", + "import { Send, Plus, Trash2, Calendar, Hash, Image, FileText, CheckCircle, Clock, AlertCircle } from 'lucide-react';\n", + "\n", + "const MultiPlatformAgent = () => {\n", + " const [posts, setPosts] = useState([]);\n", + " const [currentPost, setCurrentPost] = useState({\n", + " content: '',\n", + " platforms: [],\n", + " schedule: '',\n", + " hashtags: '',\n", + " mediaType: 'text'\n", + " });\n", + "\n", + " const platforms = [\n", + " { id: 'twitter', name: 'Twitter/X', color: 'bg-black', maxChars: 280 },\n", + " { id: 'instagram', name: 'Instagram', color: 'bg-gradient-to-r from-purple-500 to-pink-500', maxChars: 2200 },\n", + " { id: 'facebook', name: 'Facebook', color: 'bg-blue-600', maxChars: 63206 },\n", + " { id: 'linkedin', name: 'LinkedIn', color: 'bg-blue-700', maxChars: 3000 },\n", + " { id: 'tiktok', name: 'TikTok', color: 'bg-black', maxChars: 2200 }\n", + " ];\n", + "\n", + " const togglePlatform = (platformId) => {\n", + " setCurrentPost(prev => ({\n", + " ...prev,\n", + " platforms: prev.platforms.includes(platformId)\n", + " ? prev.platforms.filter(p => p !== platformId)\n", + " : [...prev.platforms, platformId]\n", + " }));\n", + " };\n", + "\n", + " const addPost = () => {\n", + " if (!currentPost.content.trim() || currentPost.platforms.length === 0) {\n", + " alert('Agrega contenido y selecciona al menos una plataforma');\n", + " return;\n", + " }\n", + "\n", + " const newPost = {\n", + " ...currentPost,\n", + " id: Date.now(),\n", + " status: currentPost.schedule ? 'scheduled' : 'draft',\n", + " createdAt: new Date().toISOString()\n", + " };\n", + "\n", + " setPosts([...posts, newPost]);\n", + " setCurrentPost({\n", + " content: '',\n", + " platforms: [],\n", + " schedule: '',\n", + " hashtags: '',\n", + " mediaType: 'text'\n", + " });\n", + " };\n", + "\n", + " const deletePost = (id) => {\n", + " setPosts(posts.filter(post => post.id !== id));\n", + " };\n", + "\n", + " const publishPost = (id) => {\n", + " setPosts(posts.map(post =>\n", + " post.id === id ? { ...post, status: 'published' } : post\n", + " ));\n", + " };\n", + "\n", + " const getStatusIcon = (status) => {\n", + " switch(status) {\n", + " case 'published': return ;\n", + " case 'scheduled': return ;\n", + " default: return ;\n", + " }\n", + " };\n", + "\n", + " const getCharLimit = () => {\n", + " if (currentPost.platforms.length === 0) return null;\n", + " const limits = currentPost.platforms.map(p =>\n", + " platforms.find(pl => pl.id === p)?.maxChars || 0\n", + " );\n", + " return Math.min(...limits);\n", + " };\n", + "\n", + " const charLimit = getCharLimit();\n", + " const isOverLimit = charLimit && currentPost.content.length > charLimit;\n", + "\n", + " return (\n", + "
\n", + "
\n", + "
\n", + "

\n", + " 🤖 Agente Multiplataforma\n", + "

\n", + "

Automatiza tu contenido en todas las redes

\n", + "
\n", + "\n", + "
\n", + " {/* Panel de Creación */}\n", + "
\n", + "

Crear Contenido

\n", + "\n", + " {/* Selección de Plataformas */}\n", + "
\n", + " \n", + "
\n", + " {platforms.map(platform => (\n", + " togglePlatform(platform.id)}\n", + " className={`px-4 py-2 rounded-lg font-medium transition-all ${\n", + " currentPost.platforms.includes(platform.id)\n", + " ? `${platform.color} text-white shadow-lg scale-105`\n", + " : 'bg-white/20 text-white hover:bg-white/30'\n", + " }`}\n", + " >\n", + " {platform.name}\n", + " \n", + " ))}\n", + "
\n", + "
\n", + "\n", + " {/* Tipo de Contenido */}\n", + "
\n", + " \n", + "
\n", + " {[\n", + " { id: 'text', icon: FileText, label: 'Texto' },\n", + " { id: 'image', icon: Image, label: 'Imagen' },\n", + " { id: 'video', icon: FileText, label: 'Video' }\n", + " ].map(type => (\n", + " setCurrentPost({ ...currentPost, mediaType: type.id })}\n", + " className={`flex items-center gap-2 px-4 py-2 rounded-lg transition-all ${\n", + " currentPost.mediaType === type.id\n", + " ? 'bg-purple-600 text-white'\n", + " : 'bg-white/20 text-white hover:bg-white/30'\n", + " }`}\n", + " >\n", + " \n", + " {type.label}\n", + " \n", + " ))}\n", + "
\n", + "
\n", + "\n", + " {/* Contenido */}\n", + "
\n", + " \n", + " setCurrentPost({ ...currentPost, content: e.target.value })}\n", + " placeholder=\"Escribe tu contenido aquí...\"\n", + " className=\"w-full h-32 bg-white/20 text-white placeholder-white/50 rounded-lg p-3 border border-white/30 focus:border-purple-400 focus:outline-none\"\n", + " />\n", + " {charLimit && (\n", + "
\n", + " {currentPost.content.length} / {charLimit} caracteres\n", + " {isOverLimit && ' (Excede el límite)'}\n", + "
\n", + " )}\n", + "
\n", + "\n", + " {/* Hashtags */}\n", + "
\n", + " \n", + " setCurrentPost({ ...currentPost, hashtags: e.target.value })}\n", + " placeholder=\"#marketing #contenido #social\"\n", + " className=\"w-full bg-white/20 text-white placeholder-white/50 rounded-lg p-3 border border-white/30 focus:border-purple-400 focus:outline-none\"\n", + " />\n", + "
\n", + "\n", + " {/* Programación */}\n", + "
\n", + " \n", + " setCurrentPost({ ...currentPost, schedule: e.target.value })}\n", + " className=\"w-full bg-white/20 text-white rounded-lg p-3 border border-white/30 focus:border-purple-400 focus:outline-none\"\n", + " />\n", + "
\n", + "\n", + " \n", + " \n", + " Agregar a la Cola\n", + " \n", + "
\n", + "\n", + " {/* Panel de Posts */}\n", + "
\n", + "

\n", + " Posts ({posts.length})\n", + "

\n", + "\n", + "
\n", + " {posts.length === 0 ? (\n", + "
\n", + " No hay posts aún\n", + "
\n", + " ) : (\n", + " posts.map(post => (\n", + "
\n", + "
\n", + "
\n", + " {getStatusIcon(post.status)}\n", + " \n", + " {post.status}\n", + " \n", + "
\n", + " deletePost(post.id)}\n", + " className=\"text-red-400 hover:text-red-300\"\n", + " >\n", + " \n", + " \n", + "
\n", + "\n", + "

\n", + " {post.content}\n", + "

\n", + "\n", + " {post.hashtags && (\n", + "

\n", + " {post.hashtags}\n", + "

\n", + " )}\n", + "\n", + "
\n", + " {post.platforms.map(platformId => {\n", + " const platform = platforms.find(p => p.id === platformId);\n", + " return (\n", + " \n", + " {platform.name}\n", + " \n", + " );\n", + " })}\n", + "
\n", + "\n", + " {post.schedule && (\n", + "

\n", + " 📅 {new Date(post.schedule).toLocaleString('es-ES')}\n", + "

\n", + " )}\n", + "\n", + " {post.status !== 'published' && (\n", + " publishPost(post.id)}\n", + " className=\"w-full bg-green-600 text-white py-2 rounded text-sm font-medium hover:bg-green-500 transition-colors flex items-center justify-center gap-2\"\n", + " >\n", + " \n", + " Publicar Ahora\n", + " \n", + " )}\n", + "
\n", + " ))\n", + " )}\n", + "
\n", + "
\n", + "
\n", + "\n", + " {/* Estadísticas */}\n", + "
\n", + " {[\n", + " { label: 'Total Posts', value: posts.length, color: 'from-blue-500 to-blue-600' },\n", + " { label: 'Publicados', value: posts.filter(p => p.status === 'published').length, color: 'from-green-500 to-green-600' },\n", + " { label: 'Programados', value: posts.filter(p => p.status === 'scheduled').length, color: 'from-purple-500 to-purple-600' },\n", + " { label: 'Borradores', value: posts.filter(p => p.status === 'draft').length, color: 'from-gray-500 to-gray-600' }\n", + " ].map(stat => (\n", + "
\n", + "
{stat.label}
\n", + "
{stat.value}
\n", + "
\n", + " ))}\n", + "
\n", + "
\n", + "
\n", + " );\n", + "};\n", + "\n", + "export default MultiPlatformAgent;\n", + "```\n", + "\n", + "**Para usarlo necesitas:**\n", + "\n", + "1. **Instalar las dependencias:**\n", + "```bash\n", + "npm install lucide-react\n", + "```\n", + "\n", + "2. **Tener Tailwind CSS configurado** en tu proyecto React\n", + "\n", + "3. **Importar el componente** en tu App.js o donde lo necesites:\n", + "```jsx\n", + "import MultiPlatformAgent from './MultiPlatformAgent';\n", + "\n", + "function App() {\n", + " return ;\n", + "}\n", + "```\n", + "\n", + "¡Listo para copiar y pegar! 🚀\n", + "\n", + ";\n", + "};\n", + "\n", + "export default MultiPlatformAgent;\n", + "```\n", + "\n", + "**Para usarlo necesitas:**\n", + "\n", + "1. **Instalar las dependencias:**\n", + "```bash\n", + "npm install lucide-react\n", + "```\n", + "\n", + "2. **Tener Tailwind CSS configurado** en tu proyecto React\n", + "\n", + "3. **Importar el componente** en tu App.js o donde lo necesites:\n", + "```jsx\n", + "import MultiPlatformAgent from './MultiPlatformAgent';\n", + "\n", + "function App() {\n", + " return ;\n", + "}\n", + "```\n", + "\n", + "¡Listo para copiar y pegar! 🚀" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 110 + }, + "id": "P1XAZM5UTyht", + "outputId": "dbe0e3d9-04c7-432d-eae3-bc224c1c81a5" + }, + "execution_count": null, + "outputs": [ + { + "output_type": "error", + "ename": "SyntaxError", + "evalue": "invalid character '🤖' (U+1F916) (ipython-input-2910247751.py, line 91)", + "traceback": [ + "\u001b[0;36m File \u001b[0;32m\"/tmp/ipython-input-2910247751.py\"\u001b[0;36m, line \u001b[0;32m91\u001b[0m\n\u001b[0;31m 🤖 Agente Multiplataforma\u001b[0m\n\u001b[0m ^\u001b[0m\n\u001b[0;31mSyntaxError\u001b[0m\u001b[0;31m:\u001b[0m invalid character '🤖' (U+1F916)\n" + ] + } + ] + }, + { + "cell_type": "markdown", + "source": [], + "metadata": { + "id": "SPA2JSGnkq5u" + } + }, + { + "cell_type": "markdown", + "metadata": { + "id": "118ec447" + }, + "source": [ + "# Task\n", + "Define placeholder LangChain Tool objects for `tool_documentos` and `tool_web_search`. Then, initialize and run the `agent_director` using these tools and the question \"Necesito saber qué es JAX y el precio de la GPU H100. Concluye con un resumen combinado.\" Finally, summarize the combined conclusion provided by the `agent_director`." + ] + }, + { + "cell_type": "code", + "source": [ + "Nano" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 275 + }, + "id": "6VFVf_doamzQ", + "outputId": "5a0613eb-82b9-4d7e-f68e-167207e12b25" + }, + "execution_count": null, + "outputs": [ + { + "output_type": "error", + "ename": "NameError", + "evalue": "name 'Nano' is not defined", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)", + "\u001b[0;32m/tmp/ipython-input-4081686929.py\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mNano\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", + "\u001b[0;31mNameError\u001b[0m: name 'Nano' is not defined" + ] + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "7894f7e6" + }, + "source": [ + "## Define tool_documentos\n", + "\n", + "### Subtask:\n", + "Define the `tool_documentos` variable as a LangChain Tool object. This will be a placeholder since its actual implementation is not provided, but it's necessary for initializing the `agent_director`.\n" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "7b351c0f" + }, + "source": [ + "**Reasoning**:\n", + "I need to define the `tool_documentos` variable as a LangChain Tool object according to the instructions provided.\n", + "\n" + ] + }, + { + "cell_type": "code", + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 879 + }, + "id": "0b3e7929", + "outputId": "003b426f-6749-4754-e56c-3b89f126114a" + }, + "source": [ + "from langchain.tools import Tool\n", + "\n", + "tool_documentos = Tool(\n", + " name='tool_documentos',\n", + " func=lambda x: 'documentos not found',\n", + " description='Placeholder tool for document search'\n", + ")\n", + "\n", + "print(\"tool_documentos defined as a LangChain Tool object.\")" + ], + "execution_count": null, + "outputs": [ + { + "output_type": "error", + "ename": "ImportError", + "evalue": "cannot import name 'Tool' from 'langchain.tools' (/usr/local/lib/python3.12/dist-packages/langchain/tools/__init__.py)", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mImportError\u001b[0m Traceback (most recent call last)", + "\u001b[0;32m/tmp/ipython-input-192102382.py\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0;32mfrom\u001b[0m \u001b[0mlangchain\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mtools\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0mTool\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 2\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 3\u001b[0m tool_documentos = Tool(\n\u001b[1;32m 4\u001b[0m \u001b[0mname\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m'tool_documentos'\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 5\u001b[0m \u001b[0mfunc\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mlambda\u001b[0m \u001b[0mx\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0;34m'documentos not found'\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;31mImportError\u001b[0m: cannot import name 'Tool' from 'langchain.tools' (/usr/local/lib/python3.12/dist-packages/langchain/tools/__init__.py)", + "", + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0;32m\nNOTE: If your import is failing due to a missing package, you can\nmanually install dependencies using either !pip or !apt.\n\nTo view examples of installing some common dependencies, click the\n\"Open Examples\" button below.\n\u001b[0;31m---------------------------------------------------------------------------\u001b[0m\n" + ], + "errorDetails": { + "actions": [ + { + "action": "open_url", + "actionText": "Open Examples", + "url": "/notebooks/snippets/importing_libraries.ipynb" + } + ] + } + } + ] + }, + { + "cell_type": "markdown", + "source": [], + "metadata": { + "id": "ektMCKN8XHzO" + } + }, + { + "cell_type": "markdown", + "metadata": { + "id": "c9c8086d" + }, + "source": [ + "**Reasoning**:\n", + "The previous code failed because the `Tool` class could not be imported from `langchain.tools` due to changes in the LangChain library's structure. I will correct the import statement to `from langchain_core.tools import Tool`.\n", + "\n" + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "838fbcd5" + }, + "source": [ + "from langchain_core.tools import Tool\n", + "\n", + "tool_documentos = Tool(\n", + " name='tool_documentos',\n", + " func=lambda x: 'documentos not found',\n", + " description='Placeholder tool for document search'\n", + ")\n", + "\n", + "print(\"tool_documentos defined as a LangChain Tool object.\")" + ], + "execution_count": null, + "outputs": [] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "18d7be8d" + }, + "source": [ + "**Reasoning**:\n", + "The previous subtask successfully defined `tool_documentos`. Now, I need to define the `tool_web_search` variable as a LangChain Tool object, following the pattern of the previous step to complete the task of defining placeholder tools.\n", + "\n" + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "3f322eea" + }, + "source": [ + "from langchain_core.tools import Tool\n", + "\n", + "tool_web_search = Tool(\n", + " name='tool_web_search',\n", + " func=lambda x: 'web search not found',\n", + " description='Placeholder tool for web search'\n", + ")\n", + "\n", + "print(\"tool_web_search defined as a LangChain Tool object.\")" + ], + "execution_count": null, + "outputs": [] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "1c84cfa2" + }, + "source": [ + "## Initialize and run the `agent_director`\n", + "\n", + "### Subtask:\n", + "Initialize and run the `agent_director` using the previously defined `tool_documentos` and `tool_web_search` objects, along with the specified question.\n", + "\n", + "#### Instructions:\n", + "1. Import necessary components for `agent_director` and its dependencies (e.g., `ChatOpenAI`, `AgentExecutor`, etc., depending on the intended implementation of `agent_director`).\n", + "2. Instantiate `agent_director` with the `tools` list containing `tool_documentos` and `tool_web_search`.\n", + "3. Run the `agent_director` with the question: \"Necesito saber qué es JAX y el precio de la GPU H100. Concluye con un resumen combinado.\"\n", + "4. Print the output from the `agent_director`." + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "677d3480" + }, + "source": [ + "**Reasoning**:\n", + "I need to initialize and run the agent director. This involves setting up the environment for OpenAI, importing the necessary LangChain components such as the ChatOpenAI model, creating a prompt template, defining the agent using `create_react_agent`, and then creating and running an `AgentExecutor` with the previously defined tools and the given question.\n", + "\n" + ] + }, + { + "cell_type": "code", + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 914 + }, + "id": "f89619a0", + "outputId": "9ac52640-d6e8-450f-b6de-0b5df6098422" + }, + "source": [ + "import os\n", + "from langchain_openai import ChatOpenAI\n", + "from langchain import hub\n", + "from langchain.agents import AgentExecutor, create_react_agent\n", + "from langchain_core.prompts import ChatPromptTemplate, MessagesPlaceholder\n", + "\n", + "# Set your OpenAI API key here\n", + "# os.environ[\"OPENAI_API_KEY\"] = \"YOUR_OPENAI_API_KEY\"\n", + "\n", + "# Verify if the API key is set\n", + "if \"OPENAI_API_KEY\" not in os.environ:\n", + " print(\"WARNING: OPENAI_API_KEY environment variable not set. Please set it to proceed.\")\n", + " print(\"You can set it like this: os.environ[\\\"OPENAI_API_KEY\\\"] = \\\"YOUR_OPENAI_API_KEY\\\"\")\n", + "\n", + "# Initialize the LLM\n", + "llm = ChatOpenAI(model=\"gpt-4-turbo-preview\", temperature=0)\n", + "\n", + "# Get the standard ReAct prompt from LangChain Hub\n", + "prompt = hub.pull(\"hwchase17/react\")\n", + "\n", + "# Define the tools list\n", + "tools = [tool_documentos, tool_web_search]\n", + "\n", + "# Create the agent\n", + "agent = create_react_agent(llm, tools, prompt)\n", + "\n", + "# Create the AgentExecutor (this will be our 'agent_director')\n", + "agent_director = AgentExecutor(agent=agent, tools=tools, verbose=True, handle_parsing_errors=True)\n", + "\n", + "# Define the question\n", + "question = \"Necesito saber qué es JAX y el precio de la GPU H100. Concluye con un resumen combinado.\"\n", + "\n", + "# Run the agent_director\n", + "print(\"\\nRunning agent_director...\")\n", + "response = agent_director.invoke({\"input\": question})\n", + "\n", + "# Print the combined conclusion\n", + "print(\"\\nCombined Conclusion from agent_director:\")\n", + "print(response[\"output\"])\n", + "\n", + "print(\"Agent director initialized and run successfully.\")" + ], + "execution_count": null, + "outputs": [ + { + "output_type": "error", + "ename": "ModuleNotFoundError", + "evalue": "No module named 'langchain_openai'", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mModuleNotFoundError\u001b[0m Traceback (most recent call last)", + "\u001b[0;32m/tmp/ipython-input-3936825312.py\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0mos\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 2\u001b[0;31m \u001b[0;32mfrom\u001b[0m \u001b[0mlangchain_openai\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0mChatOpenAI\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 3\u001b[0m \u001b[0;32mfrom\u001b[0m \u001b[0mlangchain\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0mhub\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 4\u001b[0m \u001b[0;32mfrom\u001b[0m \u001b[0mlangchain\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0magents\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0mAgentExecutor\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mcreate_react_agent\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 5\u001b[0m \u001b[0;32mfrom\u001b[0m \u001b[0mlangchain_core\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mprompts\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0mChatPromptTemplate\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mMessagesPlaceholder\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;31mModuleNotFoundError\u001b[0m: No module named 'langchain_openai'", + "", + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0;32m\nNOTE: If your import is failing due to a missing package, you can\nmanually install dependencies using either !pip or !apt.\n\nTo view examples of installing some common dependencies, click the\n\"Open Examples\" button below.\n\u001b[0;31m---------------------------------------------------------------------------\u001b[0m\n" + ], + "errorDetails": { + "actions": [ + { + "action": "open_url", + "actionText": "Open Examples", + "url": "/notebooks/snippets/importing_libraries.ipynb" + } + ] + } + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "66ec340d" + }, + "source": [ + "**Reasoning**:\n", + "The previous code failed because the `langchain_openai` package was not found, causing a `ModuleNotFoundError`. I need to install this package using `pip` before attempting to import it.\n", + "\n" + ] + }, + { + "cell_type": "code", + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 1000 + }, + "id": "f31b72f1", + "outputId": "c5c7a60c-3225-4e0f-c5ed-e8dbffa6e305" + }, + "source": [ + "!pip install langchain_openai" + ], + "execution_count": null, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "Collecting langchain_openai\n", + " Downloading langchain_openai-1.1.6-py3-none-any.whl.metadata (2.6 kB)\n", + "Collecting langchain-core<2.0.0,>=1.2.2 (from langchain_openai)\n", + " Downloading langchain_core-1.2.5-py3-none-any.whl.metadata (3.7 kB)\n", + "Requirement already satisfied: openai<3.0.0,>=1.109.1 in /usr/local/lib/python3.12/dist-packages (from langchain_openai) (2.12.0)\n", + "Requirement already satisfied: tiktoken<1.0.0,>=0.7.0 in /usr/local/lib/python3.12/dist-packages (from langchain_openai) (0.12.0)\n", + "Requirement already satisfied: jsonpatch<2.0.0,>=1.33.0 in /usr/local/lib/python3.12/dist-packages (from langchain-core<2.0.0,>=1.2.2->langchain_openai) (1.33)\n", + "Requirement already satisfied: langsmith<1.0.0,>=0.3.45 in /usr/local/lib/python3.12/dist-packages (from langchain-core<2.0.0,>=1.2.2->langchain_openai) (0.4.59)\n", + "Requirement already satisfied: packaging<26.0.0,>=23.2.0 in /usr/local/lib/python3.12/dist-packages (from langchain-core<2.0.0,>=1.2.2->langchain_openai) (25.0)\n", + "Requirement already satisfied: pydantic<3.0.0,>=2.7.4 in /usr/local/lib/python3.12/dist-packages (from langchain-core<2.0.0,>=1.2.2->langchain_openai) (2.12.3)\n", + "Requirement already satisfied: pyyaml<7.0.0,>=5.3.0 in /usr/local/lib/python3.12/dist-packages (from langchain-core<2.0.0,>=1.2.2->langchain_openai) (6.0.3)\n", + "Requirement already satisfied: tenacity!=8.4.0,<10.0.0,>=8.1.0 in /usr/local/lib/python3.12/dist-packages (from langchain-core<2.0.0,>=1.2.2->langchain_openai) (9.1.2)\n", + "Requirement already satisfied: typing-extensions<5.0.0,>=4.7.0 in /usr/local/lib/python3.12/dist-packages (from langchain-core<2.0.0,>=1.2.2->langchain_openai) (4.15.0)\n", + "Requirement already satisfied: uuid-utils<1.0,>=0.12.0 in /usr/local/lib/python3.12/dist-packages (from langchain-core<2.0.0,>=1.2.2->langchain_openai) (0.12.0)\n", + "Requirement already satisfied: anyio<5,>=3.5.0 in /usr/local/lib/python3.12/dist-packages (from openai<3.0.0,>=1.109.1->langchain_openai) (4.12.0)\n", + "Requirement already satisfied: distro<2,>=1.7.0 in /usr/local/lib/python3.12/dist-packages (from openai<3.0.0,>=1.109.1->langchain_openai) (1.9.0)\n", + "Requirement already satisfied: httpx<1,>=0.23.0 in /usr/local/lib/python3.12/dist-packages (from openai<3.0.0,>=1.109.1->langchain_openai) (0.28.1)\n", + "Requirement already satisfied: jiter<1,>=0.10.0 in /usr/local/lib/python3.12/dist-packages (from openai<3.0.0,>=1.109.1->langchain_openai) (0.12.0)\n", + "Requirement already satisfied: sniffio in /usr/local/lib/python3.12/dist-packages (from openai<3.0.0,>=1.109.1->langchain_openai) (1.3.1)\n", + "Requirement already satisfied: tqdm>4 in /usr/local/lib/python3.12/dist-packages (from openai<3.0.0,>=1.109.1->langchain_openai) (4.67.1)\n", + "Requirement already satisfied: regex>=2022.1.18 in /usr/local/lib/python3.12/dist-packages (from tiktoken<1.0.0,>=0.7.0->langchain_openai) (2025.11.3)\n", + "Requirement already satisfied: requests>=2.26.0 in /usr/local/lib/python3.12/dist-packages (from tiktoken<1.0.0,>=0.7.0->langchain_openai) (2.32.4)\n", + "Requirement already satisfied: idna>=2.8 in /usr/local/lib/python3.12/dist-packages (from anyio<5,>=3.5.0->openai<3.0.0,>=1.109.1->langchain_openai) (3.11)\n", + "Requirement already satisfied: certifi in /usr/local/lib/python3.12/dist-packages (from httpx<1,>=0.23.0->openai<3.0.0,>=1.109.1->langchain_openai) (2025.11.12)\n", + "Requirement already satisfied: httpcore==1.* in /usr/local/lib/python3.12/dist-packages (from httpx<1,>=0.23.0->openai<3.0.0,>=1.109.1->langchain_openai) (1.0.9)\n", + "Requirement already satisfied: h11>=0.16 in /usr/local/lib/python3.12/dist-packages (from httpcore==1.*->httpx<1,>=0.23.0->openai<3.0.0,>=1.109.1->langchain_openai) (0.16.0)\n", + "Requirement already satisfied: jsonpointer>=1.9 in /usr/local/lib/python3.12/dist-packages (from jsonpatch<2.0.0,>=1.33.0->langchain-core<2.0.0,>=1.2.2->langchain_openai) (3.0.0)\n", + "Requirement already satisfied: orjson>=3.9.14 in /usr/local/lib/python3.12/dist-packages (from langsmith<1.0.0,>=0.3.45->langchain-core<2.0.0,>=1.2.2->langchain_openai) (3.11.5)\n", + "Requirement already satisfied: requests-toolbelt>=1.0.0 in /usr/local/lib/python3.12/dist-packages (from langsmith<1.0.0,>=0.3.45->langchain-core<2.0.0,>=1.2.2->langchain_openai) (1.0.0)\n", + "Requirement already satisfied: zstandard>=0.23.0 in /usr/local/lib/python3.12/dist-packages (from langsmith<1.0.0,>=0.3.45->langchain-core<2.0.0,>=1.2.2->langchain_openai) (0.25.0)\n", + "Requirement already satisfied: annotated-types>=0.6.0 in /usr/local/lib/python3.12/dist-packages (from pydantic<3.0.0,>=2.7.4->langchain-core<2.0.0,>=1.2.2->langchain_openai) (0.7.0)\n", + "Requirement already satisfied: pydantic-core==2.41.4 in /usr/local/lib/python3.12/dist-packages (from pydantic<3.0.0,>=2.7.4->langchain-core<2.0.0,>=1.2.2->langchain_openai) (2.41.4)\n", + "Requirement already satisfied: typing-inspection>=0.4.2 in /usr/local/lib/python3.12/dist-packages (from pydantic<3.0.0,>=2.7.4->langchain-core<2.0.0,>=1.2.2->langchain_openai) (0.4.2)\n", + "Requirement already satisfied: charset_normalizer<4,>=2 in /usr/local/lib/python3.12/dist-packages (from requests>=2.26.0->tiktoken<1.0.0,>=0.7.0->langchain_openai) (3.4.4)\n", + "Requirement already satisfied: urllib3<3,>=1.21.1 in /usr/local/lib/python3.12/dist-packages (from requests>=2.26.0->tiktoken<1.0.0,>=0.7.0->langchain_openai) (2.5.0)\n", + "Downloading langchain_openai-1.1.6-py3-none-any.whl (84 kB)\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m84.7/84.7 kB\u001b[0m \u001b[31m3.3 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[?25hDownloading langchain_core-1.2.5-py3-none-any.whl (484 kB)\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m484.9/484.9 kB\u001b[0m \u001b[31m12.3 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[?25hInstalling collected packages: langchain-core, langchain_openai\n", + " Attempting uninstall: langchain-core\n", + " Found existing installation: langchain-core 1.2.1\n", + " Uninstalling langchain-core-1.2.1:\n", + " Successfully uninstalled langchain-core-1.2.1\n", + "Successfully installed langchain-core-1.2.5 langchain_openai-1.1.6\n" + ] + }, + { + "output_type": "display_data", + "data": { + "application/vnd.colab-display-data+json": { + "pip_warning": { + "packages": [ + "langchain_core" + ] + }, + "id": "d8f7a3e36dd24d1c9c0a5b411c600f8a" + } + }, + "metadata": {} + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "99d41422" + }, + "source": [ + "**Reasoning**:\n", + "The `langchain_openai` package has been successfully installed. Now I need to re-run the previous code block that failed due to `ModuleNotFoundError` to initialize and run the `agent_director`.\n", + "\n" + ] + }, + { + "cell_type": "code", + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 953 + }, + "id": "cc273d51", + "outputId": "77c880f6-9074-4404-99b1-cb808f01a917" + }, + "source": [ + "import os\n", + "from langchain_openai import ChatOpenAI\n", + "from langchain import hub\n", + "from langchain.agents import AgentExecutor, create_react_agent\n", + "from langchain_core.prompts import ChatPromptTemplate, MessagesPlaceholder\n", + "\n", + "# Set your OpenAI API key here\n", + "# os.environ[\"OPENAI_API_KEY\"] = \"YOUR_OPENAI_API_KEY\"\n", + "\n", + "# Verify if the API key is set\n", + "if \"OPENAI_API_KEY\" not in os.environ:\n", + " print(\"WARNING: OPENAI_API_KEY environment variable not set. Please set it to proceed.\")\n", + " print(\"You can set it like this: os.environ[\\\"OPENAI_API_KEY\\\"] = \\\"YOUR_OPENAI_API_KEY\\\"\")\n", + "\n", + "# Initialize the LLM\n", + "llm = ChatOpenAI(model=\"gpt-4-turbo-preview\", temperature=0)\n", + "\n", + "# Get the standard ReAct prompt from LangChain Hub\n", + "prompt = hub.pull(\"hwchase17/react\")\n", + "\n", + "# Define the tools list\n", + "tools = [tool_documentos, tool_web_search]\n", + "\n", + "# Create the agent\n", + "agent = create_react_agent(llm, tools, prompt)\n", + "\n", + "# Create the AgentExecutor (this will be our 'agent_director')\n", + "agent_director = AgentExecutor(agent=agent, tools=tools, verbose=True, handle_parsing_errors=True)\n", + "\n", + "# Define the question\n", + "question = \"Necesito saber qué es JAX y el precio de la GPU H100. Concluye con un resumen combinado.\"\n", + "\n", + "# Run the agent_director\n", + "print(\"\\nRunning agent_director...\")\n", + "response = agent_director.invoke({\"input\": question})\n", + "\n", + "# Print the combined conclusion\n", + "print(\"\\nCombined Conclusion from agent_director:\")\n", + "print(response[\"output\"])\n", + "\n", + "print(\"Agent director initialized and run successfully.\")" + ], + "execution_count": null, + "outputs": [ + { + "output_type": "error", + "ename": "ImportError", + "evalue": "cannot import name 'hub' from 'langchain' (/usr/local/lib/python3.12/dist-packages/langchain/__init__.py)", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mImportError\u001b[0m Traceback (most recent call last)", + "\u001b[0;32m/tmp/ipython-input-3936825312.py\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0mos\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 2\u001b[0m \u001b[0;32mfrom\u001b[0m \u001b[0mlangchain_openai\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0mChatOpenAI\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 3\u001b[0;31m \u001b[0;32mfrom\u001b[0m \u001b[0mlangchain\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0mhub\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 4\u001b[0m \u001b[0;32mfrom\u001b[0m \u001b[0mlangchain\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0magents\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0mAgentExecutor\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mcreate_react_agent\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 5\u001b[0m \u001b[0;32mfrom\u001b[0m \u001b[0mlangchain_core\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mprompts\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0mChatPromptTemplate\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mMessagesPlaceholder\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;31mImportError\u001b[0m: cannot import name 'hub' from 'langchain' (/usr/local/lib/python3.12/dist-packages/langchain/__init__.py)", + "", + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0;32m\nNOTE: If your import is failing due to a missing package, you can\nmanually install dependencies using either !pip or !apt.\n\nTo view examples of installing some common dependencies, click the\n\"Open Examples\" button below.\n\u001b[0;31m---------------------------------------------------------------------------\u001b[0m\n" + ], + "errorDetails": { + "actions": [ + { + "action": "open_url", + "actionText": "Open Examples", + "url": "/notebooks/snippets/importing_libraries.ipynb" + } + ] + } + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "45566bd8" + }, + "source": [ + "**Reasoning**:\n", + "The previous code failed with an `ImportError` because `hub` could not be imported directly from the top-level `langchain` package. This suggests that in the current LangChain version, `hub` functionality has been moved or requires explicit import from `langchain_community`. I will update the import statement to `from langchain_community import hub`.\n", + "\n" + ] + }, + { + "cell_type": "code", + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 933 + }, + "id": "527ab243", + "outputId": "0a186672-5d28-4454-a7e9-c882e4692f0a" + }, + "source": [ + "import os\n", + "from langchain_openai import ChatOpenAI\n", + "from langchain_community import hub\n", + "from langchain.agents import AgentExecutor, create_react_agent\n", + "from langchain_core.prompts import ChatPromptTemplate, MessagesPlaceholder\n", + "\n", + "# Set your OpenAI API key here\n", + "# os.environ[\"OPENAI_API_KEY\"] = \"YOUR_OPENAI_API_KEY\"\n", + "\n", + "# Verify if the API key is set\n", + "if \"OPENAI_API_KEY\" not in os.environ:\n", + " print(\"WARNING: OPENAI_API_KEY environment variable not set. Please set it to proceed.\")\n", + " print(\"You can set it like this: os.environ[\\\"OPENAI_API_KEY\\\"] = \\\"YOUR_OPENAI_API_KEY\\\"\")\n", + "\n", + "# Initialize the LLM\n", + "llm = ChatOpenAI(model=\"gpt-4-turbo-preview\", temperature=0)\n", + "\n", + "# Get the standard ReAct prompt from LangChain Hub\n", + "prompt = hub.pull(\"hwchase17/react\")\n", + "\n", + "# Define the tools list\n", + "tools = [tool_documentos, tool_web_search]\n", + "\n", + "# Create the agent\n", + "agent = create_react_agent(llm, tools, prompt)\n", + "\n", + "# Create the AgentExecutor (this will be our 'agent_director')\n", + "agent_director = AgentExecutor(agent=agent, tools=tools, verbose=True, handle_parsing_errors=True)\n", + "\n", + "# Define the question\n", + "question = \"Necesito saber qué es JAX y el precio de la GPU H100. Concluye con un resumen combinado.\"\n", + "\n", + "# Run the agent_director\n", + "print(\"\\nRunning agent_director...\")\n", + "response = agent_director.invoke({\"input\": question})\n", + "\n", + "# Print the combined conclusion\n", + "print(\"\\nCombined Conclusion from agent_director:\")\n", + "print(response[\"output\"])\n", + "\n", + "print(\"Agent director initialized and run successfully.\")" + ], + "execution_count": null, + "outputs": [ + { + "output_type": "error", + "ename": "ModuleNotFoundError", + "evalue": "No module named 'langchain_community'", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mModuleNotFoundError\u001b[0m Traceback (most recent call last)", + "\u001b[0;32m/tmp/ipython-input-293516664.py\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0mos\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 2\u001b[0m \u001b[0;32mfrom\u001b[0m \u001b[0mlangchain_openai\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0mChatOpenAI\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 3\u001b[0;31m \u001b[0;32mfrom\u001b[0m \u001b[0mlangchain_community\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0mhub\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 4\u001b[0m \u001b[0;32mfrom\u001b[0m \u001b[0mlangchain\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0magents\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0mAgentExecutor\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mcreate_react_agent\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 5\u001b[0m \u001b[0;32mfrom\u001b[0m \u001b[0mlangchain_core\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mprompts\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0mChatPromptTemplate\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mMessagesPlaceholder\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;31mModuleNotFoundError\u001b[0m: No module named 'langchain_community'", + "", + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0;32m\nNOTE: If your import is failing due to a missing package, you can\nmanually install dependencies using either !pip or !apt.\n\nTo view examples of installing some common dependencies, click the\n\"Open Examples\" button below.\n\u001b[0;31m---------------------------------------------------------------------------\u001b[0m\n" + ], + "errorDetails": { + "actions": [ + { + "action": "open_url", + "actionText": "Open Examples", + "url": "/notebooks/snippets/importing_libraries.ipynb" + } + ] + } + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "f9415fd1" + }, + "source": [ + "**Reasoning**:\n", + "The previous code failed because `langchain_community` was not found, causing a `ModuleNotFoundError`. I need to install this package using `pip` before attempting to import it again.\n", + "\n" + ] + }, + { + "cell_type": "code", + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 1000 + }, + "id": "8d034ec1", + "outputId": "313b62c8-7bfd-4c77-b77b-620e4e7849cf", + "collapsed": true + }, + "source": [ + "!pip install langchain_community" + ], + "execution_count": null, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "Collecting langchain_community\n", + " Downloading langchain_community-0.4.1-py3-none-any.whl.metadata (3.0 kB)\n", + "Requirement already satisfied: langchain-core<2.0.0,>=1.0.1 in /usr/local/lib/python3.12/dist-packages (from langchain_community) (1.2.5)\n", + "Collecting langchain-classic<2.0.0,>=1.0.0 (from langchain_community)\n", + " Downloading langchain_classic-1.0.1-py3-none-any.whl.metadata (4.2 kB)\n", + "Requirement already satisfied: SQLAlchemy<3.0.0,>=1.4.0 in /usr/local/lib/python3.12/dist-packages (from langchain_community) (2.0.45)\n", + "Collecting requests<3.0.0,>=2.32.5 (from langchain_community)\n", + " Downloading requests-2.32.5-py3-none-any.whl.metadata (4.9 kB)\n", + "Requirement already satisfied: PyYAML<7.0.0,>=5.3.0 in /usr/local/lib/python3.12/dist-packages (from langchain_community) (6.0.3)\n", + "Requirement already satisfied: aiohttp<4.0.0,>=3.8.3 in /usr/local/lib/python3.12/dist-packages (from langchain_community) (3.13.2)\n", + "Requirement already satisfied: tenacity!=8.4.0,<10.0.0,>=8.1.0 in /usr/local/lib/python3.12/dist-packages (from langchain_community) (9.1.2)\n", + "Collecting dataclasses-json<0.7.0,>=0.6.7 (from langchain_community)\n", + " Downloading dataclasses_json-0.6.7-py3-none-any.whl.metadata (25 kB)\n", + "Requirement already satisfied: pydantic-settings<3.0.0,>=2.10.1 in /usr/local/lib/python3.12/dist-packages (from langchain_community) (2.12.0)\n", + "Requirement already satisfied: langsmith<1.0.0,>=0.1.125 in /usr/local/lib/python3.12/dist-packages (from langchain_community) (0.4.59)\n", + "Requirement already satisfied: httpx-sse<1.0.0,>=0.4.0 in /usr/local/lib/python3.12/dist-packages (from langchain_community) (0.4.3)\n", + "Requirement already satisfied: numpy>=1.26.2 in /usr/local/lib/python3.12/dist-packages (from langchain_community) (2.0.2)\n", + "Requirement already satisfied: aiohappyeyeballs>=2.5.0 in /usr/local/lib/python3.12/dist-packages (from aiohttp<4.0.0,>=3.8.3->langchain_community) (2.6.1)\n", + "Requirement already satisfied: aiosignal>=1.4.0 in /usr/local/lib/python3.12/dist-packages (from aiohttp<4.0.0,>=3.8.3->langchain_community) (1.4.0)\n", + "Requirement already satisfied: attrs>=17.3.0 in /usr/local/lib/python3.12/dist-packages (from aiohttp<4.0.0,>=3.8.3->langchain_community) (25.4.0)\n", + "Requirement already satisfied: frozenlist>=1.1.1 in /usr/local/lib/python3.12/dist-packages (from aiohttp<4.0.0,>=3.8.3->langchain_community) (1.8.0)\n", + "Requirement already satisfied: multidict<7.0,>=4.5 in /usr/local/lib/python3.12/dist-packages (from aiohttp<4.0.0,>=3.8.3->langchain_community) (6.7.0)\n", + "Requirement already satisfied: propcache>=0.2.0 in /usr/local/lib/python3.12/dist-packages (from aiohttp<4.0.0,>=3.8.3->langchain_community) (0.4.1)\n", + "Requirement already satisfied: yarl<2.0,>=1.17.0 in /usr/local/lib/python3.12/dist-packages (from aiohttp<4.0.0,>=3.8.3->langchain_community) (1.22.0)\n", + "Collecting marshmallow<4.0.0,>=3.18.0 (from dataclasses-json<0.7.0,>=0.6.7->langchain_community)\n", + " Downloading marshmallow-3.26.2-py3-none-any.whl.metadata (7.3 kB)\n", + "Collecting typing-inspect<1,>=0.4.0 (from dataclasses-json<0.7.0,>=0.6.7->langchain_community)\n", + " Downloading typing_inspect-0.9.0-py3-none-any.whl.metadata (1.5 kB)\n", + "Collecting langchain-text-splitters<2.0.0,>=1.1.0 (from langchain-classic<2.0.0,>=1.0.0->langchain_community)\n", + " Downloading langchain_text_splitters-1.1.0-py3-none-any.whl.metadata (2.7 kB)\n", + "Requirement already satisfied: pydantic<3.0.0,>=2.7.4 in /usr/local/lib/python3.12/dist-packages (from langchain-classic<2.0.0,>=1.0.0->langchain_community) (2.12.3)\n", + "Requirement already satisfied: jsonpatch<2.0.0,>=1.33.0 in /usr/local/lib/python3.12/dist-packages (from langchain-core<2.0.0,>=1.0.1->langchain_community) (1.33)\n", + "Requirement already satisfied: packaging<26.0.0,>=23.2.0 in /usr/local/lib/python3.12/dist-packages (from langchain-core<2.0.0,>=1.0.1->langchain_community) (25.0)\n", + "Requirement already satisfied: typing-extensions<5.0.0,>=4.7.0 in /usr/local/lib/python3.12/dist-packages (from langchain-core<2.0.0,>=1.0.1->langchain_community) (4.15.0)\n", + "Requirement already satisfied: uuid-utils<1.0,>=0.12.0 in /usr/local/lib/python3.12/dist-packages (from langchain-core<2.0.0,>=1.0.1->langchain_community) (0.12.0)\n", + "Requirement already satisfied: httpx<1,>=0.23.0 in /usr/local/lib/python3.12/dist-packages (from langsmith<1.0.0,>=0.1.125->langchain_community) (0.28.1)\n", + "Requirement already satisfied: orjson>=3.9.14 in /usr/local/lib/python3.12/dist-packages (from langsmith<1.0.0,>=0.1.125->langchain_community) (3.11.5)\n", + "Requirement already satisfied: requests-toolbelt>=1.0.0 in /usr/local/lib/python3.12/dist-packages (from langsmith<1.0.0,>=0.1.125->langchain_community) (1.0.0)\n", + "Requirement already satisfied: zstandard>=0.23.0 in /usr/local/lib/python3.12/dist-packages (from langsmith<1.0.0,>=0.1.125->langchain_community) (0.25.0)\n", + "Requirement already satisfied: python-dotenv>=0.21.0 in /usr/local/lib/python3.12/dist-packages (from pydantic-settings<3.0.0,>=2.10.1->langchain_community) (1.2.1)\n", + "Requirement already satisfied: typing-inspection>=0.4.0 in /usr/local/lib/python3.12/dist-packages (from pydantic-settings<3.0.0,>=2.10.1->langchain_community) (0.4.2)\n", + "Requirement already satisfied: charset_normalizer<4,>=2 in /usr/local/lib/python3.12/dist-packages (from requests<3.0.0,>=2.32.5->langchain_community) (3.4.4)\n", + "Requirement already satisfied: idna<4,>=2.5 in /usr/local/lib/python3.12/dist-packages (from requests<3.0.0,>=2.32.5->langchain_community) (3.11)\n", + "Requirement already satisfied: urllib3<3,>=1.21.1 in /usr/local/lib/python3.12/dist-packages (from requests<3.0.0,>=2.32.5->langchain_community) (2.5.0)\n", + "Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.12/dist-packages (from requests<3.0.0,>=2.32.5->langchain_community) (2025.11.12)\n", + "Requirement already satisfied: greenlet>=1 in /usr/local/lib/python3.12/dist-packages (from SQLAlchemy<3.0.0,>=1.4.0->langchain_community) (3.3.0)\n", + "Requirement already satisfied: anyio in /usr/local/lib/python3.12/dist-packages (from httpx<1,>=0.23.0->langsmith<1.0.0,>=0.1.125->langchain_community) (4.12.0)\n", + "Requirement already satisfied: httpcore==1.* in /usr/local/lib/python3.12/dist-packages (from httpx<1,>=0.23.0->langsmith<1.0.0,>=0.1.125->langchain_community) (1.0.9)\n", + "Requirement already satisfied: h11>=0.16 in /usr/local/lib/python3.12/dist-packages (from httpcore==1.*->httpx<1,>=0.23.0->langsmith<1.0.0,>=0.1.125->langchain_community) (0.16.0)\n", + "Requirement already satisfied: jsonpointer>=1.9 in /usr/local/lib/python3.12/dist-packages (from jsonpatch<2.0.0,>=1.33.0->langchain-core<2.0.0,>=1.0.1->langchain_community) (3.0.0)\n", + "Requirement already satisfied: annotated-types>=0.6.0 in /usr/local/lib/python3.12/dist-packages (from pydantic<3.0.0,>=2.7.4->langchain-classic<2.0.0,>=1.0.0->langchain_community) (0.7.0)\n", + "Requirement already satisfied: pydantic-core==2.41.4 in /usr/local/lib/python3.12/dist-packages (from pydantic<3.0.0,>=2.7.4->langchain-classic<2.0.0,>=1.0.0->langchain_community) (2.41.4)\n", + "Collecting mypy-extensions>=0.3.0 (from typing-inspect<1,>=0.4.0->dataclasses-json<0.7.0,>=0.6.7->langchain_community)\n", + " Downloading mypy_extensions-1.1.0-py3-none-any.whl.metadata (1.1 kB)\n", + "Downloading langchain_community-0.4.1-py3-none-any.whl (2.5 MB)\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m2.5/2.5 MB\u001b[0m \u001b[31m32.4 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[?25hDownloading dataclasses_json-0.6.7-py3-none-any.whl (28 kB)\n", + "Downloading langchain_classic-1.0.1-py3-none-any.whl (1.0 MB)\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m1.0/1.0 MB\u001b[0m \u001b[31m63.4 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[?25hDownloading requests-2.32.5-py3-none-any.whl (64 kB)\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m64.7/64.7 kB\u001b[0m \u001b[31m5.7 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[?25hDownloading langchain_text_splitters-1.1.0-py3-none-any.whl (34 kB)\n", + "Downloading marshmallow-3.26.2-py3-none-any.whl (50 kB)\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m51.0/51.0 kB\u001b[0m \u001b[31m4.7 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[?25hDownloading typing_inspect-0.9.0-py3-none-any.whl (8.8 kB)\n", + "Downloading mypy_extensions-1.1.0-py3-none-any.whl (5.0 kB)\n", + "Installing collected packages: requests, mypy-extensions, marshmallow, typing-inspect, dataclasses-json, langchain-text-splitters, langchain-classic, langchain_community\n", + " Attempting uninstall: requests\n", + " Found existing installation: requests 2.32.4\n", + " Uninstalling requests-2.32.4:\n", + " Successfully uninstalled requests-2.32.4\n", + "\u001b[31mERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.\n", + "google-colab 1.0.0 requires requests==2.32.4, but you have requests 2.32.5 which is incompatible.\u001b[0m\u001b[31m\n", + "\u001b[0mSuccessfully installed dataclasses-json-0.6.7 langchain-classic-1.0.1 langchain-text-splitters-1.1.0 langchain_community-0.4.1 marshmallow-3.26.2 mypy-extensions-1.1.0 requests-2.32.5 typing-inspect-0.9.0\n" + ] + }, + { + "output_type": "display_data", + "data": { + "application/vnd.colab-display-data+json": { + "pip_warning": { + "packages": [ + "requests" + ] + }, + "id": "b75da2a576824d2a9620e79c01b5fa56" + } + }, + "metadata": {} + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "561f5b42" + }, + "source": [ + "**Reasoning**:\n", + "The `langchain_community` package has been successfully installed. Now I need to re-run the previous code block that failed due to `ModuleNotFoundError` to initialize and run the `agent_director`.\n", + "\n" + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "c37eb86a" + }, + "source": [ + "import os\n", + "from langchain_openai import ChatOpenAI\n", + "from langchain_community import hub\n", + "from langchain.agents import AgentExecutor, create_react_agent\n", + "from langchain_core.prompts import PromptTemplate\n", + "from google.colab import userdata # Import userdata for secure API key access\n", + "\n", + "# Retrieve your OpenAI API key from Colab's Secrets Manager\n", + "# IMPORTANT: Add your OPENAI_API_KEY to Colab's Secrets Manager (🔑 icon on the left panel)\n", + "os.environ[\"OPENAI_API_KEY\"] = userdata.get(\"OPENAI_API_KEY\")\n", + "\n", + "# Verify if the API key is set\n", + "if \"OPENAI_API_KEY\" not in os.environ:\n", + " print(\"ERROR: OPENAI_API_KEY environment variable not set. Please add it to Colab's Secrets Manager.\")\n", + " raise ValueError(\"OPENAI_API_KEY not found.\")\n", + "\n", + "# Initialize the LLM\n", + "llm = ChatOpenAI(model=\"gpt-4-turbo-preview\", temperature=0)\n", + "\n", + "# Get the standard ReAct prompt from LangChain Hub\n", + "prompt = hub.pull(\"hwchase17/react\")\n", + "\n", + "# Define the tools list\n", + "tools = [tool_documentos, tool_web_search]\n", + "\n", + "# Create the agent\n", + "agent = create_react_agent(llm, tools, prompt)\n", + "\n", + "# Create the AgentExecutor (this will be our 'agent_director')\n", + "agent_director = AgentExecutor(agent=agent, tools=tools, verbose=True, handle_parsing_errors=True)\n", + "\n", + "# Define the question\n", + "question = \"Necesito saber qué es JAX y el precio de la GPU H100. Concluye con un resumen combinado.\"\n", + "\n", + "# Run the agent_director\n", + "print(\"\\nRunning agent_director...\")\n", + "response = agent_director.invoke({\"input\": question})\n", + "\n", + "# Print the combined conclusion\n", + "print(\"\\nCombined Conclusion from agent_director:\")\n", + "print(response[\"output\"])\n", + "\n", + "print(\"Agent director initialized and run successfully.\")" + ], + "execution_count": null, + "outputs": [] + }, + { + "cell_type": "markdown", + "source": [ + "index.docker.io/semgrep/semgrep@sha256:85782eaf09692e6dfb684cd3bad87ef315775814b01f76b4d15582e4ca7c1c89action_scanning\n", + " - nombre : ' Ejecutar acciones semgrep scan '\n", + " ejecutar : ' semgrep scan --sarif --config action_scanning/semgrep-rules --config \"p/github-actions\"\n", + " >> semgrep-resultados-acciones.sarif '\n", + " - nombre : ' Guardar resultados de acciones SARIF como artefacto '\n", + " usos : ' acciones/upload" + ], + "metadata": { + "id": "FHcX-_jiW82m" + } + }, + { + "cell_type": "markdown", + "source": [ + "# Sección nueva" + ], + "metadata": { + "id": "VlAaU1erXCGg" + } + } + ] +} \ No newline at end of file