From 45e434b767ae63e571db00065ea2656de706d25f Mon Sep 17 00:00:00 2001 From: Kristopher Overholt Date: Fri, 20 Dec 2024 10:15:00 -0600 Subject: [PATCH] fix: Clarify Python and REST API query methods in sample notebooks when re-using Reasoning engine agents (#1532) # Description This PR clarifies the use of the Python SDK or REST API for querying a deployed Reasoning Engine instance, rather than using Vertex AI client libraries in other languages. --------- Co-authored-by: Holt Skinner <13262395+holtskinner@users.noreply.github.com> Co-authored-by: Holt Skinner --- .../intro_reasoning_engine.ipynb | 153 ++++++++++++------ .../tutorial_google_maps_agent.ipynb | 68 ++++++-- .../tutorial_vertex_ai_search_rag_agent.ipynb | 68 ++++++-- 3 files changed, 212 insertions(+), 77 deletions(-) diff --git a/gemini/reasoning-engine/intro_reasoning_engine.ipynb b/gemini/reasoning-engine/intro_reasoning_engine.ipynb index 89ab462eda4..7a2cadf2259 100644 --- a/gemini/reasoning-engine/intro_reasoning_engine.ipynb +++ b/gemini/reasoning-engine/intro_reasoning_engine.ipynb @@ -172,7 +172,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": { "id": "tFy3H3aPgx12" }, @@ -198,7 +198,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": { "id": "XRvKdaPDTznN" }, @@ -235,7 +235,7 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 3, "metadata": { "id": "NyKGtVQjgx13" }, @@ -264,7 +264,7 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 4, "metadata": { "id": "Nqwi-5ufWp_B" }, @@ -272,7 +272,7 @@ "source": [ "PROJECT_ID = \"[your-project-id]\" # @param {type:\"string\"}\n", "LOCATION = \"us-central1\" # @param {type:\"string\"}\n", - "STAGING_BUCKET = \"gs://[your-bucket-name]\" # @param {type:\"string\"}\n", + "STAGING_BUCKET = \"gs://[your-staging-bucket]\" # @param {type:\"string\"}\n", "\n", "import vertexai\n", "\n", @@ -299,7 +299,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 5, "metadata": { "id": "lslYAvw37JGQ" }, @@ -333,7 +333,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 6, "metadata": { "id": "921890fcb875" }, @@ -360,7 +360,7 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 7, "metadata": { "id": "ff7991bf37bf" }, @@ -392,7 +392,7 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 8, "metadata": { "id": "4ae49a2ccd2e" }, @@ -400,10 +400,10 @@ { "data": { "text/plain": [ - "{'amount': 1.0, 'base': 'USD', 'date': '2024-04-19', 'rates': {'SEK': 10.949}}" + "{'amount': 1.0, 'base': 'USD', 'date': '2024-12-13', 'rates': {'SEK': 10.9479}}" ] }, - "execution_count": 6, + "execution_count": 8, "metadata": {}, "output_type": "execute_result" } @@ -432,7 +432,7 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 9, "metadata": { "id": "68bc1b395f9d" }, @@ -467,7 +467,7 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 10, "metadata": { "id": "e0c5c699de12" }, @@ -476,15 +476,60 @@ "data": { "text/plain": [ "{'input': \"What's the exchange rate from US dollars to Swedish currency today?\",\n", - " 'output': 'Today, 1 US dollar is equal to 10.949 Swedish krona. \\n',\n", - " 'intermediate_steps': [(AgentActionMessageLog(tool='get_exchange_rate', tool_input={'currency_from': 'USD', 'currency_to': 'SEK'}, log=\"\\nInvoking: `get_exchange_rate` with `{'currency_from': 'USD', 'currency_to': 'SEK'}`\\n\\n\\n\", message_log=[AIMessageChunk(content='', additional_kwargs={'function_call': {'name': 'get_exchange_rate', 'arguments': '{\"currency_from\": \"USD\", \"currency_to\": \"SEK\"}'}}, response_metadata={'is_blocked': False, 'safety_ratings': [{'category': 'HARM_CATEGORY_HATE_SPEECH', 'probability_label': 'NEGLIGIBLE', 'blocked': False}, {'category': 'HARM_CATEGORY_DANGEROUS_CONTENT', 'probability_label': 'NEGLIGIBLE', 'blocked': False}, {'category': 'HARM_CATEGORY_HARASSMENT', 'probability_label': 'NEGLIGIBLE', 'blocked': False}, {'category': 'HARM_CATEGORY_SEXUALLY_EXPLICIT', 'probability_label': 'NEGLIGIBLE', 'blocked': False}], 'citation_metadata': None, 'usage_metadata': {'prompt_token_count': 74, 'candidates_token_count': 13, 'total_token_count': 87}}, id='run-b4f2744c-e65c-4688-9287-b619ee84ead4', tool_calls=[{'name': 'get_exchange_rate', 'args': {'currency_from': 'USD', 'currency_to': 'SEK'}, 'id': '0a06cddb-73a1-47b2-b937-7856225fc4f1'}], tool_call_chunks=[{'name': 'get_exchange_rate', 'args': '{\"currency_from\": \"USD\", \"currency_to\": \"SEK\"}', 'id': '0a06cddb-73a1-47b2-b937-7856225fc4f1', 'index': None}])]),\n", + " 'output': 'The exchange rate from US dollars to Swedish krona is 1 USD to 10.9479 SEK. \\n',\n", + " 'intermediate_steps': [[{'lc': 1,\n", + " 'type': 'constructor',\n", + " 'id': ['langchain', 'schema', 'agent', 'ToolAgentAction'],\n", + " 'kwargs': {'tool': 'get_exchange_rate',\n", + " 'tool_input': {'currency_from': 'USD', 'currency_to': 'SEK'},\n", + " 'log': \"\\nInvoking: `get_exchange_rate` with `{'currency_from': 'USD', 'currency_to': 'SEK'}`\\n\\n\\n\",\n", + " 'type': 'AgentActionMessageLog',\n", + " 'message_log': [{'lc': 1,\n", + " 'type': 'constructor',\n", + " 'id': ['langchain', 'schema', 'messages', 'AIMessageChunk'],\n", + " 'kwargs': {'content': '',\n", + " 'additional_kwargs': {'function_call': {'name': 'get_exchange_rate',\n", + " 'arguments': '{\"currency_from\": \"USD\", \"currency_to\": \"SEK\"}'}},\n", + " 'response_metadata': {'safety_ratings': [{'category': 'HARM_CATEGORY_HATE_SPEECH',\n", + " 'probability_label': 'NEGLIGIBLE',\n", + " 'blocked': False,\n", + " 'severity': 'HARM_SEVERITY_NEGLIGIBLE'},\n", + " {'category': 'HARM_CATEGORY_DANGEROUS_CONTENT',\n", + " 'probability_label': 'NEGLIGIBLE',\n", + " 'blocked': False,\n", + " 'severity': 'HARM_SEVERITY_LOW'},\n", + " {'category': 'HARM_CATEGORY_HARASSMENT',\n", + " 'probability_label': 'NEGLIGIBLE',\n", + " 'blocked': False,\n", + " 'severity': 'HARM_SEVERITY_NEGLIGIBLE'},\n", + " {'category': 'HARM_CATEGORY_SEXUALLY_EXPLICIT',\n", + " 'probability_label': 'NEGLIGIBLE',\n", + " 'blocked': False,\n", + " 'severity': 'HARM_SEVERITY_NEGLIGIBLE'}],\n", + " 'finish_reason': 'STOP'},\n", + " 'type': 'AIMessageChunk',\n", + " 'id': 'run-f88a789f-8c13-4a5c-81c2-e48eff00462c',\n", + " 'tool_calls': [{'name': 'get_exchange_rate',\n", + " 'args': {'currency_from': 'USD', 'currency_to': 'SEK'},\n", + " 'id': 'e54070df-2055-416d-9599-c891953869d3',\n", + " 'type': 'tool_call'}],\n", + " 'usage_metadata': {'input_tokens': 41,\n", + " 'output_tokens': 13,\n", + " 'total_tokens': 54},\n", + " 'tool_call_chunks': [{'name': 'get_exchange_rate',\n", + " 'args': '{\"currency_from\": \"USD\", \"currency_to\": \"SEK\"}',\n", + " 'id': 'e54070df-2055-416d-9599-c891953869d3',\n", + " 'index': None,\n", + " 'type': 'tool_call_chunk'}],\n", + " 'invalid_tool_calls': []}}],\n", + " 'tool_call_id': 'e54070df-2055-416d-9599-c891953869d3'}},\n", " {'amount': 1.0,\n", " 'base': 'USD',\n", - " 'date': '2024-04-19',\n", - " 'rates': {'SEK': 10.949}})]}" + " 'date': '2024-12-13',\n", + " 'rates': {'SEK': 10.9479}}]]}" ] }, - "execution_count": 8, + "execution_count": 10, "metadata": {}, "output_type": "execute_result" } @@ -511,7 +556,7 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 11, "metadata": { "id": "b2f8365735d2" }, @@ -537,7 +582,7 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 12, "metadata": { "id": "fd3b88c73411" }, @@ -552,10 +597,10 @@ "Creating in-memory tarfile of extra_packages\n", "Writing to gs://your-bucket-name/reasoning_engine/dependencies.tar.gz\n", "Creating ReasoningEngine\n", - "Create ReasoningEngine backing LRO: projects/954731520814/locations/us-central1/reasoningEngines/4714776228647665664/operations/4748723134759174144\n", - "ReasoningEngine created. Resource name: projects/954731520814/locations/us-central1/reasoningEngines/4714776228647665664\n", + "Create ReasoningEngine backing LRO: projects/your-project-number/locations/us-central1/reasoningEngines/224106858019815424/operations/3507815273723854848\n", + "ReasoningEngine created. Resource name: projects/your-project-number/locations/us-central1/reasoningEngines/224106858019815424\n", "To use this ReasoningEngine in another session:\n", - "reasoning_engine = vertexai.preview.reasoning_engines.ReasoningEngine('projects/954731520814/locations/us-central1/reasoningEngines/4714776228647665664')\n" + "reasoning_engine = vertexai.preview.reasoning_engines.ReasoningEngine('projects/your-project-number/locations/us-central1/reasoningEngines/224106858019815424')\n" ] } ], @@ -573,7 +618,7 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 13, "metadata": { "id": "d01b37cb77dc" }, @@ -582,10 +627,10 @@ "data": { "text/plain": [ "{'input': \"What's the exchange rate from US dollars to Swedish currency today?\",\n", - " 'output': 'Today, 1 US dollar is equal to 10.949 Swedish krona. \\n'}" + " 'output': 'The exchange rate from US dollars to Swedish krona today is 1 USD to 10.9479 SEK. \\n'}" ] }, - "execution_count": 11, + "execution_count": 13, "metadata": {}, "output_type": "execute_result" } @@ -602,25 +647,35 @@ "id": "9f2f7d3ed7bd" }, "source": [ - "### Reusing your deployed agent from other applications or SDKs" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "360870c674d5" - }, - "source": [ - "You can now import and use the remotely deployed Reasoning Engine in this notebook session or in a different notebook or Python script. First you need to get its resource_name by calling:" + "### Querying your deployed agent\n", + "\n", + "You've now deployed your Reasoning Engine agent and can [interact with it in multiple ways](https://cloud.google.com/vertex-ai/generative-ai/docs/reasoning-engine/use), both within this notebook and from other applications or environments. The primary methods for accessing your deployed agent are via the Python client library or through REST API calls. Here's an overview of both methods:\n", + "\n", + "**Method 1: Reusing within this notebook or another Python environment**\n", + "\n", + "You can directly reuse and query the `remote_agent` instance you created in this notebook.\n", + "\n", + "Or, you can instantiate a new instance in another notebook or Python script. To do this, you'll need to retrieve your deployed agent's resource name that uniquely identifies your agent, which is a string that includes the project, location, and Reasoning Engine ID. You can retrieve it by running the following code in the notebook or environment where you created your agent:" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 14, "metadata": { "id": "fdaf8b91413f" }, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "'projects/your-project-number/locations/us-central1/reasoningEngines/223106848019812424'" + ] + }, + "execution_count": 14, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "remote_agent.resource_name" ] @@ -631,12 +686,12 @@ "id": "060f8369d113" }, "source": [ - "Afterwards you can use it by uncommenting and adapting the following code:" + "Use the resource name to load the agent in your other notebook or Python script, then query the remote agent as usual:" ] }, { "cell_type": "code", - "execution_count": 12, + "execution_count": 15, "metadata": { "id": "78af4442827e" }, @@ -644,7 +699,7 @@ "source": [ "# from vertexai.preview import reasoning_engines\n", "\n", - "# REASONING_ENGINE_RESOURCE_NAME = \"YOUR_REASONING_ENGINE_RESOURCE_NAME\"\n", + "# REASONING_ENGINE_RESOURCE_NAME = \"YOUR_REASONING_ENGINE_RESOURCE_NAME\" # Replace with the resource name of your deployed Reasoning Engine\n", "\n", "# remote_agent = reasoning_engines.ReasoningEngine(REASONING_ENGINE_RESOURCE_NAME)\n", "# response = remote_agent.query(input=query)" @@ -656,7 +711,15 @@ "id": "63ab06554fc0" }, "source": [ - "Or, you can query your agent from other programming languages using any of the [available client libraries in Vertex AI](https://cloud.google.com/vertex-ai/docs/start/client-libraries), including C#, Java, Node.js, Python, Go, or REST API." + "**Method 2: Accessing from other environments via REST API**\n", + "\n", + "Beyond the Python client library, your deployed Vertex AI agent can be [queried using REST API calls](https://cloud.google.com/vertex-ai/generative-ai/docs/reasoning-engine/use), including:\n", + "\n", + "- Python: You can use Python's `requests` library or similar tools to make HTTP calls to the Vertex AI REST API.\n", + "- cURL: A command-line tool, cURL allows you to send HTTP requests directly. This is useful for testing and debugging.\n", + "- Other Programming Languages: If you prefer a different language for your application, you can use its native HTTP client library to make REST API calls.\n", + "\n", + "In summary, you have access to your deployed Reasoning Engine agent through the Python client library within Python environments, and more universally through its REST API via tools and programming languages of your choosing." ] }, { @@ -692,7 +755,7 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": 16, "metadata": { "id": "5408d3da2726" }, @@ -735,7 +798,7 @@ }, { "cell_type": "code", - "execution_count": 14, + "execution_count": 17, "metadata": { "id": "08623f46a9e4" }, @@ -776,7 +839,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 18, "metadata": { "id": "7cec827288b7" }, diff --git a/gemini/reasoning-engine/tutorial_google_maps_agent.ipynb b/gemini/reasoning-engine/tutorial_google_maps_agent.ipynb index 4e7fa3472df..75c612e5596 100644 --- a/gemini/reasoning-engine/tutorial_google_maps_agent.ipynb +++ b/gemini/reasoning-engine/tutorial_google_maps_agent.ipynb @@ -756,10 +756,10 @@ "Creating in-memory tarfile of extra_packages\n", "Writing to gs://your-bucket-name/reasoning_engine/dependencies.tar.gz\n", "Creating ReasoningEngine\n", - "Create ReasoningEngine backing LRO: projects/954731520814/locations/us-central1/reasoningEngines/2553752094951604224/operations/2599704568526798848\n", - "ReasoningEngine created. Resource name: projects/954731520814/locations/us-central1/reasoningEngines/2553752094951604224\n", + "Create ReasoningEngine backing LRO: projects/your-project-number/locations/us-central1/reasoningEngines/2553752094951604224/operations/2599704568526798848\n", + "ReasoningEngine created. Resource name: projects/your-project-number/locations/us-central1/reasoningEngines/2553752094951604224\n", "To use this ReasoningEngine in another session:\n", - "reasoning_engine = vertexai.preview.reasoning_engines.ReasoningEngine('projects/954731520814/locations/us-central1/reasoningEngines/2553752094951604224')\n" + "reasoning_engine = vertexai.preview.reasoning_engines.ReasoningEngine('projects/your-project-number/locations/us-central1/reasoningEngines/2553752094951604224')\n" ] } ], @@ -989,46 +989,82 @@ { "cell_type": "markdown", "metadata": { - "id": "f0a73c613b9f" + "id": "9f2f7d3ed7bd" }, "source": [ - "### Reusing your deployed agent from other applications or SDKs" + "### Querying your deployed agent\n", + "\n", + "You've now deployed your Reasoning Engine agent and can [interact with it in multiple ways](https://cloud.google.com/vertex-ai/generative-ai/docs/reasoning-engine/use), both within this notebook and from other applications or environments. The primary methods for accessing your deployed agent are via the Python client library or through REST API calls. Here's an overview of both methods:\n", + "\n", + "**Method 1: Reusing within this notebook or another Python environment**\n", + "\n", + "You can directly reuse and query the `remote_agent` instance you created in this notebook.\n", + "\n", + "Or, you can instantiate a new instance in another notebook or Python script. To do this, you'll need to retrieve your deployed agent's resource name that uniquely identifies your agent, which is a string that includes the project, location, and Reasoning Engine ID. You can retrieve it by running the following code in the notebook or environment where you created your agent:" + ] + }, + { + "cell_type": "code", + "execution_count": 23, + "metadata": { + "id": "fdaf8b91413f" + }, + "outputs": [ + { + "data": { + "text/plain": [ + "'projects/your-project-number/locations/us-central1/reasoningEngines/223106848019812424'" + ] + }, + "execution_count": 23, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "remote_agent.resource_name" ] }, { "cell_type": "markdown", "metadata": { - "id": "11b3e4790512" + "id": "060f8369d113" }, "source": [ - "You can now import and use the remotely deployed Reasoning Engine in this notebook session or in a different notebook or Python script by uncommenting and adapting the following code:" + "Use the resource name to load the agent in your other notebook or Python script, then query the remote agent as usual:" ] }, { "cell_type": "code", - "execution_count": 23, + "execution_count": 24, "metadata": { - "id": "1ba9886e4b48" + "id": "78af4442827e" }, "outputs": [], "source": [ "# from vertexai.preview import reasoning_engines\n", "\n", - "# PROJECT_ID = \"YOUR_PROJECT_ID\"\n", - "# LOCATION = \"YOUR_LOCATION\"\n", - "# REASONING_ENGINE_ID = \"YOUR_REASONING_ENGINE_ID\"\n", + "# REASONING_ENGINE_RESOURCE_NAME = \"YOUR_REASONING_ENGINE_RESOURCE_NAME\" # Replace with the resource name of your deployed Reasoning Engine\n", "\n", - "# remote_agent = reasoning_engines.ReasoningEngine(f\"projects/{PROJECT_ID}/locations/{LOCATION}/reasoningEngines/{REASONING_ENGINE_ID}\")\n", + "# remote_agent = reasoning_engines.ReasoningEngine(REASONING_ENGINE_RESOURCE_NAME)\n", "# response = remote_agent.query(input=query)" ] }, { "cell_type": "markdown", "metadata": { - "id": "a002a18dbf33" + "id": "63ab06554fc0" }, "source": [ - "Or, you can query your agent from other programming languages using any of the [available client libraries in Vertex AI](https://cloud.google.com/vertex-ai/docs/start/client-libraries), including C#, Java, Node.js, Python, Go, or REST API." + "**Method 2: Accessing from other environments via REST API**\n", + "\n", + "Beyond the Python client library, your deployed Vertex AI agent can be [queried using REST API calls](https://cloud.google.com/vertex-ai/generative-ai/docs/reasoning-engine/use), including:\n", + "\n", + "- Python: You can use Python's `requests` library or similar tools to make HTTP calls to the Vertex AI REST API.\n", + "- cURL: A command-line tool, cURL allows you to send HTTP requests directly. This is useful for testing and debugging.\n", + "- Other Programming Languages: If you prefer a different language for your application, you can use its native HTTP client library to make REST API calls.\n", + "\n", + "In summary, you have access to your deployed Reasoning Engine agent through the Python client library within Python environments, and more universally through its REST API via tools and programming languages of your choosing." ] }, { @@ -1044,7 +1080,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 25, "metadata": { "id": "95b1caa1ff1d" }, diff --git a/gemini/reasoning-engine/tutorial_vertex_ai_search_rag_agent.ipynb b/gemini/reasoning-engine/tutorial_vertex_ai_search_rag_agent.ipynb index ee2b23c5c6f..5a9f5af684f 100644 --- a/gemini/reasoning-engine/tutorial_vertex_ai_search_rag_agent.ipynb +++ b/gemini/reasoning-engine/tutorial_vertex_ai_search_rag_agent.ipynb @@ -630,10 +630,10 @@ "Creating in-memory tarfile of extra_packages\n", "Writing to gs://your-bucket-name/reasoning_engine/dependencies.tar.gz\n", "Creating ReasoningEngine\n", - "Create ReasoningEngine backing LRO: projects/954731510984/locations/us-central1/reasoningEngines/5997035485053059072/operations/2550512418300100608\n", - "ReasoningEngine created. Resource name: projects/954731510984/locations/us-central1/reasoningEngines/5997035485053059072\n", + "Create ReasoningEngine backing LRO: projects/your-project-number/locations/us-central1/reasoningEngines/5997035485053059072/operations/2550512418300100608\n", + "ReasoningEngine created. Resource name: projects/your-project-number/locations/us-central1/reasoningEngines/5997035485053059072\n", "To use this ReasoningEngine in another session:\n", - "reasoning_engine = vertexai.preview.reasoning_engines.ReasoningEngine('projects/954731510984/locations/us-central1/reasoningEngines/5997035485053059072')\n" + "reasoning_engine = vertexai.preview.reasoning_engines.ReasoningEngine('projects/your-project-number/locations/us-central1/reasoningEngines/5997035485053059072')\n" ] } ], @@ -833,46 +833,82 @@ { "cell_type": "markdown", "metadata": { - "id": "c046d84370d6" + "id": "9f2f7d3ed7bd" }, "source": [ - "### Reusing your deployed agent from other applications or SDKs" + "### Querying your deployed agent\n", + "\n", + "You've now deployed your Reasoning Engine agent and can [interact with it in multiple ways](https://cloud.google.com/vertex-ai/generative-ai/docs/reasoning-engine/use), both within this notebook and from other applications or environments. The primary methods for accessing your deployed agent are via the Python client library or through REST API calls. Here's an overview of both methods:\n", + "\n", + "**Method 1: Reusing within this notebook or another Python environment**\n", + "\n", + "You can directly reuse and query the `remote_agent` instance you created in this notebook.\n", + "\n", + "Or, you can instantiate a new instance in another notebook or Python script. To do this, you'll need to retrieve your deployed agent's resource name that uniquely identifies your agent, which is a string that includes the project, location, and Reasoning Engine ID. You can retrieve it by running the following code in the notebook or environment where you created your agent:" + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "metadata": { + "id": "fdaf8b91413f" + }, + "outputs": [ + { + "data": { + "text/plain": [ + "'projects/your-project-number/locations/us-central1/reasoningEngines/223106848019812424'" + ] + }, + "execution_count": 21, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "remote_agent.resource_name" ] }, { "cell_type": "markdown", "metadata": { - "id": "e757f51ab1a0" + "id": "060f8369d113" }, "source": [ - "You can now import and use the remotely deployed Reasoning Engine in this notebook session or in a different notebook or Python script by uncommenting and adapting the following code:" + "Use the resource name to load the agent in your other notebook or Python script, then query the remote agent as usual:" ] }, { "cell_type": "code", - "execution_count": 21, + "execution_count": 22, "metadata": { - "id": "2ef34db8ea09" + "id": "78af4442827e" }, "outputs": [], "source": [ "# from vertexai.preview import reasoning_engines\n", "\n", - "# PROJECT_ID = \"YOUR_PROJECT_ID\"\n", - "# LOCATION = \"YOUR_LOCATION\"\n", - "# REASONING_ENGINE_ID = \"YOUR_REASONING_ENGINE_ID\"\n", + "# REASONING_ENGINE_RESOURCE_NAME = \"YOUR_REASONING_ENGINE_RESOURCE_NAME\" # Replace with the resource name of your deployed Reasoning Engine\n", "\n", - "# remote_agent = reasoning_engines.ReasoningEngine(f\"projects/{PROJECT_ID}/locations/{LOCATION}/reasoningEngines/{REASONING_ENGINE_ID}\")\n", + "# remote_agent = reasoning_engines.ReasoningEngine(REASONING_ENGINE_RESOURCE_NAME)\n", "# response = remote_agent.query(input=query)" ] }, { "cell_type": "markdown", "metadata": { - "id": "f193197f0bc8" + "id": "63ab06554fc0" }, "source": [ - "Or, you can query your agent from other programming languages using any of the [available client libraries in Vertex AI](https://cloud.google.com/vertex-ai/docs/start/client-libraries), including C#, Java, Node.js, Python, Go, or REST API." + "**Method 2: Accessing from other environments via REST API**\n", + "\n", + "Beyond the Python client library, your deployed Vertex AI agent can be [queried using REST API calls](https://cloud.google.com/vertex-ai/generative-ai/docs/reasoning-engine/use), including:\n", + "\n", + "- Python: You can use Python's `requests` library or similar tools to make HTTP calls to the Vertex AI REST API.\n", + "- cURL: A command-line tool, cURL allows you to send HTTP requests directly. This is useful for testing and debugging.\n", + "- Other Programming Languages: If you prefer a different language for your application, you can use its native HTTP client library to make REST API calls.\n", + "\n", + "In summary, you have access to your deployed Reasoning Engine agent through the Python client library within Python environments, and more universally through its REST API via tools and programming languages of your choosing." ] }, { @@ -888,7 +924,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 23, "metadata": { "id": "7cec827288b7" },