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.
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.
| 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 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.
[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 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 protohost.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.
Each section in prompt.txt corresponds to a real failure mode observed in a real log. Worth knowing they exist:
.Count()needs parens,.Countdoes not work. MSScriptControl binds VB Collection'sCountas 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.Resetbetween stages. Variables don't persist; the AI was told and stopped relying on it. - String vs number comparison.
"85000" > "420000"istruein JScript because it's lexicographic. The proto honestly showsPublic budget As String; the prompt now warns the AI toparseFloatnumeric-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.
- Open
Project1.vbpin VB6. - Set your API keys in the form (one per backend) and click each Set button. Keys persist to the registry.
- Click the Regen button to generate
./protos/. Click it again after any class structure changes. - Type a question in
txtAgentPrompt. - Select ChatGPT or Claude via the radio buttons.
- Click Agentic Test.
The log file ./agent.log will contain the full trace. Watch the progress bar; click Cancel to abort mid-run.
- Drop your classes into a project that includes
modProtoGen,COpenAI,CClaudeAI,CJSON,CLogger, and a Form1-style host. - Replace
mgrinForm1with your root domain object (or add an additionalsc.AddObjectcall inside the agent loop's per-stage rebind). - Click Regen.
- 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.
- 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.
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.