Instrument generative AI applications

This document describes the benefit of instrumenting your generative AI applications. It also summarizes how you can instrument an application that uses the LangGraph framework.

About generative AI agents

Applications that use generative AI rely on agents to complete tasks or achieve goals. Agents are applications that complete tasks or pursue goals on behalf of a user. For example, a generative AI agent can navigate a website and issue API commands. These API commands might retrieve information or perform an action.

Agents act autonomously and they use reasoning to determine how to decompose a goal or task into subtasks, and then to determine which tools to use to accomplish those subtasks. In the context of generative AI, tools determine how the agent can interact with its environment. For example, an agent might have a tool that lets it issue API commands.

To learn more about agents, see the following:

Why instrument your generative AI applications

Instrumenting your generative AI applications is the only way you can understand the reasoning used by the autonomous agents. This reasoning process isn't deterministic.

When you instrument a generative AI application, the telemetry data includes the decisions and actions of the agents. You can use this data to validate or improve your application.

How to instrument your generative AI applications

Instrumenting your application involves generating telemetry and sending it to where the data can be stored and queried and analyzed. For example, when your instrumentation sends telemetry to your Google Cloud project, you can use Google Cloud Observability to view and analyze that data.

The LangGraph framework example illustrates how to use OpenTelemetry to instrument a generative AI application that uses the LangChain or LangGraph framework.

  • OpenTelemetry is an open source project that provides a unified framework for application instrumentation.

  • An agent framework provides the infrastructure needed to develop a generative AI application. Agent frameworks define how to create and register tools, how to select a tool to run, and how to run the tool.

Cloud Trace is configured to extract events from spans written by generative AI applications, provided the spans conform to the OpenTelemetry Semantic conventions for generative AI spans and include attributes or events that follow the Semantic conventions for generative AI events.