AgentSpec (tracing)

Open Agent Specification (Agent Spec) (pyagentspec) is Oracle’s open specification and Python SDK for defining and running agentic systems. It provides a portable way to describe agents, models, and workflows across runtimes. Respan gives you full observability over every spec execution, model call, and tool invocation — and gateway routing through the OpenAI-compatible Respan endpoint.

Create an account at platform.respan.ai and grab an API key.

Run npx @respan/cli setup to set up with your coding agent.

See AgentSpec gateway setup to route this integration through the Respan gateway.

Setup

1

Install packages

$pip install respan-ai respan-instrumentation-agentspec "pyagentspec[langgraph]"
2

Set environment variables

$export OPENAI_API_KEY="YOUR_OPENAI_API_KEY"
$export RESPAN_API_KEY="YOUR_RESPAN_API_KEY"

OPENAI_API_KEY is used for LLM requests. RESPAN_API_KEY is used to export traces to Respan.

3

Initialize and run

1from pyagentspec.adapters.langgraph import AgentSpecLoader
2from pyagentspec.agent import Agent
3from pyagentspec.llms import OpenAiConfig
4from respan import Respan
5from respan_instrumentation_agentspec import AgentSpecInstrumentor
6
7respan = Respan(
8 app_name="agentspec-haiku-agent",
9 instrumentations=[
10 AgentSpecInstrumentor(workflow_name="agentspec_haiku_agent")
11 ],
12)
13
14try:
15 agent = Agent(
16 name="haiku_assistant",
17 description="A helpful assistant that writes haikus.",
18 llm_config=OpenAiConfig(name="openai", model_id="gpt-4.1-nano"),
19 system_prompt="You are a helpful assistant. Respond only with a haiku.",
20 )
21
22 langgraph_agent = AgentSpecLoader().load_component(agent)
23
24 result = langgraph_agent.invoke(
25 input={"messages": [{"role": "user", "content": "Write a haiku about recursion."}]}
26 )
27 print(result["messages"][-1].content)
28finally:
29 respan.shutdown()
30 respan.flush()
4

View your trace

Open the Traces page to see your AgentSpec workflow with specification execution, tool calls, and LLM generations.

Configuration

ParameterTypeDefaultDescription
api_keystr | NoneNoneFalls back to RESPAN_API_KEY env var.
base_urlstr | NoneNoneFalls back to RESPAN_BASE_URL env var.
instrumentationslist[]Plugin instrumentations to activate (e.g. AgentSpecInstrumentor()).
customer_identifierstr | NoneNoneDefault customer identifier for all spans.
metadatadict | NoneNoneDefault metadata attached to all spans.
environmentstr | NoneNoneEnvironment tag (e.g. "production").

AgentSpecInstrumentor(workflow_name="...") sets the Respan workflow name and the root AgentSpec trace span name, making each run easy to identify in the Traces page.

Attributes

In Respan()

Set defaults at initialization — these apply to all spans.

1from respan import Respan
2from respan_instrumentation_agentspec import AgentSpecInstrumentor
3
4respan = Respan(
5 instrumentations=[
6 AgentSpecInstrumentor(workflow_name="agentspec_support_request")
7 ],
8 customer_identifier="user_123",
9 metadata={"service": "agentspec-api", "version": "1.0.0"},
10)

With propagate_attributes

Override per-request using a context scope.

1from respan import Respan, propagate_attributes
2from respan_instrumentation_agentspec import AgentSpecInstrumentor
3
4respan = Respan(
5 instrumentations=[
6 AgentSpecInstrumentor(workflow_name="agentspec_support_request")
7 ],
8)
9
10def handle_request(user_id: str, message: str):
11 with propagate_attributes(
12 customer_identifier=user_id,
13 thread_identifier="conv_abc_123",
14 metadata={"plan": "pro"},
15 ):
16 result = langgraph_agent.invoke(
17 input={"messages": [{"role": "user", "content": message}]}
18 )
19 print(result["messages"][-1].content)
AttributeTypeDescription
customer_identifierstrIdentifies the end user in Respan analytics.
thread_identifierstrGroups related messages into a conversation.
metadatadictCustom key-value pairs. Merged with default metadata.