Skip to content

Commit 7b695dc

Browse files
enystopenhands-agentxingyaoww
authored
examples: add Laminar observability example (#1131)
Co-authored-by: openhands <openhands@all-hands.dev> Co-authored-by: Xingyao Wang <xingyao@all-hands.dev>
1 parent a656ca7 commit 7b695dc

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
"""
2+
Observability & Laminar example
3+
4+
This example demonstrates enabling OpenTelemetry tracing with Laminar in the
5+
OpenHands SDK. Set LMNR_PROJECT_API_KEY and run the script to see traces.
6+
"""
7+
8+
import os
9+
10+
from pydantic import SecretStr
11+
12+
from openhands.sdk import LLM, Agent, Conversation, Tool
13+
from openhands.tools.terminal import TerminalTool
14+
15+
16+
# Tip: Set LMNR_PROJECT_API_KEY in your environment before running, e.g.:
17+
# export LMNR_PROJECT_API_KEY="your-laminar-api-key"
18+
# For non-Laminar OTLP backends, set OTEL_* variables instead.
19+
20+
# Configure LLM and Agent
21+
api_key = os.getenv("LLM_API_KEY")
22+
model = os.getenv("LLM_MODEL", "openhands/claude-sonnet-4-5-20250929")
23+
base_url = os.getenv("LLM_BASE_URL")
24+
llm = LLM(
25+
model=model,
26+
api_key=SecretStr(api_key) if api_key else None,
27+
base_url=base_url,
28+
usage_id="agent",
29+
)
30+
31+
agent = Agent(
32+
llm=llm,
33+
tools=[Tool(name=TerminalTool.name)],
34+
)
35+
36+
# Create conversation and run a simple task
37+
conversation = Conversation(agent=agent, workspace=".")
38+
conversation.send_message("List the files in the current directory and print them.")
39+
conversation.run()
40+
print(
41+
"All done! Check your Laminar dashboard for traces "
42+
"(session is the conversation UUID)."
43+
)

0 commit comments

Comments
 (0)