For AI agents: a documentation index is available at the root level at /llms.txt and /llms-full.txt. Append /llms.txt to any URL for a page-level index, or .md for the markdown version of any page.
Copy to LLMGithubGo to App
DocumentationIntegrationsBuilding Self-Improving AgentsSelf-hosting OpikSDK & API reference
DocumentationIntegrationsBuilding Self-Improving AgentsSelf-hosting OpikSDK & API reference
    • Overview
  • TypeScript
    • Opik TypeScript SDK
  • Python
      • AG2
      • Agent Spec
      • Agno
      • BeeAI
      • Claude Agent SDK
      • Autogen
      • CrewAI
      • DSPy
      • Google ADK
      • Haystack
      • Harbor
      • Instructor
      • LangChain
      • LangGraph
      • LangServe
      • LiveKit Agents
      • Llama Index
      • Microsoft Agent Framework
      • OpenAI Agents
      • Pipecat
      • Pydantic AI
      • Semantic Kernel
      • Smolagents
      • Strands Agents
      • Temporal
      • VoltAgent
    • Opik Python SDK
    • OpenTelemetry Python SDK
  • Java
    • Spring AI
    • Quarkus LangChain4j
  • .NET
  • Ruby
    • OpenTelemetry Ruby SDK
  • No-Code
    • Cursor
    • Dify
    • Flowise
    • Langflow
    • n8n
    • OpenClaw
    • OpenAI Codex
    • OpenWebUI
    • Prompt Flow
  • Multi-Language
    • OpenTelemetry
LogoLogo
Copy to LLMGithubGo to App
On this page
  • Account Setup
  • Getting Started
  • Installation
  • Configuring Opik
  • Configuring your LLM provider
  • Tracing Agent Spec workflows with Opik
  • Further improvements
PythonFrameworks

Observability for Agent Spec with Opik

Was this page helpful?
Previous

Observability for Agno with Opik

Next
Built with

Open Agent Specification is a portable configuration language for defining agentic systems (agents, tools, and structured workflows).

Agent Spec Tracing is an extension of Agent Spec that standardizes how agent and flow executions emit traces. This makes it easier to analyze what happened (LLM calls, tool calls, and intermediate steps) across different runtimes and adapters.

Account Setup

Comet provides a hosted version of the Opik platform, simply create an account and grab your API Key.

You can also run the Opik platform locally, see the installation guide for more information.

Getting Started

Installation

To use Agent Spec with Opik, install opik and pyagentspec:

$pip install -U opik pyagentspec opentelemetry-sdk opentelemetry-instrumentation

If you are using the LangGraph adapter (as in the example below), install the LangGraph extra as well:

$pip install -U "pyagentspec[langgraph]"

If you are using another framework, you can install the respective extra for pyagentspec, according to the installation instructions.

Configuring Opik

Configure the Opik Python SDK for your deployment type. See the Python SDK Configuration guide for detailed instructions on:

  • CLI configuration: opik configure
  • Code configuration: opik.configure()
  • Self-hosted vs Cloud vs Enterprise setup
  • Configuration files and environment variables

Configuring your LLM provider

In order to run the example below, you will need to configure your LLM provider API keys. For this example, we’ll use OpenAI. You can find or create your API keys in these pages:

You can set them as environment variables:

$export OPENAI_API_KEY="YOUR_API_KEY"

Or set them programmatically:

1import os
2import getpass
3
4if "OPENAI_API_KEY" not in os.environ:
5 os.environ["OPENAI_API_KEY"] = getpass.getpass("Enter your OpenAI API key: ")

Tracing Agent Spec workflows with Opik

Opik provides an AgentSpecInstrumentor that connects Agent Spec Tracing to Opik. Wrap your Agent Spec runtime execution in the instrumentor context to capture traces.

1import asyncio
2import uuid
3
4from pyagentspec.agent import Agent
5from pyagentspec.llms import OpenAiConfig
6from pyagentspec.property import FloatProperty
7from pyagentspec.tools import ServerTool
8
9
10def build_agentspec_agent() -> Agent:
11 tools = [
12 ServerTool(
13 name="sum",
14 description="Sum two numbers",
15 inputs=[FloatProperty(title="a"), FloatProperty(title="b")],
16 outputs=[FloatProperty(title="result")],
17 ),
18 ServerTool(
19 name="subtract",
20 description="Subtract two numbers",
21 inputs=[FloatProperty(title="a"), FloatProperty(title="b")],
22 outputs=[FloatProperty(title="result")],
23 ),
24 ]
25
26 return Agent(
27 name="calculator_agent",
28 description="An agent that provides assistance with tool use.",
29 llm_config=OpenAiConfig(name="openai-gpt-5-mini", model_id="gpt-5-mini"),
30 system_prompt=(
31 "You are a helpful calculator agent.\n"
32 "Your duty is to compute the result of the given operation using tools, "
33 "and to output the result.\n"
34 "It's important that you reply with the result only.\n"
35 ),
36 tools=tools,
37 )
38
39
40async def main():
41 from opik.integrations.agentspec import AgentSpecInstrumentor
42 from pyagentspec.adapters.langgraph import AgentSpecLoader
43
44 agent = build_agentspec_agent()
45 tool_registry = {
46 "sum": lambda a, b: a + b,
47 "subtract": lambda a, b: a - b,
48 }
49
50 langgraph_agent = AgentSpecLoader(tool_registry=tool_registry).load_component(agent)
51
52 # Each conversation turn gets its own Opik trace; thread_id groups them into a session.
53 thread_id = str(uuid.uuid4())
54 messages = []
55 while True:
56 user_input = input("USER >>> ")
57 if user_input.lower() in ["exit", "quit"]:
58 break
59 messages.append({"role": "user", "content": user_input})
60
61 with AgentSpecInstrumentor().instrument_context(
62 project_name="agentspec-demo",
63 mask_sensitive_information=False,
64 thread_id=thread_id,
65 ):
66 response = langgraph_agent.invoke(
67 input={"messages": messages},
68 config={"configurable": {"thread_id": "1"}},
69 )
70
71 agent_answer = response["messages"][-1].content.strip()
72 print("AGENT >>>", agent_answer)
73 messages.append({"role": "assistant", "content": agent_answer})
74
75
76if __name__ == "__main__":
77 asyncio.run(main())

Agent Spec traces often include prompts, tool inputs/outputs, and messages. If you need to avoid logging sensitive information, set mask_sensitive_information=True.

Once you run the script and interact with your agent, you can inspect the trace tree in Opik to debug tool usage, LLM generations, and intermediate steps.

Further improvements

If you would like to see us improve this integration, simply open a new feature request on Github.