Skip to content

Reply functions

Reply Functions

Reply functions are used for giving responses in an Autograms chatbot. These functions pause the program and cause the stack to return to the point before where the first @autograms_function was called. Typically, the entry @autograms_function is wrapped using the Autogram class. A call to a reply function will cause autogram.reply() to return. The Memory Object tracks what line in an @autograms_function the reply came from, so that the next time autogram.reply() is called with a new user input, the program will continue from that point--including recalling any @autograms_function s that are needed to re-create the stack from where the reply was given.

There are some similarities between reply() functions and the Python input function. input also pauses a program to wait for a reply. However with input or any other mechanism that pauses the program, the program must continue to run indefinitely while waiting for a response, making it impractical for most chatbot APIs that mandle multiple users. Autograms reply functions used within @autograms_functions and managed by an Autogram object can simulate the effect of the input command while also allowing the state of the function (and stack trace) to be serialized, saved, and reloaded from the disk or a database later.

reply(text, data,**kwargs)

autograms.functional.reply Raises a ReplyExit exception to send a direct reply.

  • Parameters:
  • text (str): The reply message to the user.
  • data (dict): optional data to be sent back in autograms return object sent by autogram.apply()

  • Raises:

  • ReplyExit: Used to exit the current function and send the reply.

reply_suffix(instruction,**kwargs)

autograms.functional.reply_suffix Replies to the user and includes the specified suffix in the response.

  • Parameters:
  • instruction (str): The suffix to be included in the reply.
  • data (dict): optional data to be sent back in autograms return object sent by autogram.apply()

  • Raises:

  • ReplyExit: Used to exit the current function and send the reply.

reply_instruction(instruction,**kwargs)

autograms.functional.reply_instruction Replies based on an instruction generated by the conversational model.

  • Parameters:
  • instruction (str): The instruction to guide the reply.
  • data (dict): optional data to be sent back in autograms return object sent by autogram.apply()

  • Raises:

  • ReplyExit: Used to exit the current function and send the reply

ADDRESS argument in reply functions (Advanced)

All reply functions accept an ADDRESS keyword argument meant for the compiler. Specifying ADDRESS for reply functions is optional and more advanced, but does makes it possible to change the program mid execution since it allows line numbers to be mapped. Without an ADDRESS defined, it will most likely cause an error to do this due to the changing line numbers. If you for instance encounter a reply you do not like--if an ADDRESS is defined, you can change the code and reload the previous memory object to see how this change affects the reply. If the reply is inside a nested @autograms_function() scope, you must also provide an ADDRESS argument to each @autograms_function() call in the stack trace. If you want your code to be able to be reloaded mid-execution with changes--you should include an ADDRESS key word argument to every reply function/node, and every call to an @autograms_function(). Note that all @autograms_function()s can accept an ADDRESS keyword, regardless of whether the wrapped function has an ADDRESS keyword argument.

Technically, an ADDRESS for a reply function can be a target for a GOTO or RETURNTO, although it's recommended to use nodes instead for this behavior.

ADDRESS is only meant for the compiler-- and each value passed as an ADDRESS must be unique, and be a string literal or global constant so that it can be determined at compile time.