﻿{"id":4566,"date":"2025-10-30T18:01:18","date_gmt":"2025-10-30T12:31:18","guid":{"rendered":"https:\/\/blogs.infosys.com\/emerging-technology-solutions\/?p=4566"},"modified":"2025-10-30T18:01:18","modified_gmt":"2025-10-30T12:31:18","slug":"learning-on-the-fly-how-agentic-ai-learns-to-choose-the-right-cybersecurity-tools","status":"publish","type":"post","link":"https:\/\/blogs.infosys.com\/emerging-technology-solutions\/artificial-intelligence\/learning-on-the-fly-how-agentic-ai-learns-to-choose-the-right-cybersecurity-tools.html","title":{"rendered":"Learning on the Fly: How Agentic AI Learns to Choose the Right Cybersecurity Tools"},"content":{"rendered":"<p>Cybersecurity demands more than reactive defences\u2014it calls for <strong>proactive, intelligent systems<\/strong> that can adapt and improve with every interaction. In our earlier blog, <a href=\"https:\/\/blogs.infosys.com\/emerging-technology-solutions\/artificial-intelligence\/learning-on-the-fly-user-driven-adaptation-in-small-language-models.html\">Learning on the Fly: User-Driven Adaptation in Small Language Models<\/a>, we explored how Small Language Models (SLMs) can be fine-tuned to incorporate user feedback, transforming them from static utilities into dynamic, evolving assets for cyber defense.<\/p>\n<p>That work focused on capturing <strong>user dissatisfaction signals<\/strong> and feeding them back into SLMs to create a self-learning loop. Building on that foundation, this blog shifts the focus to an <strong>agentic AI use case<\/strong>\u2014where models don\u2019t just generate answers but must <strong>decide which external tool to use<\/strong> for a given problem.<\/p>\n<p>The challenge is clear:<strong> what happens when an agent picks the wrong tool<\/strong>? Imagine a security analyst asking, \u201cIs this IP malicious?\u201d, but the agent mistakenly chooses a GeoIP Lookup instead of a reputation check. Such errors not only erode user trust but also reduce the system\u2019s operational effectiveness. However, if these decisions are systematically <strong>logged, analyzed, and fed back<\/strong> into the learning process, agents can become more accurate over time.<\/p>\n<p>In this blog, we explore how to<strong> log tool-selection correctness in agentic AI systems.<\/strong> By tracking when an agent chooses the right tool versus when it does not, and by applying lightweight rules to determine ground truth, organizations can build feedback loops that extend beyond text outputs\u2014laying the groundwork for <strong>self-improving, tool-aware AI agents<\/strong> in cybersecurity and beyond.<\/p>\n<h2>Why This Matters<\/h2>\n<p>SLMs are efficient, cost-effective, and well-suited for enterprise deployment, but<strong> a 1B parameter SML is not inherently intelligent enough to orchestrate tools reliably<\/strong>. By continuously feeding it <strong>validated tool decisions<\/strong>, we enable the model to gain <strong>expertise in specific operational contexts.<\/strong><\/p>\n<p>This approach effectively transforms the SML into a <strong>domain-specific expert system,<\/strong> much like a <strong>Mixture of Experts (MoE),<\/strong> but optimized for enterprise scenarios where resource efficiency and auditability are critical.<\/p>\n<p>The full demonstration of this pipeline, along with reference code, is available in the public GitHub repository: <a href=\"https:\/\/github.com\/ameya\/agentic-slm-demo.\">https:\/\/github.com\/ameya\/agentic-slm-demo.<\/a><\/p>\n<h2>Cybersecurity Application<\/h2>\n<p>Consider a scenario where a SOC agent supports analysts by <strong>choosing the right tool<\/strong> for investigating suspicious IP addresses:<\/p>\n<ul>\n<li>\u201cWhere is this IP located?\u201d \u2192 correct choice: <strong>GeoIP Lookup<\/strong><\/li>\n<li>\u201cWho owns this IP address?\u201d \u2192 correct choice: <strong>WHOIS Lookup<\/strong><\/li>\n<li>\u201cIs this IP malicious?\u201d \u2192 correct choice: <strong>Reputation Check<\/strong><\/li>\n<\/ul>\n<p>Yet, agentic systems don\u2019t always get this right. An agent might mistakenly use a GeoIP lookup when asked about maliciousness\u2014producing an answer that sounds valid but misses the analyst\u2019s real intent.<\/p>\n<p>To address this, we can<strong> log each interaction<\/strong> in a structured table containing:<\/p>\n<ul>\n<li>The input prompt,<\/li>\n<li>The tool selected by the SLM,<\/li>\n<li>The expected tool (derived through rules or validation by a stronger LLM),<\/li>\n<li>A correctness label (true\/false).<\/li>\n<\/ul>\n<p>Once collected, these logs serve two purposes:<\/p>\n<ul>\n<li><strong>Performance tracking<\/strong> \u2014 enabling metrics like accuracy, error trends, and confusion matrices of tool choices.<\/li>\n<li><strong>Training data generation<\/strong> \u2014 correctness labels provide ground truth that can be used to fine-tune the SLM, so it learns to avoid repeating the same mistakes.<\/li>\n<\/ul>\n<p>This approach transforms tool-choice errors into<strong> learning opportunities<\/strong>. While our example highlights cybersecurity tasks, the same method applies broadly to domains such as finance, healthcare, or customer service\u2014anywhere agentic AI must pick the right tool to deliver the right outcome.<\/p>\n<h2>Steps to Create Long-Term Memory for Agentic SLM<\/h2>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-4568 aligncenter\" src=\"https:\/\/blogs.infosys.com\/emerging-technology-solutions\/wp-content\/uploads\/2025\/10\/LoFAAI2.png\" alt=\"\" width=\"592\" height=\"554\" \/><\/p>\n<h3>Step 1: Building the Fine-Tuning Pipeline for Agentic SLMs<\/h3>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-4570 aligncenter\" src=\"https:\/\/blogs.infosys.com\/emerging-technology-solutions\/wp-content\/uploads\/2025\/10\/LoFAAI3.png\" alt=\"\" width=\"315\" height=\"473\" \/><\/p>\n<p>To enable a Small Language Model (SLM) to improve its <strong>tool selection intelligence,<\/strong> we need a modular, auditable, and secure fine-tuning pipeline. The goal is to create a loop where model performance improves based on <strong>logged tool decisions<\/strong>\u2014particularly where the agent picked the wrong tool.<\/p>\n<p><strong>Key Components of the Pipeline:<\/strong><\/p>\n<ul>\n<li><strong>Prompt &amp; Tool Capture:<\/strong> Each user prompt and the tool chosen by the agent is logged.<\/li>\n<li><strong>Decision Validation:<\/strong> Analysts or automated heuristics mark whether the tool selection was <strong>correct<\/strong> (\u2705) <strong>or incorrect<\/strong> (\u274c).<\/li>\n<li><strong>Analysis Database:<\/strong> A structured store that keeps a record of prompts, tools, and decision outcomes.<\/li>\n<li><strong>Batch Processing (BAT):<\/strong> A Python application that periodically extracts logs, prepares training datasets, and pushes them for further analysis.<\/li>\n<li><strong>Augmented Data Generation:<\/strong> A large external LLM enriches the dataset by generating synthetic training examples, especially for error cases.<\/li>\n<li>F<strong>ine-Tuning the SML:<\/strong> Using<strong> LoRA\/QLoRA or PEFT<\/strong> adapters to make the 1B-parameter SML more intelligent without heavy compute costs.<\/li>\n<li><strong>Benchmark &amp; Feedback Loop:<\/strong> Each fine-tuned SML is tested against baseline performance and redeployed, closing the loop.<\/li>\n<\/ul>\n<h3>Step 2: Logging Agentic Tool Interactions in a Relational Database<\/h3>\n<p>Capturing real-world <strong>tool selection decisions<\/strong> is the foundation of a self-learning Agentic system. Instead of logging raw session histories or user identifiers, the focus is on <strong>prompts, tool metadata, and correctness flags.<\/strong><\/p>\n<p><strong>Minimalist Schema:<\/strong><\/p>\n<p>&nbsp;<\/p>\n<table style=\"border-collapse: collapse;width: 100%;border: 1px solid black\">\n<thead>\n<tr style=\"background-color: #d3d3d3\">\n<th style=\"border: 1px solid black;padding: 8px\">Column<\/th>\n<th style=\"border: 1px solid black;padding: 8px\">Type<\/th>\n<th style=\"border: 1px solid black;padding: 8px\">Description<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style=\"border: 1px solid black;padding: 8px\">id<\/td>\n<td style=\"border: 1px solid black;padding: 8px\">INT<\/td>\n<td style=\"border: 1px solid black;padding: 8px\">Unique identifier for the interaction<\/td>\n<\/tr>\n<tr>\n<td style=\"border: 1px solid black;padding: 8px\">prompt<\/td>\n<td style=\"border: 1px solid black;padding: 8px\">TEXT<\/td>\n<td style=\"border: 1px solid black;padding: 8px\">User\u2019s input query<\/td>\n<\/tr>\n<tr>\n<td style=\"border: 1px solid black;padding: 8px\">tool_name<\/td>\n<td style=\"border: 1px solid black;padding: 8px\">TEXT<\/td>\n<td style=\"border: 1px solid black;padding: 8px\">Name of the selected tool<\/td>\n<\/tr>\n<tr>\n<td style=\"border: 1px solid black;padding: 8px\">tool_desc<\/td>\n<td style=\"border: 1px solid black;padding: 8px\">TEXT<\/td>\n<td style=\"border: 1px solid black;padding: 8px\">Metadata\/description of the tool<\/td>\n<\/tr>\n<tr>\n<td style=\"border: 1px solid black;padding: 8px\">decision<\/td>\n<td style=\"border: 1px solid black;padding: 8px\">BOOL<\/td>\n<td style=\"border: 1px solid black;padding: 8px\">Correct (1) \/ Incorrect (0) selection<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><strong>Example Interaction:<\/strong><\/p>\n<ul>\n<li>Prompt: \u201cCorrelate login failures across AD logs.\u201d<\/li>\n<li>Tool Chosen: LogCorrelator<\/li>\n<li>Tool Description: Cross-checks failed logins across domains<\/li>\n<li>Decision: \u274c (wrong tool \u2014 should have been AD-Audit)<\/li>\n<\/ul>\n<p>This schema ensures we can<strong> systematically analyze failure<\/strong> cases without exposing sensitive organizational data.<\/p>\n<h3>Step 3: Identifying Wrong Tool Decisions<\/h3>\n<p>Not every interaction indicates a problem\u2014but when the agent selects the<strong> wrong tool,<\/strong> it\u2019s a critical signal for retraining. By analyzing <strong>decision logs<\/strong>, we can detect common failure patterns such as:<\/p>\n<ul>\n<li><strong>Confusion<\/strong>: The SML maps a prompt to a tool with similar keywords but wrong functionality.<\/li>\n<li><strong>Over-generalization:<\/strong> The same tool is chosen for too many unrelated tasks.<\/li>\n<li><strong>Gaps in training data:<\/strong> The SML hasn\u2019t seen enough examples for niche tools.<\/li>\n<\/ul>\n<p>These patterns provide the foundation for generating better training data.<\/p>\n<h3>Step 4: Suppressing Sensitive Metadata<\/h3>\n<p>Before preparing datasets, the pipeline must <strong>remove or anonymize sensitive organizational metadata.<\/strong> For example:<\/p>\n<ul>\n<li>Tool names that reveal internal projects.<\/li>\n<li>Paths or commands embedded in tool descriptions.<\/li>\n<li>Proprietary log sources or datasets<\/li>\n<\/ul>\n<p>A lightweight PII scrubber can be applied here, similar to cybersecurity chat scenarios, ensuring compliance with GDPR and enterprise data safety.<\/p>\n<h3>Step 5: Generating Better Training Data Using an External LLM<\/h3>\n<p>Once raw logs are cleaned, a large external LLM (e.g., GPT-4) generates <strong>better training data:<\/strong><\/p>\n<ul>\n<li>Improves the mapping of <strong>prompts \u2192 correct tools.<\/strong><\/li>\n<li>Suggests <strong>synthetic variations<\/strong> of prompts that could confuse the SML.<\/li>\n<li>Expands coverage for <strong>rarely used tools<\/strong>.<\/li>\n<\/ul>\n<p><strong>Sample Prompt for GPT-4 Augmentation:<\/strong><\/p>\n<blockquote><p>\u201cYou are assisting in training an Agentic SOC assistant. Below is a prompt and the incorrect tool chosen. Suggest the correct tool, and generate 2\u20133 alternate prompt\u2013tool pairs that should be added to improve training coverage.\u201d<\/p><\/blockquote>\n<h3>Step 6: Fine-Tuning the SML<\/h3>\n<p>With curated training data, the SLM (1B parameter) is fine-tuned using parameter-efficient techniques:<\/p>\n<ul>\n<li><strong>Base Model:<\/strong> Custom enterprise SLM (1B)<\/li>\n<li><strong>Technique:<\/strong> LoRA \/ QLoRA \/ PEFT<\/li>\n<li><strong>Goal:<\/strong> Improve tool orchestration accuracy while keeping compute costs minimal<\/li>\n<\/ul>\n<p>This allows the smaller SLM to evolve into a <strong>specialized decision-making expert<\/strong>\u2014a lightweight but intelligent Mixture of Experts (MoE).<\/p>\n<h3>Step 7: Testing and Benchmarking the Fine-Tuned Agentic Model<\/h3>\n<p>Fine-tuning only matters if it improves real-world tool selection. Benchmarking involves:<\/p>\n<p>\u2022 <strong>Correctness<\/strong>: % of times the right tool is chosen<br \/>\n\u2022 <strong>Efficiency<\/strong>: Reduction in unnecessary tool calls<br \/>\n\u2022 <strong>Coverage<\/strong>: Ability to handle rare or unseen tools<br \/>\n\u2022 <strong>Analyst Feedback<\/strong>: Validation from SOC analysts in real workflows<\/p>\n<p><strong>Sample Test Cases:<\/strong><\/p>\n<p>\u2022 Prompt: \u201cParse suspicious PowerShell commands.\u201d \u2192 Expected Tool: ScriptAnalyzer<br \/>\n\u2022 Prompt: \u201cDetect Kerberos ticket anomalies.\u201d \u2192 Expected Tool: AD-Audit<br \/>\n\u2022 Prompt: \u201cSummarize last 24 hours of IDS alerts.\u201d \u2192 Expected Tool: AlertSummarizer<\/p>\n<p>Over time, repeated cycles of logging, cleaning, and retraining help the SML mature into a trustworthy agentic expert in enterprise environments.<\/p>\n<h2>Agentic Context Engineering: Evolving the Agent\u2019s Memory and Strategy<\/h2>\n<p>While fine-tuning improves the model\u2019s tool selection accuracy, <strong>Agentic Context Engineering (ACE)<\/strong> ensures that the agent evolves its <strong>decision-making playbook<\/strong> over time\u2014without retraining. This involves dynamically updating the agent\u2019s context with:<\/p>\n<ul>\n<li><strong>Successful strategies<\/strong> from past interactions<\/li>\n<li><strong>Failure cases<\/strong> and their corrected outcomes<\/li>\n<li><strong>Domain-specific heuristics<\/strong> and tool usage patterns<\/li>\n<\/ul>\n<p>Instead of relying solely on static prompts or retrained weights, ACE treats context as a <strong>living memory<\/strong>\u2014a structured, modular, and editable layer that guides the agent\u2019s behavior.<\/p>\n<h3>Prompt Template for Agentic Context Engineering<\/h3>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-4574\" src=\"https:\/\/blogs.infosys.com\/emerging-technology-solutions\/wp-content\/uploads\/2025\/10\/LoFAAI6.png\" alt=\"\" width=\"903\" height=\"551\" \/><\/p>\n<p><strong>Cybersecurity Example: Hallucination vs. Context-Engineered Response<\/strong><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-4575\" src=\"https:\/\/blogs.infosys.com\/emerging-technology-solutions\/wp-content\/uploads\/2025\/10\/LoFAAI4.png\" alt=\"\" width=\"1490\" height=\"459\" \/><\/p>\n<p><strong>Without Proper Context (Hallucination)<\/strong><\/p>\n<p><strong>Prompt:<\/strong><\/p>\n<blockquote><p>\u201cIs this IP address malicious?\u201d<\/p><\/blockquote>\n<p><strong>Agent Response:<\/strong><\/p>\n<blockquote><p>\u201cGeoIP Lookup Result: The IP is located in Frankfurt, Germany.\u201d<\/p><\/blockquote>\n<p><strong>Issue:<\/strong><br \/>\nThe agent incorrectly assumes location implies maliciousness. It selects the wrong tool (GeoIP) and gives a misleading answer.<\/p>\n<p><strong>With Agentic Context Engineering<\/strong><br \/>\n<strong>Updated Context:<\/strong><\/p>\n<ul>\n<li>Task: Identify malicious IPs<\/li>\n<li>Previous failure: GeoIP used instead of Reputation Check<\/li>\n<li>Correct tool: ThreatIntelReputation<\/li>\n<li>Strategy: Always use reputation-based tools for maliciousness queries<\/li>\n<\/ul>\n<p><strong>Prompt:<\/strong><\/p>\n<blockquote><p>\u201cIs this IP address malicious?\u201d<\/p><\/blockquote>\n<p><strong>Agent Response:<\/strong><\/p>\n<blockquote><p>\u201cThreatIntelReputation Result: The IP has been flagged in 3 threat feeds for malware distribution. Risk Score: High.\u201d<\/p><\/blockquote>\n<p><strong>Outcome:<\/strong><br \/>\nThe agent selects the correct tool and provides a relevant, actionable response\u2014thanks to context engineering.<\/p>\n<h2>Conclusion<\/h2>\n<p>As enterprises move toward Agentic AI systems, the ability to learn from past actions becomes as important as generating new responses. By systematically logging tool choices, validating correctness, and feeding that data back into a fine-tuning loop, we give Small Language Models (SLMs) the ability to evolve into specialized experts.<\/p>\n<p>This approach transforms a lightweight 1B SLM from a generic assistant into a domain-aware Mixture of Experts (MoE), capable of making smarter, context-driven decisions. Unlike static models, the agent grows with every interaction\u2014adapting not only to user prompts but also to the operational tools of the enterprise.<\/p>\n<p>In doing so, we bridge the gap between efficiency and intelligence: large LLMs provide synthetic data generation and reasoning depth, while fine-tuned SLMs deliver cost-effective, reliable decision-making at scale. Over time, this creates a self-learning, auditable, and trustworthy AI layer that enterprises can safely embed into their SOCs and business workflows.<\/p>\n<p>Complementing this, <strong>Agentic Context Engineering (ACE)<\/strong> introduces a dynamic memory layer that evolves with each interaction. ACE reduces hallucinations and improves decision-making by treating context as a modular, editable playbook\u2014updated through generation, reflection, and curation. This enables agents to adapt without retraining, making them more resilient, accurate, and aligned with domain-specific goals.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Cybersecurity demands more than reactive defences\u2014it calls for proactive, intelligent systems that can adapt [&hellip;]<\/p>\n","protected":false},"author":504,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"inline_featured_image":false,"footnotes":""},"categories":[4,10],"tags":[60,186],"coauthors":[181],"class_list":["post-4566","post","type-post","status-publish","format-standard","hentry","category-artificial-intelligence","category-predictive-cyber-security","tag-artificial-intelligence","tag-generative-ai"],"acf":[],"_links":{"self":[{"href":"https:\/\/blogs.infosys.com\/emerging-technology-solutions\/wp-json\/wp\/v2\/posts\/4566","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blogs.infosys.com\/emerging-technology-solutions\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.infosys.com\/emerging-technology-solutions\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.infosys.com\/emerging-technology-solutions\/wp-json\/wp\/v2\/users\/504"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.infosys.com\/emerging-technology-solutions\/wp-json\/wp\/v2\/comments?post=4566"}],"version-history":[{"count":6,"href":"https:\/\/blogs.infosys.com\/emerging-technology-solutions\/wp-json\/wp\/v2\/posts\/4566\/revisions"}],"predecessor-version":[{"id":4581,"href":"https:\/\/blogs.infosys.com\/emerging-technology-solutions\/wp-json\/wp\/v2\/posts\/4566\/revisions\/4581"}],"wp:attachment":[{"href":"https:\/\/blogs.infosys.com\/emerging-technology-solutions\/wp-json\/wp\/v2\/media?parent=4566"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.infosys.com\/emerging-technology-solutions\/wp-json\/wp\/v2\/categories?post=4566"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.infosys.com\/emerging-technology-solutions\/wp-json\/wp\/v2\/tags?post=4566"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/blogs.infosys.com\/emerging-technology-solutions\/wp-json\/wp\/v2\/coauthors?post=4566"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}