-
Notifications
You must be signed in to change notification settings - Fork 232
docs(agentic-trust): Analyze AI agents guide #8383
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
2a86e35
101dfa0
882fa0d
aa12f95
8937c80
72fa586
112e3af
774245f
286da22
3f204a8
86fa46f
ada3cb8
3eb7235
211f922
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,178 @@ | ||
| --- | ||
| id: analyze-ai-agents | ||
| title: Analyze your AI agents with Optimize | ||
| sidebar_label: Analyze your AI agents | ||
| description: "Analyze and improve the performance of your AI agent executions using Optimize." | ||
| keywords: ["agentic ai", "AI agents", "Optimize"] | ||
| --- | ||
|
|
||
| import ScriptTask from './img/script-task.png'; | ||
| import Heatmap from './img/heatmap.png'; | ||
| import PieChart from './img/pie-chart.png'; | ||
| import Dashboard from './img/dashboard-optimize.png'; | ||
|
|
||
| Analyze and improve the performance of your AI agent executions using Optimize. | ||
|
|
||
| ## About | ||
|
|
||
| In this guide, you will: | ||
|
|
||
| - Understand what data Optimize can analyze for AI agents. | ||
| - Create reports and heatmaps, including token and tool usage. | ||
| - Build a dashboard to track AI agent behavior over time. | ||
|
|
||
| After completing this guide, you will be able to analyze AI agent executions in Optimize and build dashboards that track usage and performance trends. | ||
|
|
||
| ## Prerequisites | ||
|
|
||
| - You have access to [Optimize](/components/optimize/what-is-optimize.md). | ||
| - You have deployed and run the [AI Agent Chat Quick Start](https://marketplace.camunda.com/en-US/apps/587865) model blueprint. This is needed for Optimize to fetch execution data to analyze. Consider running it using different prompts to trigger various AI agent tools. | ||
|
|
||
| :::important | ||
| This guide is a follow-up to [Build your first AI agent](../../guides/getting-started-agentic-orchestration.md), in which you use the same example AI agent process. We recommend completing that guide first. However, you can also apply this guide to other AI agent process implementations. | ||
| ::: | ||
|
|
||
| ## Step 1: Make your data available | ||
|
|
||
| To make data available to Optimize, make sure it's scoped at the process level. If it's scoped to a lower level, for example, within a connector or tool-execution scope, extract it into process variables. | ||
|
|
||
| :::important | ||
| Optimize can only use variable data at the **process level**. | ||
| ::: | ||
|
|
||
| ### Example: Collect token usage | ||
|
|
||
| In the AI Agent Chat Quick Start example, token usage data is not available at the process level, but in a nested scope. To surface those metrics, you can add a script task after the AI agent execution that copies those values into process variables. | ||
|
|
||
| How you extract these values depends on how your AI agent implementation exposes token usage. The important aspect is that the target variables exist at the **process level** when the instance finishes. | ||
|
|
||
| To do so: | ||
|
|
||
| 1. Add a [script task](/components/modeler/bpmn/script-tasks/script-tasks.md). | ||
| 1. Configure its **Properties** as follows: | ||
| - In **General**, **Name**: Gather metrics. | ||
| - In **Implementation**, select **FEEL expression**. | ||
| - In **Script**, | ||
| - **Result variable**: `tokenUsage`. | ||
| - **FEEL expression**: `agent.context.metrics.tokenUsage.inputTokenCount`. | ||
| - In **Output mapping**, add two process variables: | ||
| - `inputTokenUsage` with **Variable assignment value**: `agent.context.metrics.tokenUsage.inputTokenCount`. | ||
| - `outputTokenUsage` with **Variable assignment value**: `agent.context.metrics.tokenUsage.outputTokenCount`. | ||
|
Comment on lines
+55
to
+60
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Disclaimer: I don't know much about Optimize, so I might miss something here. I'm not sure if I completely understand why we refer to Could we potentially create a result variable
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
|
||
| You should see something like the following: | ||
|
|
||
| <img src={ScriptTask} alt="Script task configuration for collecting token usage"/> | ||
|
|
||
| ## Step 2: Examine data in Optimize | ||
|
|
||
| By leveraging data collected during process execution, you can use Optimize to examine it through reports and dashboards and identify areas for improvement in your AI agent processes. | ||
|
|
||
| 1. Open Optimize. | ||
| 1. Go to the **Dashboards** tab. | ||
| 1. Select your AI agent process, **AI Agent Chat With Tools**, in the **Process dashboards and KPIs** section. | ||
| 1. Verify that Optimize shows data for your executed process instances in the **Business Operations** section, including your AI agent process model diagram and other statistics below. | ||
| 1. Explore the other metrics shown below in the **Business Reporting** and **Process Improvement** sections. | ||
|
|
||
| See the Optimize [getting started](/components/optimize/improve-processes-with-optimize.md) guide for more details on what you can do with Optimize for business intelligence. | ||
|
|
||
| ## Step 3: Create reports for token usage | ||
|
|
||
| You can create reports for token usage across process instances and over time. | ||
|
|
||
| To do so: | ||
|
|
||
| 1. Go to the **Collections** tab. | ||
| 1. Select **Report** from the **Create new** dropdown. | ||
| 1. Select **AI Agent Chat With Tools** from the **Select one or more processes** dropdown. You can fetch data for all process model versions or customize it. | ||
| 1. Choose a blank template. | ||
| 1. Enable **Update preview automatically** to make it easier to see the report results as you configure it. | ||
| 1. In the **Report setup** section, select **Variable** in the **View** option, and then select **tokenUsage**. | ||
| 1. Click the pencil icon and select an aggregation that matches your goal. For example: | ||
| - **Sum** to track total tokens across instances. | ||
| - **Average** to track typical usage per process instance. | ||
| 1. Save the report with a descriptive name. For example, **Token usage**. | ||
|
|
||
| :::note | ||
| You can create similar reports, targeting other goals and process variables, such as `inputTokenUsage` or `outputTokenUsage`. | ||
| ::: | ||
|
|
||
| ### Example: Set a target threshold | ||
|
|
||
| If you have a token budget, you can set a target in the report. | ||
|
|
||
| 1. Follow [the previous steps 1 through 6](#step-3-create-reports-for-token-usage). | ||
| 1. In the **Visualization** settings, click the gear icon, and then enable **Set target** to configure a target value, for example, a maximum token usage threshold. | ||
| 1. Set the target to less than 10,000 tokens. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If Optimize uses a specific target operator or threshold mode here, we could consider naming it explicitly instead of implying "less than" behavior but I'm not sure of the mechanics here -- like would "Set the target to 10,000 tokens or to the threshold that matches your budget." even really work? Feel free to disregard but just a thought. |
||
| 1. Save the report with a descriptive name. For example, **Token usage with threshold**. | ||
|
|
||
| ## Step 4: Create reports for tool usage | ||
|
|
||
| You can create reports for tool usage across process instances and over time. | ||
|
|
||
| ### Example: Create a heatmap | ||
|
|
||
| Use a heatmap to understand how long your AI agent spends in each task. | ||
|
|
||
| 1. Go to the **Collections** tab. | ||
| 1. Select **Report** from the **Create new** dropdown. | ||
| 1. Select **Flow node** as the **View**. | ||
| 1. Select **Duration** as the **Measure**. | ||
| 1. (Optional) Filter the report by selecting **Flow node selection** in the **Filter flow nodes** dropdown. For example, select only tool tasks within the AI Agent connector. | ||
| 1. In the **Visualization** settings, select **Heatmap**. Then click the gear icon and enable the tooltip to show absolute values. | ||
| 1. Save the report with a descriptive name. For example, **Tool usage heatmap**. | ||
|
|
||
| <p align="center"> | ||
| <img src={Heatmap} alt="Tool usage heatmap" width="80%"/> | ||
| </p> | ||
|
|
||
| ### Example: Create a report for tool call counts | ||
|
|
||
| Create a bar chart to see how many times each tool is called. | ||
|
|
||
| 1. Go to the **Collections** tab. | ||
| 1. Select **Report** from the **Create new** dropdown. | ||
| 1. Select **Flow node** as **View**. | ||
| 1. Select **Count** as the **Measure**. | ||
| 1. (Optional) Filter the report by selecting **Flow node selection** in the **Filter flow nodes** dropdown. For example, select only tool tasks within the AI Agent connector. | ||
| 1. In the **Visualization** settings, select **Bar chart** or **Pie chart**. Then click the gear icon and enable both tooltips to show absolute and relative values. | ||
| 1. Save the report with a descriptive name. For example, **Tool usage**. | ||
|
|
||
| <p align="center"> | ||
| <img src={PieChart} alt="Tool usage pie chart" width="50%"/> | ||
| </p> | ||
|
|
||
| ### Example: Track trends over time | ||
|
|
||
| Use a timeline report to analyze trends over time. For example, you can see how many times a tool is called per day over a one-week period. | ||
|
|
||
| 1. Go to the **Collections** tab. | ||
| 1. Select **Report** from the **Create new** dropdown. | ||
| 1. Select **Flow node** as **View**. | ||
| 1. Select **Count** as the **Measure**. | ||
| 1. In **Group by**, select **Start date**. Then choose your preferred interval, for example, **Week**. | ||
| 1. (Optional) Filter the report by selecting **Flow node selection** in the **Filter flow nodes** dropdown. For example, select only tool tasks within the AI Agent connector. | ||
| 1. In the **Visualization** settings, select **Bar chart** or **Line chart**. Then click the gear icon and enable both tooltips to show absolute and relative values. | ||
| 1. Save the report with a descriptive name. For example, **Tool usage over time**. | ||
|
|
||
| ## Step 5: Build a dashboard | ||
|
|
||
| You can create a dashboard, which is a collection of reports that you can view together, for your AI agent process. | ||
| To do so: | ||
|
|
||
| 1. Go to the **Collections** tab. | ||
| 1. Select **Dashboard** from the **Create new** dropdown. | ||
| 1. Click the plus icon to add tiles for the reports you created. | ||
| 1. In the **Optimize report** section, add reports as needed. | ||
| 1. Arrange the tiles to customize your dashboard layout. | ||
| 1. Save the dashboard with a descriptive name. For example, **AI Agent Chat Quick Start dashboard**. | ||
|
|
||
| <p align="center"> | ||
| <img src={Dashboard} alt="Dashboard overview" width="80%"/> | ||
| </p> | ||
|
|
||
| ## Next steps | ||
|
|
||
| Now that you know how to analyze your AI agents, you can: | ||
|
|
||
| - [Monitor your AI agents](/components/agentic-orchestration/monitor-ai-agents.md) with Operate. | ||
| - Learn more about [Camunda agentic orchestration](/components/agentic-orchestration/agentic-orchestration-overview.md) and the [AI Agent connector](/components/connectors/out-of-the-box-connectors/agentic-ai-aiagent.md). | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Getting the token counts from the agent context only works with the AI Agent Process when the "Include agent context" option is enabled, because otherwise the context won't be part of the agent response - should we mention this somewhere?