code

Type EString
Multiplicity 0..1

How code attribute is used is subclass-specific:

  • Crew - code is added to the top of the generated crew class after configuration fields and before any other declarations.
  • Agent and Task - code is used as agent/task method body template.
  • Function - code is used to produce function body.
  • Tool - what is added to the tools array. E.g. SerperDevTool().

Code can contain interpolation tokens for adding imports. Example:

my_var = ${spel:addItemImport('my_module', 'my_item').item}
  • spel: is a prefix for Spring Expression Language tokens.
  • addItemImport('my_module', 'my_item').item - calls org.nasdanika.models.python.Source.addImport() method and then getItem() value of the result. Import methods:
    • addItemImport(module, item) - the method used above
    • addItemImport(module, item, name) - in this case use .name
    • addModuleImport(module) - in this case use add dot and imported item after the token. e.g. ${spel:addModuleImport('my_module').module}.my_item
    • addModuleImport(module, alias) - in this case use add dot and imported item after the token. e.g. ${spel:addModuleImport('my_module', 'mi_modulo').alias}.my_item