Skip to content

dzzie/ai4vb

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ai4vb

Agentic AI for VB6. An AI agent loop running inside a VB6 host that can introspect and reason about a live VB6 object model. Point ChatGPT or Claude at any VB6 project, and the agent discovers its classes via auto-generated proto files, queries live instances through a JScript bridge, and answers questions about the data — all from inside the IDE.

The framework is the load-bearing structure. The prompt is where the work actually happens.


What it does

An AI agent emits JScript one stage at a time. The VB6 host evaluates each script against a live, in-memory object graph and feeds the result back to the AI for the next stage. The AI discovers what's in the object graph by calling host.describe(obj), which returns a proto description auto-generated from the project's source. After enough discovery, the AI computes an answer, delivers it via host.answer(...), and emits DONE.

Both OpenAI's /v1/responses (with previous_response_id chaining) and Anthropic's /v1/messages (with client-maintained history, since their API is stateless) are supported polymorphically. Same code, same prompt, swap backends via radio button.


The pieces

File Role
Form1.frm UI host. Contains the agent loop, ScriptControl, regen button, cancel button, progress bar.
COpenAI.cls OpenAI client. Async HTTP with poll-loop and cancel support. Uses previous_response_id for context.
CClaudeAI.cls Anthropic client. Same surface as COpenAI; maintains conversation history in-memory because Anthropic's API is stateless.
CJSON.cls JSON parser/path-accessor over ScriptControl.
CLogger.cls Append-only logger with timestamps and section headers. Every run produces a re-readable trail.
CManager.cls, CUser.cls, CProject.cls Test domain. Replace with your own model in real use.
modProtoGen.bas Source-parses the .vbp + each .cls/.frm and writes ./protos/<ClassName>.txt.
prompt.txt System prompt for the agent. Hardened against specific JScript/MSScriptControl gotchas.
./protos/ Auto-generated descriptions of every public class in the project. Regenerated on demand via the Regen button.
./agent.log Full trace of the last N agent runs. Every prompt, script, error, and elapsed time.

The two layers

The framework layer (this codebase): delivers a live object model to an AI agent. Handles introspection, dispatch, context, retries, cancellation, logging. Backend-agnostic. Domain-agnostic. Reusable across any VB6 project with a class hierarchy.

The prompt layer (prompt.txt + the questions you ask): what the AI is told about the environment, and what you ask it. This is where domain expertise plugs in. The prompt currently encodes a handful of hard-won environment gotchas (see below); the questions you write are yours.

The framework doesn't try to make the AI smart. It tries to give the AI everything it needs and stay out of the way.


How a run works

[user clicks Agentic Test]
    │
    ▼
cmdAgentTest_Click
    │
    ├── select backend (radio button: ChatGPT or Claude)
    ├── reset conversation context
    ├── open log file
    ├── lock agent button, unlock cancel, prime progress bar
    │
    └── for stage in 1..MAX_STAGES:
          │
          ├── send user message to AI (async HTTP, polls with DoEvents)
          ├── receive JScript
          ├── reset JScript engine (hermetic per stage)
          ├── re-bind manager + host
          ├── sc.Eval(jsScript)
          ├── capture result or error
          ├── log everything
          │
          ├── if AI returned "DONE" → exit
          ├── if HTTP error or cancelled → exit
          └── otherwise build next user message:
                - on JS error: send error + failed script
                - on success: send "Result: [...] If done, DONE."

The introspection contract

The AI doesn't know what's in your object graph. It learns by calling:

host.describe(manager)                       // returns CManager proto
host.describe(manager.Users.Item(1))         // returns CUser proto
host.describe(manager.Projects.Item(1))      // returns CProject proto

host.describe reads ./protos/<TypeName(obj)>.txt, which is generated by modProtoGen from your .vbp and source files. The proto mirrors VB6 syntax with bodies stripped:

Class CProject
  Public name As String
  Public leadName As String
  Public budget As String
End Class

There is no per-class describeSelf() method to write or maintain. The source is the source of truth. Regenerate after schema changes by clicking the Regen button.


Prompt gotchas (earned, not theorized)

Each section in prompt.txt corresponds to a real failure mode observed in a real log. Worth knowing they exist:

  • .Count() needs parens, .Count does not work. MSScriptControl binds VB Collection's Count as a method, not a property, despite the typelib. Empirically confirmed; the model burned 12+ stages trying to recover before we added this rule.
  • JScript runs hermetically per stage. sc.Reset between stages. Variables don't persist; the AI was told and stopped relying on it.
  • String vs number comparison. "85000" > "420000" is true in JScript because it's lexicographic. The proto honestly shows Public budget As String; the prompt now warns the AI to parseFloat numeric-looking strings before comparing.
  • For-in doesn't enumerate COM members. Use host.describe() instead.
  • Multi-task DONE. When a single user message has multiple tasks, DONE means all of them. Each gets its own host.answer.

Setup

  1. Open Project1.vbp in VB6.
  2. Set your API keys in the form (one per backend) and click each Set button. Keys persist to the registry.
  3. Click the Regen button to generate ./protos/. Click it again after any class structure changes.
  4. Type a question in txtAgentPrompt.
  5. Select ChatGPT or Claude via the radio buttons.
  6. Click Agentic Test.

The log file ./agent.log will contain the full trace. Watch the progress bar; click Cancel to abort mid-run.


Adapting to your own VB6 project

  1. Drop your classes into a project that includes modProtoGen, COpenAI, CClaudeAI, CJSON, CLogger, and a Form1-style host.
  2. Replace mgr in Form1 with your root domain object (or add an additional sc.AddObject call inside the agent loop's per-stage rebind).
  3. Click Regen.
  4. Ask questions.

The framework is class-agnostic. It works whatever your domain is, as long as every class you want introspected is listed in the .vbp as a Class= or Form= entry.


What this is not

  • Not a chatbot. The agent runs to completion or to MAX_STAGES; it's not for free-form conversation.
  • Not a code generator. It introspects and reasons about live data, not source files.
  • Not async-first. The HTTP layer is async with polling, but the agent loop is otherwise synchronous and runs on the UI thread.
  • Not a typelib reflector. It uses source-parsed protos rather than ITypeInfo, because Standard EXE VB6 projects don't register typelibs and this works the same on Standard EXE, ActiveX EXE, and ActiveX DLL alike.

Status

Roger is still the oldest user. Carol still leads Sentinel.

The framework is solid. The system has been tested end-to-end with both backends on single-task and multi-task prompts. Self-discovery works (the AI finds new classes added to the project without prompt updates). Cancel works. Hermetic per-stage execution works. Logging captures enough for full post-hoc debugging.

About

AI integration classes for Claude and ChatGPT with Agentic COM demo

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors