diff --git a/docs/ai/monitoring/agents/naming.mdx b/docs/ai/monitoring/agents/naming.mdx index 0aebb89eca905..bb3efd9aee968 100644 --- a/docs/ai/monitoring/agents/naming.mdx +++ b/docs/ai/monitoring/agents/naming.mdx @@ -14,18 +14,18 @@ Sentry uses the `gen_ai.agent.name` span attribute to identify agents in the [AI ## Quick Reference -| Framework | Platform | How to Name | -| ----------------------- | -------- | ------------------------------------------------------------------ | -| OpenAI Agents SDK | Python | `Agent(name="...")` | -| Pydantic AI | Python | `Agent(..., name="...")` | -| LangChain | Python | `create_agent(model, tools, name="...")` | -| LangGraph | Python | `.compile(name="...")` or `create_react_agent(..., name="...")` | -| Vercel AI SDK | JS | `experimental_telemetry: { functionId: "..." }` | -| LangGraph | JS | `.compile({ name: "..." })` or `createReactAgent({ name: "..." })` | -| LangChain | JS | `createAgent({ name: "..." })` | -| Mastra | JS | `Agent({ id: "...", name: "..." })` | -| .NET (M.E.AI) | .NET | `options.Experimental.AgentName = "..."` | -| Other / raw LLM clients | Any | [Manual instrumentation](#manual-instrumentation) | +| Framework | Platform | How to Name | +| ----------------------- | -------- | ------------------------------------------------------------------------------------ | +| OpenAI Agents SDK | Python | `Agent(name="...")` | +| Pydantic AI | Python | `Agent(..., name="...")` | +| LangChain | Python | `create_agent(model, tools, name="...")` | +| LangGraph | Python | `.compile(name="...")` or `create_react_agent(..., name="...")` | +| Vercel AI SDK | JS | `experimental_telemetry: { functionId: "..." }` on `generateText` or `ToolLoopAgent` | +| LangGraph | JS | `.compile({ name: "..." })` or `createReactAgent({ name: "..." })` | +| LangChain | JS | `createAgent({ name: "..." })` | +| Mastra | JS | `Agent({ id: "...", name: "..." })` | +| .NET (M.E.AI) | .NET | `options.Experimental.AgentName = "..."` | +| Other / raw LLM clients | Any | [Manual instrumentation](#manual-instrumentation) | ## Framework Integrations @@ -113,7 +113,7 @@ agent = create_react_agent(model, tools, name="dice_agent") #### Vercel AI SDK -Vercel AI SDK doesn't have a dedicated agent name field. Instead, set `functionId` in `experimental_telemetry` — Sentry uses this as the agent identifier. +Set `functionId` in `experimental_telemetry` — Sentry uses this as the agent identifier. This works for both `generateText` and `ToolLoopAgent`: ```javascript import { generateText } from "ai"; @@ -129,6 +129,24 @@ const result = await generateText({ }); ``` +For the `ToolLoopAgent` class, set `functionId` in the constructor: + +```javascript +import { ToolLoopAgent } from "ai"; +import { openai } from "@ai-sdk/openai"; + +const agent = new ToolLoopAgent({ + model: openai("gpt-4o"), + tools: { + /* ... */ + }, + experimental_telemetry: { + isEnabled: true, + functionId: "weather_agent", + }, +}); +``` + -To correctly capture spans, pass the `experimental_telemetry` object with `isEnabled: true` to every `generateText`, `generateObject`, and `streamText` function call. For more details, see the [AI SDK Telemetry Metadata docs](https://sdk.vercel.ai/docs/ai-sdk-core/telemetry#telemetry-metadata). +To correctly capture spans, pass the `experimental_telemetry` object with `isEnabled: true` to every `generateText`, `generateObject`, `streamText`, and `ToolLoopAgent` call. For more details, see the [AI SDK Telemetry Metadata docs](https://sdk.vercel.ai/docs/ai-sdk-core/telemetry#telemetry-metadata). ```javascript const result = await generateText({ @@ -160,6 +160,34 @@ Sentry.init({ +## ToolLoopAgent + +The integration also captures spans for the [`ToolLoopAgent`](https://ai-sdk.dev/docs/agents/overview#toolloopagent-class) class. Each call to `generate()` or `stream()` creates an agent span with individual LLM requests and tool executions as child spans. + + + +No additional configuration is needed — `ToolLoopAgent` spans are captured automatically. + + + + + +Pass `experimental_telemetry` with `isEnabled: true` to the `ToolLoopAgent` constructor to correctly capture spans: + + + +```javascript +const agent = new ToolLoopAgent({ + model: openai("gpt-4o"), + tools: { /* ... */ }, + experimental_telemetry: { isEnabled: true }, +}); + +const result = await agent.generate({ + prompt: "What is the weather in San Francisco?", +}); +``` + ## Identifying functions In order to make it easier to correlate captured spans with the function calls we recommend setting `functionId` in `experimental_telemetry` in all generation function calls: @@ -174,6 +202,19 @@ const result = await generateText({ }); ``` +For `ToolLoopAgent`, set `functionId` in the constructor: + +```javascript +const agent = new ToolLoopAgent({ + model: openai("gpt-4o"), + tools: { /* ... */ }, + experimental_telemetry: { + isEnabled: true, + functionId: "weather-agent", + }, +}); +``` + ## Configuration By default this integration adds tracing support to all `ai` function callsites. If you need to disable span collection for a specific call, you can do so by setting `experimental_telemetry.isEnabled` to `false` in the first argument of the function call.