Flows
Instrument and monitor multi-step AI systems.

Introduction
LLM-powered systems are multi-step processes, leveraging information sources, delegating computation to tools, or iterating with the LLM to generate the final answer.
Looking at the inputs and output of such a system is not enough to reason about its behavior. Flows address this by tracing all components of the feature, unifying Logs in a comprehensive view of the system.
Basics
To integrate Flows in your project, add the SDK flow decorator on the entrypoint of your AI feature.
Python
TypeScript
The decorator will capture the inputs and output of the agent on Humanloop.
You can then start evaluating the system’s performance through code or through the platform UI.
Tracing
Additional Logs can be added to the trace to provide further insight into the system’s behavior.
On Humanloop, a trace is the collection of Logs associated with a Flow Log.
Python
TypeScript
The agent makes multiple provider calls to refine the response to the question. It makes function calls to search_wikipedia
to retrieve additional information from an external source.
Calling the other functions inside call_agent
creates Logs and adds them to the trace created by call_agent
.

Manual Tracing
If you don’t want to use decorators, first create a Flow Log, then pass its id
when creating Logs you want to add to the trace.
Code for Manual Tracing
Python
TypeScript
Versioning
Any data you pass into attributes
will contribute to the version of the Flow. If you pass in a new value, the version will be updated.
Python
TypeScript
Completing Flow Logs
Traces must be marked as complete once all relevant Logs have been added. The flow
decorator will mark a trace as complete when the function returns.
Monitoring Evaluators only run on Flow Logs once the log is completed. Completing the Flow Log signals its Evaluators that no other Logs will arrive.
Unlike other Logs, Evaluators added to Flows can access all Logs inside a trace:
A Flow Log’s metrics, such as cost, latency and tokens, are computed once the Log is completed.
A Flow Log’s start_time
and end_time
are computed automatically to span the earliest start and latest end of the Logs in its trace. If start_time
and end_time
already span the Logs’ timestamps, they are kept.
Manual Tracing
If you don’t want to use the decorator, you can complete the Flow Log via the SDK directly.
Code for Manual Tracing
Python
TypeScript
Evaluation
Unlike Prompts, which can be evaluated via the Humanloop UI, you must run evaluations on your Flows through code. After each Flow Log is complete, Evaluators added to the evaluation will still run on Humanloop.
To do this, provide a callable
argument to the evaluations.run
SDK method.
Python
TypeScript
Next steps
You now understand the role of Flows in the Humanloop ecosystem. Explore the following resources to apply Flows to your AI project:
-
Check out our logging quickstart for an example project instrumented with Flows.
-
Dive into the evals guide to learn how to evaluate your AI project.