- Start and end time are logged
- The output from the wrapped function is logged as the output of the step
- The updated step is sent to the Literal AI API
If your environment doesn’t support AsyncLocalStorage, or if you don’t like the callback style, you can always revert to the wrapper-less syntax. Please note that this syntax requires you to manually manage thread and step IDs, and also to manually send entities to the Literal AI API.
Basic usage
Thread wrapper
Step wrapper
Decoration wrapper
This wrapper is used to add metadata and tags to everything that will be logged inside it. It can also be used to specify in advance the ID of any generation created inside it.This is especially useful when using one of our integrations, as you may not be able to specify metadata
or tags directly in the API call, and you may not be able to retrieve the ID of the generation that was logged.
Advanced usage
Nesting wrappers
One advantage of using wrappers is that the structure of your code will closely represent the structure of the conversation as it is logged on Literal AI. For example consider the following code :
Nested threads and steps
Wrapping existing threads or steps
When you fetch a thread or step from the client, you can wrap it with thewrap method. This will allow you to add additional steps or threads to the existing one.
Updating steps and threads
Using the context
You can also update the current step or thread using the context object. The context object is available in the wrapped function and it will be sent to Literal AI upon exiting the wrapped function. There are two ways to access the context object:- It is provided as an argument to the wrapper function
- It is available as a property of the client object :
client.getCurrentThread()andclient.getCurrentStep()