Moldable Chat: Raising the chat conversation level through specialized tools
Tools provide the interface through which the LLM perceives the world. We can use them to raise the level of abstraction.
An interesting case can be observed in SmaCC, the compiler-compiler that underpins many of the tools in Glamorous Toolkit. SmaCC lets us define parsers in a dedicated, succinct language and then generates the corresponding Smalltalk code. While the generated code is useful at runtime, understanding the parser is easier when working with the higher-level language. The tools already support this. For example, JSParser
contains the parser for JavaScript, but when you browse the class, you first see a dedicated high-level browser.
If we want the LLM to produce such parsers, it also benefits from working with the higher-level representation rather than the generated source code. In the example below, we add dedicated tools for that purpose (subclasses of GtLSmaCCTool
):
smaccModel := GtLSmaCCModel new. c := GtL gt addTools: (GtLSmaCCTool allSubclasses collect: [ :each | each new model: smaccModel ]); gtPageExplanation: 'SmaCC grammar'; sendMarkdown: 'Create a SmaCC parser to parse and evaluate simple math expressions. The class should be named `SampleExpressionParser` and be in the package `TempParsers`. Ensure you get no error in the parser. Compile the parser. Build the abstract syntax tree. Add expression evaluation logic. Test it with a simple script and once it''s working provide the script'
The prompt above will likely lead the LLM to use the tools to create a grammar, compile it, and test it with an input string. The prompt also asks it to extend the generated abstract syntax tree with evaluation logic, which requires compiling methods. This means mixing levels of abstraction, and that typically works well too.
To see how a parser can be updated, try the prompt below:
c sendMarkdown: 'Update the parser with the ability to raise to power.'