Posts

google adk - agentic RAG basic code using custom model

Image
There's alot of example that uses Gemini to do a RAG call. In this example I am going to use a custom llm engine to perform a RAG that I have setup in Agentic platform. I assume you have setup a RAG with your document.  So instead of using the genai apporach, we are now using agentic approach to query our RAG.  import asyncio from urllib import response from google . adk . agents import Agent from google . adk . runners import Runner from google . adk . sessions import InMemorySessionService from google . genai import types from google . adk . agents . callback_context import CallbackContext from google . adk . models . llm_request import LlmRequest from datetime import datetime import os import logging from vertexai . preview import rag from google . adk . agents . llm_agent import LlmAgent from google . adk . models . lite_llm import LiteLlm import google . cloud . logging from google . adk . tools . retrieval . vertex_ai_rag_retrieval ...

google adk erroring out with Failed in retrieving contexts due to: ', PermissionDenied('Agent Platform API has not been used in project your-project-id before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/aiplatform.googleapis.com/overview?project=your-project-id then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry

Bump into this error when trying to setup my agent to query Agentic platform RAG.  Despite checking that I have the right permission and then ensure the key environemnts variable are configured correctly GOOGLE_CLOUD_LOCATION=us-central1 GOOGLE_GENAI_USE_VERTEXAI=TRUE Yet this error keeps on coming up  RuntimeError: ('Failed in retrieving contexts due to: ', PermissionDenied('Agent Platform API has not been used in project your-project-id before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/aiplatform.googleapis.com/overview?project=your-project-id then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry.')) Then I place this in my code to force it and then I was able to resolve it. import vertexai # Ensure this matches your actual GCP Project ID, not a placeholder vertexai . init ( project = "project-your-project-id" , location = "us-central1" )

ADK input and output for llm function call using Gemini model

When it comes to tool calling, it can quickly get complicated - as tool calling can behave quite differently for different models, how do you pass those response back to the LLM model so that it can be used.  If we were to use a 2 billion paramater smaller model, those tool calling cane challenging. Having said that, it is worth look behind the scene how tool happens - what is the input and output when using it with Google ADK  This is what an input to the model using Google ADK looks like using Gemini-2.5-flash model='gemini -2.5 -flash' contents=[ Content(   parts= [     Part(       text='What is my account balance including pending charges for user_ 123 ?'     ) ,   ],   role='user' ) ] config=GenerateContentConfig(   system_instruction= """You are a helpful customer support agent. Answer questions concisely. You are an agent. Your internal name is " account_assistant ".""" ,   tools=[     Tool( ...

application insights kusto working with dates

While working with dates are relatively easy until you be more specific. For example, what is the date and time range or between start and finish datetime range.  By default, application insights uses UTC time for its query. It is often a hassle when trying to convert between UTC to local time - and often introduces error in the query  How can we convert t local time? Save some time trying to figure out why there's no record coming back when we know there's some data in there. request | where timestamp between ( datetime_local_to_itc(datetime( 2026 - 10 - 0 7 11 : 00 : 00 , "Australia/Sydney" )) .. datetime_local_to_itc(datetime( 2026 - 10 - 0 7 11 : 15 : 00 , "Australia/Sydney" )) )

Using model armour with your google ADK agent

Image
Model armour provide guardrails for your model to ensure attacker do not perform mallicious prompt injection or perform jailbreak.  We can do that by creating our model armour in GCP and then test it out using our script. First we will start off by creating our template. Click on 'Create template'.  So here is how Model Armour works - you create the template in a region. Then when we deploy our agent - ADK to that region and ensure agent to use that configuration. All in the same region.  And then under "Detection" tab ensure that we have checked "Prompt injection and jailbreak detection".  As you can see, I have responsible AI configure too. And you can configure other details such as Responsible AI.  This is an example of our model armour Here is how we configure our model  from google . adk . agents . llm_agent import Agent from google . genai import types as genai_types TEMPLATE = "projects/project-your-id/locations/us-central1/templates/m...

Google agent platform creating corpus using console

Image
Creating corpus can be tricky in Google where we can get error messages about corpus type not being avaiable in certain regions.  Here is a quick example where we can create this corpus using console.  Click on "Create corpus" And then we need to provide some details :-  Please check to see corpus is supported in your region  Next, click on upload to upload your document. Supported documents are pdf, html, jsonl, json, markdwn, textfile, docs, pptx, google docs. No CSV :). Size are typically 10 to 50 MB.   This is different from vertex search which does support csv.  There are 3 embedding model here but we can only choose 2 ( text-embedding-005 and text-multilingual-embedding-002 ) that are recommended for use with RAG.  Something to note: As you can see we are running in "serverless mode" and that does not support Vector Search  (At least at the moment). Ensure you have selected "Managed Agent Retrieval".  And click " create corpus ". ...