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, start by creating a logging trace.
Using the Humanloop SDK, we are capturing the inputs and output of the agent on Humanloop, and we can already begin evaluating the system’s performance through code or through the platform UI.
Additional Logs can be added to the trace, providing additional context when investigating.
Tracing
When creating a Log, use the trace_parent_id
attribute to link it to another Log in a trace, forming a chain of related actions.
In the scenario above, call_agent
calls call_model
multiple times to refine responses. Through function calls to search_wikipedia
, the LLM queries an external source to provide factual answers.
Calling the other functions inside call_agent
creates Logs and adds them to the trace created by call_agent
.
Versioning
Flow versioning is managed through the attributes
field, which acts as your feature’s manifest.
Observability
You must mark a trace as complete once all relevant Logs have been added. This triggers the monitoring Evaluators to evaluate the Log.
Evaluators can access nested Logs via the children
attribute, allowing you to evaluate individual steps or the entire workflow.
Evaluation
Unlike Prompts, which can be evaluated on the Humanloop runtime, you have to evaluate Flows on your side through code.
To do this, provide a callable
argument to the evaluate
method.
Flow-level metrics
Flow Logs calculate their start and end times based on the earliest and latest Logs in the trace.
Log metrics such as cost and token usage aggregate values from all Logs within the trace.
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.