Workflow Annotations
Enrich your traces by annotating chains and workflows in your app
Traceloop SDK supports several ways to annotate workflows, tasks, agents and tools in your code to get a more complete picture of your app structure.
If you’re using a framework like Langchain, Haystack or LlamaIndex - no need to do anything! OpenLLMetry will automatically detect the framework and annotate your traces.
Workflows and Tasks
Sometimes called a “chain”, intended for a multi-step process that can be traced as a single unit.
Use it as @workflow(name="my_workflow")
or @task(name="my_task")
.
The name
argument is optional. If you don’t provide it, we will use the
function name as the workflow or task name.
You can version your workflows and tasks. Just provide the version
argument
to the decorator: @workflow(name="my_workflow", version=2)
Use it as @workflow(name="my_workflow")
or @task(name="my_task")
.
The name
argument is optional. If you don’t provide it, we will use the
function name as the workflow or task name.
You can version your workflows and tasks. Just provide the version
argument
to the decorator: @workflow(name="my_workflow", version=2)
This feature is only available in Typescript. Unless you’re on Nest.js, you’ll need to update your tsconfig.json
to enable decorators.
Update tsconfig.json
to enable decorators:
Use it in your code @traceloop.workflow({ name: "my_workflow" })
.
You can provide the parameters to the decorator directly or by providing a function that resolves to the parameters.
The function will be called with the this
parameter and the arguments of the decorated function
(see example).
The name is optional. If you don’t provide it, we will use the function qualified name as the workflow or task name.
Use it as withWorkflow("my_workflow", {}, () => ...)
or withTask(name="my_task", () => ...)
.
The function passed to withWorkflow
or withTask
witll be part of the workflow or task and can be async or sync.
Agents and Tools
Similarily, if you use autonomous agents, you can use the @agent
decorator to trace them as a single unit.
Each tool should be marked with @tool
.
Similarily, if you use autonomous agents, you can use the @agent
decorator to trace them as a single unit.
Each tool should be marked with @tool
.
Similarily, if you use autonomous agents, you can use the @agent
decorator to trace them as a single unit.
Each tool should be marked with @tool
.
If you’re not on Nest.js, remember to set experimentalDecorators
to true
in your tsconfig.json
.
Similarily, if you use autonomous agents, you can use the withAgent
to trace them as a single unit.
Each tool should be in withTool
.
Async methods
In Typescript, you can use the same syntax for async methods.
In python, the decorators work seamlessly with both synchronous and asynchronous functions.
Use @workflow
, @task
, @agent
, and so forth for both sync and async methods.
The async-specific decorators (@aworkflow
, @atask
, etc.) are deprecated and will be removed in a future version.
See also a separate section on using threads in Python with OpenLLMetry.
Decorating Classes (Python only)
While the examples above shows how to decorate functions, you can also decorate classes. In this case, you will also need to provide the name of the method that runs the workflow, task, agent or tool.
Was this page helpful?