Configure Span Types
Categorize your spans by type and set type-specific attributes
Overview
Span types are optional but allow you to classify the most common types of components in AI apps, which includes:
- LLMs: Track the model used, prompt version, token usage, and cost per token.
- Retrievers: Track the embedding model, chunk size, and top-k retrieval settings.
- Tools: Track tool descriptions and function calling behavior.
- Agents: Track available tools and agent handoffs for multi-agent orchestration.
This is set via the type parameter when observing a function. By classifying span types you can create more tailored UIs on Confident AI, view online evals specific to each span type, and set type-specific attributes instead of using generalized metadata.
Confident AI has tailored displays for different span types on the UI, such as displaying prompts for LLMs and chunk sizes for retrievers.
LLM Spans
An LLM span represents a call to a language model. It tracks the input, output, and token usage of the model.
Python
TypeScript
There are SIX optional parameters for update_llm_span:
- [Optional]
model: The model used, of typestr. - [Optional]
prompt: The prompt of typePrompt, which must be pulled prior to updating the span. - [Optional]
input_token_count: The number of tokens of typefloatin the input. - [Optional]
output_token_count: The number of tokens of typefloatin the generated response. - [Optional]
cost_per_input_token: The cost per input token of typefloat. - [Optional]
cost_per_output_token: The cost per output token of typefloat.
If cost_per_input_token is not set, setting input_token_count will not help calculate the cost. The same applies to output tokens.
For more information on setting token cost tracking, click here.
Retriever Spans
A Retriever span represents a component that fetches relevant information from a vector store or knowledge base. It’s a crucial part of RAG (Retrieval-Augmented Generation) pipelines, handling the embedding and retrieval process.
Python
TypeScript
There are THREE optional parameters for update_retriever_span:
- [Optional]
embedder: The name of the embedding model used of typestr. - [Optional]
chunk_size: The size of the text chunks retrieved of typeintfrom the vector store. - [Optional]
top_k: The number of text chunks retrieved of typeintfrom the vector store.
Tool Spans
A Tool span represents a function that an agent can call to perform a specific task. It’s commonly used for function calling in LLM applications.
Python
TypeScript
There is ONE mandatory and THREE optional parameters for the tool span type:
type: The type of span. Must be"tool"for tool spans.- [Optional]
description: A string that describes what the tool does. Defaulted to an empty string. - [Optional]
name: A string specifying the display name on Confident AI. Defaulted to the name of the observed function. - [Optional]
metricsA list of strings specifying the names of the online metrics you wish to run upon tracing to Confident AI. Learn more about using online metrics here.
Agent Spans
An Agent span represents an autonomous entity that can make decisions and interact with other components. It’s particularly useful for implementing thinking agents or multi-agent systems.
Python
TypeScript
There is ONE mandatory and FOUR optional parameters for the agent span type:
type: The type of span. Must be"agent"for agent spans.- [Optional]
available_tools: A list of strings specifying the tools this agent can use. Defaulted to an empty list. - [Optional]
handoff_agents: A list of strings specifying other agents this agent can delegate to. Defaulted to an empty list. - [Optional]
name: A string specifying the display name on Confident AI. Defaulted to the name of the observed function. - [Optional]
metricsA list of strings specifying the names of the online metrics you wish to run upon tracing to Confident AI. Learn more about using online metrics here.
Agents can be nested within other agents, which is useful for implementing hierarchical agent architectures. For instance, a “supervisor” agent might coordinate communication between specialized agents.
Custom Spans
The most flexible type out of all (and the default type if type is not provided), custom spans are essential for creating hierarchical structures or grouping related spans together. They provide flexibility in organizing your tracing data.
Python
TypeScript
There is ONE mandatory and TWO optional parameters for the Custom span type:
type: The type of span. Anything other than"llm","retriever","tool", and"agent"is a custom span type. Defaulted to thename.- [Optional]
name: A string specifying how this custom span is displayed on Confident AI. Defaulted to the name of the observed function. - [Optional]
metricsA list of strings specifying the names of the online metrics you wish to run upon tracing to Confident AI. Learn more about using online metrics here.
The input and output of a custom span default to the function’s input arguments and return value, but you can also set them dynamically.
Next Steps
Now that your spans are typed, enrich them further with prompt tracking and custom I/O.