agentlang-ai / agentlang

Generative AI-powered Programming Language
Apache License 2.0
119 stars 4 forks source link

Have `auto-generated` attributes #691

Open puneet-fractl opened 1 year ago

puneet-fractl commented 1 year ago

These attributes can not be written by the user but will be provided by the system. Ex.

{:LastUpdatedAt {:type :Kernel/DateTime
                 :auto-generated true}}
vijayfractl commented 1 year ago

@fractlrao @puneet-fractl Does this imply that the instance is always generated by (or passes through) a resolver that know how to auto-generate the correct value for the attribute? I think there could be three possibilities here -

  1. Auto-generated by the storage layer - like an auto-increment int field. In this case the model may not be portable to other stores.
  2. Auto-generated by a resolver - again the model is not portable because it is bound to a particular resolver implementation
  3. Auto-generated by business logic in the model itself, an example is shown below
(defn generate-user-hash [instance]
  (hash (str (:UserName instance) ":" (:Email instance))))

 (entity :User
  {:Username :Kernel/String
   :Email :Kernel/Email
   :Hash {:auto-generated true
          :generator generate-user-hash}})

I think for (1) the spec should be :auto-increment true. For (2) the :generator is omitted.

puneet-fractl commented 1 year ago

What if it's :optional by default?

vijayfractl commented 1 year ago

The developer may mark an :auto-generated attribute as :optional, but marking an :auto-increment field should be an error. This ensures that this model is always used with a compliant store. Moreover, an auto-increment field is often used as identity.