LLM tools by example

A tool can be used by an LLM chat to execute logic. For example, the below chat looks up the definition of a class using GtLToolForClassLookup GtLAbstractFunctionTool << #GtLToolForClassLookup slots: {}; tag: 'Tools'; package: 'Gt4LlmCore' .

messageWithToolCallExample
	<gtExample>
	<noTest>
	| chat  |
	chat := self currentChat.
	chat tools: (GtLTools withAll: {GtLToolForClassLookup new}).
	chat markdownResponse.
	chat sendMarkdown: 'Use tools and give me a description of the class BlElement'.
	self waitForChatRunIsDoneThen: [ 
		self assert: self currentChat messages size equals: 2 ].
	^ chat
    

A tool's implementation has a name, takes arguments and returns an instance of GtLDomainObject Object << #GtLDomainObject traits: {TGtLDomainObject}; slots: {}; tag: 'Domain Objects'; package: 'Gt4LlmCore' . This instance knows how to serialize itself. For OpenAI it serializes by implementing GtLDomainObject>>#serializeToOpenAIResponseJsonObject serializeToOpenAIResponseJsonObject "Return a JSON dictionary that represents the domain object." <return: #NeoJSONObject> ^ self subclassResponsibility .

Each tool has corresponding examples that test its logic in isolation. For example, GtLToolForClassLookup GtLAbstractFunctionTool << #GtLToolForClassLookup slots: {}; tag: 'Tools'; package: 'Gt4LlmCore' has examples in GtLToolForClassLookupExamples Object << #GtLToolForClassLookupExamples slots: {}; tag: 'Tools'; package: 'Gt4LlmCore-Examples' .