DEV Community

Xiao Ling
Xiao Ling

Posted on • Originally published at dynamsoft.com

Solving the AI Knowledge Gap: Testing AI Agents with Dynamsoft Barcode Reader SDK

As AI coding assistants become increasingly popular, developers face a critical question: Which AI agent provides the most accurate and up-to-date code? This article documents a comprehensive experiment testing five major AI coding agents and how to solve their knowledge limitations.

The Experiment

I tested the following AI coding agents with a single, straightforward prompt:

"Create a command line barcode scanner in Python using the Dynamsoft Barcode Reader SDK"

AI Agents Tested

  1. Claude Sonnet 4

    Claude Sonnet 4

  2. Claude Sonnet 4.5

    Claude Sonnet 4.5

  3. Gemini 2.5 Pro

    Gemini 2.5 Pro

  4. GPT-5

    GPT-5

  5. Grok Code

    Grok Code

The Problem: Outdated Knowledge

What Happened

Out of five AI agents tested, only Claude Sonnet 4.5 generated code using the latest version of the Dynamsoft Barcode Reader SDK. The remaining five agents produced code based on outdated API versions, which would fail in production environments.

Why This Matters

The Dynamsoft Barcode Reader SDK underwent significant changes in its Python package:

  • Old Package: dbr (deprecated)
  • New Package: dynamsoft-barcode-reader-bundle (current)

The API structure also changed:

  • Different import statements
  • Updated class names and methods
  • New license initialization approach
  • Changed result handling patterns

The Knowledge Gap

This experiment revealed a fundamental challenge with AI coding agents:

  1. Training Data Cutoff: Most AI models have a knowledge cutoff date, meaning they lack awareness of recent updates.
  2. Inconsistent Updates: Even models with similar architectures (like Claude Sonnet 4 vs 4.5) have different knowledge bases.
  3. API Documentation Access: Not all agents effectively retrieve and process the latest documentation.

The Solution: Custom Agent Definitions

After identifying the knowledge gap, I created a custom agent definition that successfully solved the problem for all AI agents.

What is a Custom Agent?

A custom agent is a configuration file that:

  • Defines the agent's role and expertise
  • Specifies tools the agent should use
  • Provides explicit instructions on accessing up-to-date information
  • Establishes golden rules for code generation

The Custom Agent Structure

I created the custom agent in .github/agents/python-barcode-scanner.agent.md:


---
description: 'Python helper for Dynamsoft Barcode Reader that always checks the latest docs and samples.'
tools:
  - fetch       # read web pages for latest docs
  - githubRepo  # search Dynamsoft sample repos
  - search      # workspace/code search
  - edit        # edit files in the workspace
---

# Role
You are an expert Python assistant for the **Dynamsoft Barcode Reader SDK (DBR) Python Edition**.

## Golden rules

1. **Always use latest Python package & APIs**
   - Prefer the **`dynamsoft-barcode-reader-bundle`** package (successor to `dbr`).
   - Show installation as:
     > pip install dynamsoft-barcode-reader-bundle

   - Use imports that match the *current* Dynamsoft Python docs and samples.

2. **Always check the latest documentation before giving DBR-specific code**
   - Before answering any question involving DBR code, use the `#fetch` tool on:
     - https://www.dynamsoft.com/barcode-reader/docs/server/programming/python/
     - https://www.dynamsoft.com/barcode-reader/docs/server/programming/python/user-guide.html
     - https://github.com/Dynamsoft/barcode-reader-python-samples
   - If the docs and prior knowledge conflict, **trust the docs**.

3. **Keep answers runnable and up to date**
   - Always include complete, minimal working examples in Python.
   - Include necessary imports, license initialization, and basic error handling.

4. **Always create actual code files for complete solutions**
   - Generate the actual `.py` file(s) using the workspaceWrite tool.
   - Use descriptive filenames (e.g., `barcode_scanner.py`).
   - Include complete, runnable code with proper structure.

5. **Explain when you're relying on fetched docs**
   - Briefly tell the user that you just looked at the latest Dynamsoft docs.

6. **When the user gives a URL**
   - Use `#fetch` with that URL first.
   - Base your answer on that exact version.

Enter fullscreen mode Exit fullscreen mode

Key Components of the Solution

1. Tool Specifications

The custom agent explicitly requires specific tools:

tools:
  - fetch       # Forces the agent to read web pages
  - githubRepo  # Enables searching official sample repositories
  - search      # Workspace and code search
  - edit        # File editing capabilities
Enter fullscreen mode Exit fullscreen mode

2. Golden Rules

The most critical aspect is establishing Golden Rules that force the agent to:

  • Always use the latest package name: dynamsoft-barcode-reader-bundle
  • Always fetch documentation before coding: This ensures up-to-date information
  • Trust documentation over training data: Explicitly tells the agent to prioritize fetched content
  • Create actual files: Not just inline code snippets

