Step
Using the decorator on a function
If you want to create a step from a function, you should use the @client.step
decorator.
The step is automatically ended and sent to the platform when the function returns.
Another advantage of using the decorator is that you get several variables automatically set for you:
name
: The name of the step. This is automatically set to the function name.input
: The input of the step. This is automatically set to the arguments of the function.output
: The output of the step. This is automatically set to the return value of the function.
Here is how to use the decorator:
If you want to override the default step parameters, you can pass them to the decorator:
You can access the step object with the get_current_step
method:
Using the with
statement
If you want to create a step from a block of code, you should use the with
statement.
The step is automatically ended and sent to the platform when the code exits the with
block.
If you want to override the default step parameters, you can pass them to the step
method:
Using the start_step
method
This method should be used as a last resort because it doesn’t automatically end the step.
You must call the end
method on the step object to end the step and send it to the platform.
You can either pass the step parameters to the start_step
method, or set them directly on the step object:
Step parameters
The id of the thread
The id of the step. If not provided, a random uuid will be generated. Use custom ones to match your own system. Step ids must be unique across your project.
The name of the step (automatically set to the function name if using the decorator)
The type of the step. A Step can be one of the following types:
run
: A generic steptool
: A step that runs a toolllm
: A step that runs a language modelembedding
: A step that runs an embedding modelretrieval
: A step that retrieves documentsrerank
: A step that reranks documentsundefined
: An undefined step
Metadata associated with the step. This enables you to add custom fields to your steps.
The id of the parent step. This enables you to create nested steps.
The start time of the step.
The end time of the step.
The server-side creation time of the step.
A dictionary symbolizing an input.
Prefer using content
key to store a message.
A dictionary symbolizing an output.
Prefer using content
key to store a message.
The tags of the step. This is a complimentary field to the metadata field. It enables you to add custom tags to your steps.
The generation object associated with the step.
The feedback object associated with the step.
The attachments associated with the step.
Step API
Step API
Manipulate steps directly using the API.