You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/platforms/python/tracing/instrumentation/custom-instrumentation/agents-module.mdx
+97-34Lines changed: 97 additions & 34 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,22 +4,87 @@ sidebar_order: 500
4
4
description: "Learn how to manually instrument your code to use Sentry's Agents module."
5
5
---
6
6
7
-
As a prerequisite to setting up [AI Agents](/product/insights/agents/), you’ll need to first <PlatformLinkto="/tracing/">set up tracing</PlatformLink>. Once this is done, the Python SDK will automatically instrument AI agents created with the `openai-agents` library. If that doesn't fit your use case, you can set up using custom instrumentation described below.
7
+
As a prerequisite to setting up [AI Agents](https://sentry.io/orgredirect/organizations/:orgslug/insights/agents/), you’ll need to first <PlatformLinkto="/tracing/">set up tracing</PlatformLink>. Once this is done, the Python SDK will automatically instrument AI agents created with the `openai-agents` library. If that doesn't fit your use case, you can set up using custom instrumentation described below.
8
8
9
9
## Custom Instrumentation
10
10
11
-
For your AI agents data to show up in the Sentry Agents Insights Module a couple of different spans can be created. Those spans need to have well defined names and attributes.
11
+
For your AI agents data to show up in the Sentry Agents Insights Module a couple of different spans must be created. Those spans need to have well defined names and attributes.
12
12
13
-
### Common Span Attributes
13
+
## Span Types
14
+
15
+
### Invoke Agent Span
16
+
17
+
Describes AI agent invocation.
18
+
19
+
- The spans `op` MUST be `"gen_ai.invoke_agent"`.
20
+
- The span `name` MUST be `"invoke_agent {gen_ai.agent.name}"`.
21
+
- The `gen_ai.operation.name` attribute MUST be `"invoke_agent"`.
22
+
- The `gen_ai.agent.name` attribute SHOULD be set to the agents name. (e.g. `"Weather Agent"`)
23
+
24
+
### Execute Tool Span
25
+
26
+
Describes tool execution span.
27
+
28
+
- The spans `op` MUST be `"gen_ai.execute_tool"`.
29
+
- The spans `name` MUST be `"gen_ai.execute_tool {gen_ai.tool.name}"`. (e.g. `"gen_ai.execute_tool query_database"`)
30
+
- The `gen_ai.tool.name` attribute SHOULD be set to the name of the tool. (e.g. `"query_database"`)
31
+
32
+
Additional attributes on the span:
33
+
34
+
| Data Attribute | Type | Requirement Level | Description | Example |
|`gen_ai.request.available_tools`| string | optional | List of objects describing the available tools. **[0]**|`"[{\"name\": \"random_number\", \"description\": \"...\"}, {\"name\": \"query_db\", \"description\": \"...\"}]"`|
61
+
|`gen_ai.request.frequency_penalty`| float | optional | Model configuration parameter. |`0.5`|
62
+
|`gen_ai.request.max_tokens`| int | optional | Model configuration parameter. |`500`|
63
+
|`gen_ai.request.messages`| string | optional | List of objects describing the messages (prompts) sent to the LLM **[0]**, **[1]**|`"[{\"role\": \"system\", \"content\": [{...}]}, {\"role\": \"system\", \"content\": [{...}]}]"`|
64
+
|`gen_ai.request.presence_penalty`| float | optional | Model configuration parameter. |`0.5`|
65
+
|`gen_ai.request.temperature`| float | optional | Model configuration parameter. |`0.1`|
66
+
|`gen_ai.request.top_p`| float | optional | Model configuration parameter. |`0.7`|
67
+
|`gen_ai.response.tool_calls`| string | optional | The tool calls in the model’s response. **[0]**|`"[{\"name\": \"random_number\", \"type\": \"function_call\", \"arguments\": \"...\"}]"`|
68
+
|`gen_ai.response.text`| string | optional | The text representation of the model’s responses. **[0]**|`"[\"The weather in Paris is rainy\", \"The weather in London is sunny\"]"`|
69
+
|`gen_ai.usage.input_tokens.cached`| int | optional | The number of cached tokens used in the AI input (prompt) |`50`|
70
+
|`gen_ai.usage.input_tokens`| int | optional | The number of tokens used in the AI input (prompt). |`10`|
71
+
|`gen_ai.usage.output_tokens.reasoning`| int | optional | The number of tokens used for reasoning. |`30`|
72
+
|`gen_ai.usage.output_tokens`| int | optional | The number of tokens used in the AI response. |`100`|
73
+
|`gen_ai.usage.total_tokens`| int | optional | The total number of tokens used to process the prompt. (input and output) |`190`|
74
+
75
+
-**[0]:** As span attributes only allow primitive data types this needs to be a stringified version of a list of dictionaries. Do NOT set `[{"foo": "bar"}]` but rather the string `"[{\"foo\": \"bar\"}]"`.
76
+
-**[1]:** Each item in the list has the format `{role:"", content:""}` where `role` can be `"user"`, `"assistant"`, or `"system"` and `content` can either be a string or a list of dictionaries.
77
+
78
+
## Common Span Attributes
14
79
15
80
Some attributes are common to all types of AI Agents spans:
0 commit comments