SnagTrace | Deterministic AI Agent Fault Detection Library

SnagTrace is an open-source Python library that helps developers identify common failures in AI agent execution traces using deterministic analysis. Instead of relying on another language model to judge whether an agent failed, it detects structural issues such as execution loops, invalid tool arguments, and cost budget overruns, then reports the exact step where the problem occurred. The library is designed to integrate with modern agent frameworks such as LangChain and LangGraph while remaining lightweight, reproducible, and easy to extend. Overview Debugging AI agents can be difficult because a single execution may involve hundreds of tool calls, multiple agents, and long execution traces. While existing observability platforms provide tracing and replay, developers often still need to manually inspect traces to locate the source of a failure. SnagTrace focuses on failure types that can be detected reliably without an LLM. By analyzing execution traces with deterministic rules, it produces consistent results and helps reduce the time required to investigate common agent failures. Features Key Capabilities Loop Detection Detects repeated tool invocations and recursive execution patterns using configurable sliding-window analysis. Tool Argument Validation Identifies invalid tool inputs, schema mismatches, truncated arguments, and parsing failures before they propagate through an agent workflow. Cost Budget Monitoring Tracks cumulative execution cost and reports the precise step where a configured budget threshold is exceeded. Technologies Design SnagTrace follows a deterministic approach to agent debugging. Each detector analyzes execution traces independently without calling an external language model. This makes diagnoses reproducible, inexpensive to run, and suitable for automation in development and CI workflows. The detector system is modular, allowing additional rule-based detectors to be added without changing the core architecture. Performance The library is designed for efficient analysis of large execution traces while keeping detectors stateless and easy to test. For long-running agents, traces can be analyzed periodically or after execution completes to avoid unnecessary overhead. My Role This project was designed and developed independently. My work included: Outcome SnagTrace provides a lightweight way to detect common AI agent failures without introducing additional LLM-based analysis. It is intended for developers who want deterministic, reproducible diagnostics that can be integrated into local development workflows or automated pipelines.

Fine-Tuning LLaMA 3.1 for English–Nepali Medical Translation

nepali translation

Medical information is only useful when people can understand it. While English has a large ecosystem of medical resources, high-quality medical translation for Nepali remains limited. General-purpose language models can translate everyday text reasonably well, but they often struggle with clinical terminology, dosage instructions, and domain-specific language. This project explores whether a large language model can be adapted for English–Nepali medical translation using parameter-efficient fine-tuning instead of retraining the entire model. The goal was to build a reproducible baseline that can serve as a foundation for future research in low-resource medical NLP. Why I Built This Many multilingual language models support Nepali, but most are trained for general translation rather than medical language. Clinical text introduces challenges that aren’t common in everyday conversations, including specialised terminology, formal writing style, and safety-critical information. Instead of relying on prompt engineering alone, I wanted to evaluate whether domain-specific fine-tuning could significantly improve translation quality while remaining feasible on consumer-grade hardware. Building the Dataset One of the biggest challenges was the lack of publicly available English–Nepali medical parallel data. To address this, I compiled a parallel corpus consisting of 58,682 aligned sentence pairs collected from publicly available medical resources, health education materials, question–answer datasets, and health-related articles. The dataset contains only publicly available information and excludes personally identifiable or protected health information. Model and Training The project uses Meta’s LLaMA 3.1 8B Instruct as the base model. Rather than fine-tuning all 8 billion parameters, I adopted a parameter-efficient approach using LoRA together with 4-bit NF4 quantization (QLoRA). This reduced GPU memory requirements while training only about 0.52% of the model’s parameters. Training was performed on a Tesla T4 (16 GB VRAM) provided by Google Colab over approximately 25–30 hours, demonstrating that domain adaptation can be achieved without access to expensive multi-GPU infrastructure. Evaluation To evaluate the model, I used two standard machine translation metrics: The fine-tuned model achieved: Metric Score BLEU 11.63 ChrF++ 34.65 Compared with the zero-shot LLaMA 3.1 baseline, this represents an 8.9× improvement in BLEU and a 2.1× improvement in ChrF++, showing that parameter-efficient fine-tuning substantially improves domain-specific translation performance. What I Learned The project reinforced that fine-tuning is only part of building a reliable translation system. Dataset quality, domain coverage, evaluation methodology, and error analysis all have a significant impact on the final results. Although the model preserves many medical terms and produces grammatically correct Nepali translations, it can still omit safety-critical information in some cases. For that reason, it should be treated as a first-draft translation assistant rather than a replacement for qualified bilingual medical professionals. Future Work There are several directions for extending this research:

Real-Time Object Detection on Raspberry Pi: LiteRT, OpenCV, and Telegram

object detection

