Posts

agentic invoice design for reliability and performance

Image
This is a design for invoice processing system - the focus is performance, reliability and cost and the workflow is after client made their submission, they expect to be getting json as an output for entry or every item in the invoice and then fill up their web form and then user validate if everything is ok and finally click submit.  In our agent, we also have a validator but that to ensure we returning legit data.  Agent is specialized and do not have too many context poisoning. If model validator checks out ok, then we proceed to move to the next - which return json results back to user.  Another reason reason for this design, lets say our model is down - somewhere somehow - we are able to retain the client submission and help to processes it later. If for some reason, the default model is not able to decipher the image, model validator can try better model to see if it helps. But this can incur additioan cost. Given that the model can't recognized it, do we want to re...

google adk with tool calling using gwen3.8-2b-distill

Image
 When we are using the model to perform tool calling it is important to prompt correctly. Let''s see the difference if we were to do it this way  Prompt #1  When we using the prompt below and notice the output  banking_agent = Agent (     name = "account_assistant" ,     model = model ,     instruction = "You are a helpful customer support agent. Answer questions concisely." ,     tools = [ get_user_account_balance ],     before_model_callback = inspect_llm_input ) Output from prompt1 If i specifiy or prompt the model to specifically "use the tool", the model would call the function. Prompt #2  When we change our prompt slight to ask it to use the tool.  # ------------------------------------------------------------- # 2. CREATE THE ADK AGENT # ------------------------------------------------------------- banking_agent = Agent (     name = "account_assistant" ,     model = model , ...

When i do a uv add xxx-package, this install goes into the folder that has .venv defined instaead of my current activated python venv shell?

 When i do a uv add pypi-package , this install goes into the folder that has .venv defined instaead of my current activated python venv shell? This happens because uv add is a project-level command. It is designed to manage dependencies inside a pyproject.toml file and explicitly targets the project's local .venv directory, completely ignoring any active virtual environment in your shell. To install packages directly into your currently activated shell environment without creating or modifying a project structure, use uv pip install instead: Bash uv pip install xxx-package Verification uv pip list

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 ". ...