3. Documentation URLs

By providing exact URLs to official documentation, we ensure:

  • Agents fetch the latest API information
  • Consistency across different AI models
  • Access to working code examples

Results: Before and After

Before Custom Agent

AI Agent Package Used Result
Claude Sonnet 4 dbr (outdated) ❌ Failed
Claude Sonnet 4.5 dynamsoft-barcode-reader-bundle ✅ Success
Gemini 2.5 Pro dbr (outdated) ❌ Failed
GPT-5 dbr (outdated) ❌ Failed
Grok Code dbr (outdated) ❌ Failed

After Custom Agent

AI Agent Package Used Result
Claude Sonnet 4 dynamsoft-barcode-reader-bundle ✅ Success
Claude Sonnet 4.5 dynamsoft-barcode-reader-bundle ✅ Success
Gemini 2.5 Pro dynamsoft-barcode-reader-bundle ✅ Success
GPT-5 dynamsoft-barcode-reader-bundle ✅ Success
Grok Code dynamsoft-barcode-reader-bundle ✅ Success

Result: 100% success rate across all AI agents!

How to Implement and Load Custom Agents

The easiest way to create and use a custom agent in VS Code:

  1. Create a new custom agent:

    • Open the Chat box in Visual Studio Code
    • Click on Agent dropdown
    • Select Configure Custom Agents
    • Click Create new custom agent
    • Name your agent (e.g., "python-barcode-scanner")
  2. Load and use the agent:

    • In the Chat box, click on the Agent dropdown
    • Select your created custom agent
    • Choose a specific model to use with this agent
    • Start chatting with your configured agent

This method automatically creates the necessary file structure and allows you to edit the agent definition through the VS Code interface.

copilot custom agent

Code Examples

The Correct Implementation (Latest API)

#!/usr/bin/env python3
"""
Command-line barcode scanner using Dynamsoft Barcode Reader SDK
"""
import sys
import os
from dynamsoft_barcode_reader_bundle import *


def scan_barcode(image_path):
    """Scan barcode from a single image file"""
    # Check if file exists
    if not os.path.exists(image_path):
        print(f"Error: File '{image_path}' not found.")
        return

    # Initialize license (public trial license)
    errorCode, errorMsg = LicenseManager.init_license(
        "DLS2eyJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSJ9" # Replace with your actual license key
    )
    if errorCode != EnumErrorCode.EC_OK and \
       errorCode != EnumErrorCode.EC_LICENSE_CACHE_USED:
        print(f"License initialization failed: {errorCode}, {errorMsg}")
        return

    # Create CaptureVisionRouter instance
    cvr_instance = CaptureVisionRouter()

    # Capture barcode from image
    print(f"Scanning barcode from: {image_path}")
    result = cvr_instance.capture(
        image_path, 
        EnumPresetTemplate.PT_READ_BARCODES.value
    )

    # Check for errors
    if result.get_error_code() != EnumErrorCode.EC_OK:
        print(f"Error: {result.get_error_code()} - {result.get_error_string()}")
        return

    # Get barcode results
    barcode_result = result.get_decoded_barcodes_result()
    if barcode_result is None or len(barcode_result.get_items()) == 0:
        print("No barcode detected.")
        return

    # Display results
    items = barcode_result.get_items()
    print(f"\n✓ Decoded {len(items)} barcode(s):\n")
    for index, item in enumerate(items):
        print(f"Result {index + 1}:")
        print(f"  Format: {item.get_format_string()}")
        print(f"  Text: {item.get_text()}")
        print()


if __name__ == "__main__":
    if len(sys.argv) < 2:
        print("Usage: python barcode_scanner.py <image_path>")
        sys.exit(1)

    scan_barcode(sys.argv[1])
Enter fullscreen mode Exit fullscreen mode

The Outdated Implementation (Old API)

# ❌ This is what most agents generated - it doesn't work!
import dbr  # This package is deprecated!
from dbr import *

# Old API that no longer exists
reader = BarcodeReader()
reader.init_license("YOUR-LICENSE-KEY")

# Old method names
text_results = reader.decode_file("image.jpg")

# Old result handling
for result in text_results:
    print(result.barcode_text)
Enter fullscreen mode Exit fullscreen mode

When to Use Custom Agents

Consider creating custom agents for:

  1. Rapidly Evolving SDKs: APIs that frequently change or update
  2. Complex Domain Knowledge: Specialized libraries or frameworks
  3. Enterprise Development: Ensuring consistent code standards
  4. Team Collaboration: Standardizing AI assistance across team members
  5. Quality Assurance: Reducing bugs from outdated code patterns

Source Code

https://github.com/yushulx/python-barcode-qrcode-sdk/tree/main/examples/official/ai_agent

Top comments (0)