Coding Agent
The ToolBox Agent is the coding agent on the Erik's ToolBox - Interactive Code page. It writes, fixes, explains, runs, and saves ToolBox programs by acting directly on the editor, the console, and your saved programs. This page describes what it operates on, how it works, what it knows about the ToolBox dialect, and how to get good results from it.
For the panel itself (sending messages, tool indicators, files, conversations) see Using the Agent Panel.
What the Agent Operates On
| Object | What the agent can do |
|---|---|
| The editor | Read the current program, replace it with a new one |
| The compiler | Check a program for errors without running it |
| The interpreter | Run the program in the editor, or run a throwaway snippet, and read the console output and diagnostics |
| The console | Output of a run appears in the console below the editor, exactly as when you press Run |
| Saved programs | List, read, load into the editor, and save (as the current program or under a new name) |
| The Excel data sheet | Programs it writes can use exset, exget, exclear, and exopen; loading a saved program restores its sheet |
| The data model | Find tables, pages, reports, codeunits, queries, XMLports, and enums by name or number; read a table's fields, types, option members, and keys; read sample rows |
| The dialect catalog | Search the functions and methods the interpreter supports before using one |
The agent has no access outside these tools. It cannot open other pages, change setup, or reach data except through the programs it runs, which run with your permissions.
How It Sees Your Program
The agent does not receive your code automatically. Its instructions tell it to call get_program at the start of every task. That tool returns:
- the source in the editor as it is right now, including edits you typed since the agent's last reply;
- the program name (empty when the program was never saved);
- whether the program has unsaved changes;
- the last run: when it ran, whether it succeeded, and the console output or the compile and runtime diagnostics, truncated at 6,000 characters.
The last run is recorded both when you press Run (or F9) and when the agent runs the editor program itself. That is why "Why did that fail?" works without pasting anything: the agent reads the diagnostics from the last run.
Snippets the agent runs without touching the editor do not update the last run.
What It Knows About ToolBox AL
The agent starts every conversation with instructions about the dialect, so it does not write full AL that the interpreter would reject. The instructions cover:
- Program structure. One script, no objects, no triggers, no
OnRun. An optionalvarsection, optional procedures with their ownvarsections, and one mandatory mainbegin..end;block that runs on Run. It gets a complete example program. - Console output.
Message()writes one line to the console; there are no dialogs to dismiss. - Records. Declare by table name in double quotes when needed (
Record "Sales Header"), never by number; field names must match the table exactly, andget_table_infois the source of truth. - Supported constructs. Records with filters,
FindSet/repeat,CalcFields,Insert/Modify/Delete, temporary records; the scalar types; one-dimensional arrays;List of [..]andDictionary of [..]; the four JSON types; codeunit variables from the supported list; procedures with parameters and return values;if/case/for/foreach/while/repeat; compound assignment. - Unsupported constructs.
check_programreports "X is not implemented" for anything the interpreter lacks. The agent is told to rewrite that part rather than retry the same code, and to uselist_script_functionsbefore using a method it is not sure about. - The Excel sheet.
exset(Row, Column, Value)orexset('A1', Value),exget,exclear(),exopen(), as the way to hand you tabular results. eval(Source)compiles and runs a source text and returns its console output.- Permissions. The program runs with your permissions and ToolBox access level, and it can modify data.
Because the instructions are written by the ToolBox and shipped with it, they track the interpreter. The agent can still be wrong about a detail; the check and run tools are how it finds out.
The Agent's Working Method
The instructions give the agent a fixed order of work:
- Understand. Call
get_program. Read the last run when you ask about a failure. - Discover. Never guess a table, field, report, or codeunit name or number.
find_objects, thenget_table_info, thenread_table_rowsto see real values and formats. - Write. Build the complete program text, run
check_programon it, fix every diagnostic, thenset_program. Becauseset_programreplaces the whole editor, keep everything of your code that you did not ask to change. - Run. Only when you asked or the task clearly needs it ("show me", "how many", "does this work"). Ask before running code that inserts, modifies, or deletes. Use a throwaway snippet to probe data without touching the editor. Read the output, fix, and re-run a few times at most.
- Save. Only with
save_programwhen you ask. Beforeopen_program, look at the unsaved flag and ask when it is set. - Explain briefly. The editor and the console are the output; do not repeat the program in the chat unless asked.
You will recognise this order in the tool indicators: a typical "write me a program" request shows get_program, one or two find_objects and get_table_info calls, check_program, and set_program, followed by a two-line summary.
What Happens on the Page
| Tool | Effect you see |
|---|---|
set_program |
The editor shows the new program within about two seconds. The program is marked as unsaved. Nothing is saved or run. |
check_program |
Nothing visible. The result (ok, or the diagnostics text) goes to the model only. |
run_program (editor program) |
The console shows the console output and any diagnostics, as after Run. The last run is recorded. |
run_program (snippet) |
The console shows the snippet's output. The editor and the last run are untouched. |
open_program |
The editor loads the saved program, the page caption shows its name, and its Excel sheet (if stored) replaces the current sheet. The unsaved flag is cleared. |
save_program |
The program is saved, the page caption adopts the name, the unsaved flag is cleared. If Program Storage sync is configured, the shared programs are synced. If the saved program already had an Excel sheet stored, the current sheet is stored with it. |
list_programs, get_saved_program, find_objects, get_table_info, read_table_rows, list_script_functions |
Nothing visible. Results go to the model only. |
The page picks up changes on a two-second poll. If you type in the editor at the exact moment the agent replaces the program, the agent's version wins; the agent reads the editor again at its next task.
Running Programs Through the Agent
run_program mirrors the Run action:
- the program is compiled; compile errors are returned as diagnostics and nothing runs;
- the source is recorded in the audit trail like a manual run;
- the license is checked: in an unregistered production environment the tool refuses with a message telling the agent that the ToolBox is not licensed;
- your ToolBox access level is applied, so a ReadOnly level makes writes fail at runtime;
- console output is captured and returned, together with runtime diagnostics if any;
- the output is truncated at 6,000 characters in the tool result; the console shows it in full.
The program runs in your session. A loop that never ends blocks your session until it finishes or times out, exactly as a manual run would. The agent is told to cap iterations while testing; if you ask it to process a whole ledger, expect a wait.
The Show output in console toggle on the page does not affect agent runs: their console output is always captured and shown in the console.
Example Requests
Write a program from a description
List all customers with a balance over 10,000, sorted by balance, and put name and balance in the Excel sheet.
Expect get_program, find_objects (Customer), get_table_info (18), check_program, set_program. The program appears in the editor; the reply is two or three lines. Ask "Run it" to execute and get the row count in the console.
Fix the current program
The last run failed. Fix it.
Expect get_program (reads the diagnostics from the last run), possibly a get_table_info to verify a field name, check_program, set_program, and often a run_program to confirm the fix if you asked for a run earlier in the conversation.
Explain code
Explain what this program does, step by step.
Expect get_program and a structured explanation. No changes to the editor.
Probe data without changing the editor
How many open sales orders are there per salesperson?
Expect the agent to run a snippet through run_program with a source parameter and report the counts. The editor keeps your program.
Modify part of a program
Add the customer's e-mail address to the output.
Expect get_program, get_table_info to find the E-Mail field, check_program, set_program. The rest of your program is preserved.
Data change with confirmation
Set the Salesperson Code to JR on every customer in the Copenhagen city.
Expect the agent to look up the fields, probe how many customers match, and then ask you to confirm before it runs the modifying program. Answer explicitly.
Reuse saved work
Open my program "Item Stock Report" and change it to only show items with inventory below the reorder point.
Expect list_programs or get_saved_program, open_program (after checking the unsaved flag), get_table_info, check_program, set_program.
Learn the dialect
Can I use a Dictionary of [Code[20], Decimal] here? Show me how.
Expect list_script_functions with a kind filter, and an example. Ask it to put the example in the editor if you want to run it.
Tips
- Give it a name. Programs the agent writes are unsaved. Say "save it as X" when you want to keep the result; the agent does not save on its own.
- Verify before writes. When the agent proposes a modifying program, read it in the editor before you answer yes. The agent can show you the affected rows first with a snippet.
- Use the last run. After a manual Run, "what went wrong?" is all the context the agent needs.
- Let it discover. If you are not sure about a field name, do not guess it in your request; describe what you mean and let
get_table_infosettle it. - Keep programs small. Ask for one report or one data fix at a time. Small programs compile, run, and get verified faster.
- One page per session. If you open the Interactive Code page twice, the agent acts on the page you opened last. Close the one you do not need.
- Symbols still matter for your own typing: the agent does not depend on downloaded symbols, but IntelliSense in the editor does. See Symbols.