|
| 1 | +--- |
| 2 | +title: Observability |
| 3 | +description: Trace CUA execution steps and sessions |
| 4 | +--- |
| 5 | + |
| 6 | +## Observability |
| 7 | + |
| 8 | +CUA has a native integration with [Laminar](https://laminar.sh/) – open-source platform for tracing, evals, and labeling of autonomous AI agents. Read more about Laminar in the [Laminar docs](https://docs.lmnr.ai/). |
| 9 | + |
| 10 | +## Setup |
| 11 | + |
| 12 | +Register on [Laminar Cloud](https://laminar.sh/) or spin up a [local instance](https://github.com/lmnr-ai/lmnr) and get the key from your project settings. Set the `LMNR_PROJECT_API_KEY` environment variable to your key. |
| 13 | + |
| 14 | +```bash |
| 15 | +pip install lmnr[all] |
| 16 | +export LMNR_PROJECT_API_KEY=your-key |
| 17 | +``` |
| 18 | + |
| 19 | +## Usage |
| 20 | + |
| 21 | +Then, initialize Laminar at the entry point of your application, register Laminar LiteLLM callback, and all steps of CUA will be automatically traced. |
| 22 | + |
| 23 | +```python |
| 24 | +import os |
| 25 | + |
| 26 | +import litellm |
| 27 | + |
| 28 | +from agent import ComputerAgent |
| 29 | +from computer import Computer |
| 30 | +from lmnr import Laminar, LaminarLiteLLMCallback # [!code highlight] |
| 31 | + |
| 32 | +Laminar.initialize() # [!code highlight] |
| 33 | +litellm.callbacks.append(LaminarLiteLLMCallback()) # [!code highlight] |
| 34 | + |
| 35 | +computer = Computer( |
| 36 | + os_type="linux", |
| 37 | + provider_type="cloud", |
| 38 | + name=os.getenv("CUA_CONTAINER_NAME"), |
| 39 | + api_key=os.getenv("CUA_API_KEY"), |
| 40 | +) |
| 41 | + |
| 42 | +agent = ComputerAgent( |
| 43 | + model="openai/computer-use-preview", |
| 44 | + tools=[computer], |
| 45 | +) |
| 46 | + |
| 47 | +async def main(): |
| 48 | + async for step in agent.run("Create a new file called 'test.txt' in the current directory"): |
| 49 | + print(step["output"]) |
| 50 | + |
| 51 | +if __name__ == "__main__": |
| 52 | + asyncio.run(main()) |
| 53 | +``` |
| 54 | + |
| 55 | +## Viewing traces |
| 56 | + |
| 57 | +You can view traces in the Laminar UI by going to the traces tab in your project. When you select a trace, |
| 58 | +you will see all the agent execution steps, including computer actions, LLM calls, and screenshots. |
| 59 | + |
| 60 | +For each step, you will see the LLM call, the computer action. The computer actions are highlighted in the timeline in yellow. |
| 61 | + |
| 62 | +<img src="/docs/img/laminar_trace_example.png" alt="Example trace in Laminar showing the litellm.response span and its output." width="800px" /> |
0 commit comments