The goal of this project was to build a lightweight edge AI system that could detect people in real time and send alerts without relying on cloud-based inference. I wanted the entire detection pipeline to run locally on a Raspberry Pi so that it could respond quickly, reduce network usage, and continue working even with limited internet connectivity. The application starts by capturing frames from a USB camera using OpenCV and the V4L2 backend. Each frame is resized and prepared for inference before being passed to a quantized MobileNet SSD model running with Google’s LiteRT runtime. Using a quantized model keeps inference efficient enough to run on Raspberry Pi hardware while maintaining reasonable detection accuracy. After inference, the model outputs multiple candidate detections. Since object detection models often generate overlapping bounding boxes for the same object, I applied Non-Maximum Suppression (NMS) to remove duplicate detections and keep only the highest-confidence result for each person. To avoid sending blurry or underexposed images, the application briefly waits for the camera’s auto-exposure to stabilize whenever a new person enters the frame. It also clears buffered frames from the camera before capturing the final snapshot, ensuring the notification contains the most recent image instead of an older buffered frame. The annotated image is encoded directly in memory and sent to Telegram using the Bot API. This avoids unnecessary disk writes and reduces I/O overhead on the Raspberry Pi. To make the system suitable for continuous operation, I implemented retry handling for temporary network failures and deployed the application as a systemd service. This allows the gateway to start automatically after boot and recover from unexpected interruptions without manual intervention. Where This Project Can Be Used Although this project was built as a learning exercise in edge AI and computer vision, the same architecture can be applied to a variety of real-world scenarios. Home and Office Monitoring The system can monitor entrances, hallways, or restricted areas and send instant notifications whenever a person is detected. Smart Classrooms Schools can use the gateway to monitor classroom activity, laboratories, or computer rooms without continuously streaming video to a remote server. Retail Stores The project can be adapted to monitor customer movement, detect occupancy, or trigger alerts when someone enters specific areas. Construction Sites and Warehouses A local edge device can detect workers entering restricted zones and notify supervisors without requiring cloud processing. Remote Locations Because inference runs entirely on the Raspberry Pi, the system is well suited for environments with unreliable or limited internet connectivity. Only alert messages need to be transmitted, significantly reducing bandwidth requirements. AI and Edge Computing Research The project also serves as a practical example of deploying lightweight computer vision models on embedded hardware. Developers can extend it by adding custom object detection models, face recognition, multiple cameras, or integration with IoT devices and automation platforms. What I Learned Building this project reinforced that deploying an AI model is only part of the solution. Real-world systems also need to account for camera behavior, duplicate detections, network interruptions, and long-running reliability. Addressing these practical challenges made the system far more usable than simply running an object detection model on a live video stream. This project also provided hands-on experience with edge AI deployment, computer vision optimization, Linux service management, and integrating AI applications with external APIs for real-time notifications.

OpenCV: Everything You Need to Know

OpenCV (Open Source Computer Vision Library) is an open-source, cross-platform library designed for real-time computer vision and image processing tasks. Initially released in 2000 and developed by Intel, it provides tools for analyzing and manipulating images and videos. OpenCV is widely used in applications involving object detection, facial recognition, motion tracking, augmented reality (AR), virtual reality (VR), and more. How Does OpenCV Work? At its core, OpenCV helps computers interpret visual data similarly to how the human eye works. It can perform a variety of tasks such as: In low-light conditions (like nighttime), where typical visual data capture might fail, sensor fusion techniques (combining data from multiple sensors) are used to enhance the vision system. Key Features of OpenCV Applications of OpenCV in Computer Vision 1. Robotics ApplicationsOpenCV enables robots to “see” by integrating object detection and recognition, helping them interact intelligently with their environment. Tasks like obstacle avoidance, path planning, and human-robot interaction heavily rely on OpenCV. 2. Medical ApplicationsIn the healthcare industry, OpenCV is used for medical image analysis, such as detecting anomalies in X-rays, CT scans, and MRIs. It also aids in developing diagnostic tools and surgical assistance technologies. 3. Industrial Automation ApplicationsOpenCV plays a vital role in manufacturing and quality control. It powers automated inspection systems, assembly line monitoring, and defect detection processes. 4. Transportation ApplicationsIn autonomous vehicles, OpenCV is used for:Lane detection and road analysis.Traffic signs and pedestrian recognition.Object tracking for safe navigation. How OpenCV Handles Images Images in OpenCV are processed as arrays of pixel values. Depending on your requirements, you can load an image in different modes using the cv2.imread() function: -1 (Alpha Channel): Loads the image with transparency (if available). 1 (Color Mode): Loads a color image with all channels (RGB). 0 (Grayscale Mode): Loads the image in black and white. Image Filtering in OpenCV Image filtering is used to enhance or modify images, such as removing noise, blurring, or sharpening. Filters work by altering pixel values based on a mathematical operation performed on a kernel (matrix) and the surrounding pixels. Types of Filters: Convolution and Kernels in OpenCV Convolution is the core operation behind filters in OpenCV. A kernel (matrix) slides over the image, performing operations on pixel values to produce a new image. Kernels, or matrices used in image filtering, are typically implemented as NumPy arrays in OpenCV. Key Steps in Convolution: Convolution Formula: Popular Filters and Techniques in OpenCV Applications of OpenCV: Detection and Recognition OpenCV enables the development of diverse detection and recognition applications. A key feature in OpenCV is the Haar-cascade classifier, which implements the Viola-Jones algorithm. What is Haar-Cascade? Haar-cascade is a machine learning-based object detection algorithm. It was initially developed for real-time face detection but later expanded to detect various objects. The process involves: Challenges with Haar-Cascade: Why Deep Learning is Preferred Today Deep learning models like CNNs (Convolutional Neural Networks) have largely replaced Haar-cascade in many applications. These models: Haar-Cascade Today Despite its limitations, Haar-cascade remains relevant for: Challenges in Computer Vision and AI Development Lighting Effects in Detection Lighting significantly impacts the performance of computer vision systems. Poor or uneven illumination, such as overly bright or dark regions, can cause detection errors: Facebook’s Face Detection System Facebook made a significant decision to discontinue its facial recognition system in 2021, citing ethical and privacy concerns: Apple’s Role in Computer Vision Apple is a leader in integrating computer vision into consumer products, focusing on hardware and software advancements: Challenges with Open-Sourcing AI Technologies AI companies face dilemmas in balancing innovation, transparency, and commercial interests: