Lens

Debug AI agent answers by tracing the context behind each turn, from retrieval to prompt.

What is Lens?

Lens is a Redis Iris observability tool that traces your AI agent's turns. A turn is one agent exchange, such as answering a single message. For each turn, Lens records what each source returned, such as a memory recall or a retrieval, and what entered the prompt. It also records which model and tool calls ran, how long each step took, and how the turn ended.

When your agent gives a wrong answer, Lens shows where it went wrong. For example, you might see that the right memory was recalled but dropped from the prompt, or that a retrieval came back empty.

Concepts

Learn how sessions, turns, and steps work

Learn more →
Read more
Quickstart

Trace your first turn and read it back

Learn more →
Read more
Agent integration

Trace agents built with LangGraph, the OpenAI Agents SDK, and more

Learn more →
Read more

Why use Lens?

  • See why an agent answered the way it did: Compare what each source returned with what entered the prompt, turn by turn.
  • Iris services trace themselves: Agent Memory, Agent Playbooks, and Context Gateway calls appear in the turn with no extra code.
  • Model calls traced automatically: Calls through OpenAI, Anthropic, Amazon Bedrock, and LangChain clients appear with their prompts, completions, and token counts.
  • Built on OpenTelemetry: Lens joins the tracer your application already uses, and Iris service steps reach your existing observability tools as well.
  • You control content capture: Capture prompts and retrieved text for debugging, or keep only IDs, hashes, and counts.
  • Background export: Lens exports in the background, so your agent never waits for it. If an export fails, the error stays out of your agent's code.

Concepts

Lens groups turns into sessions by agent, and records each turn's steps. See Lens concepts.

  1. Your agent opens a turn for each message with the Redis Iris software development kit (SDK).
  2. The SDK records each step in the turn: retrievals, memory recalls, prompt assembly, model calls, tool calls, and Iris service calls.
  3. Lens assembles the turn and groups it into sessions by agent.
  4. You inspect the turn in the Lens user interface (UI) or query it with the read application programming interface (API).
Your agent sends its turns to Lens through the Redis Iris SDK, and the Iris services it calls record their own steps in the same turn. You inspect sessions in the Lens UI or query turns with the read API.

Quick example

  1. Set up a Lens instance and get its endpoints and keys:

  2. Install the Redis Iris Python package:

    pip install 'redis-iris[llm-tracing]>=1.0.0'
    
  3. With IRIS_LENS_ENDPOINT, IRIS_LENS_API_KEY, and IRIS_LENS_AGENT_ID in your environment, trace a turn. The example calls OpenAI; use any supported client.

import uuid

from openai import OpenAI
from redis_iris import lens

lens.init()
client = OpenAI()

session_id = f"quickstart-{uuid.uuid4().hex[:8]}"

with lens.turn(session_id, user_id="user-1042") as turn:
    response = client.responses.create(
        model="gpt-4.1-mini",
        input="Where can I see my refund status?",
    )
    print(response.output_text)
    turn.set_outcome("completed")

turn_id = turn.trace_id
print(f"Session: {session_id}")
print(f"Turn: {turn_id}")

Follow the quickstart to read the turn back.

Use Lens

RATE THIS PAGE
Back to top ↑