Install
LangChain integration
pip install nexus-library[langchain]
OpenAI Agents SDK integration
pip install nexus-library[openai]
Get your Nexus API key
Create or sign in to the Nexus platform and copy your nexus_api_key:
In examples below, nexus_key means your nexus_api_key.
Run your first manual trace
The source tree exports NexusClient from nexus_library.nexus_core.
from nexus_library.nexus_core import NexusClient
nexus_key = "your_nexus_api_key"
client = NexusClient( api_key = nexus_key)
with client.span( "root-workflow" , event_type = "chain" , input_data = { "question" : "What is Nexus?" }) as root:
with client.span( "lookup-tool" , event_type = "tool" , input_data = { "query" : "nexus-library" }) as tool_span:
tool_span.set_output({ "result" : "Tracing library for AI systems" })
root.set_output({ "status" : "ok" })
client.flush()
Add LangChain callback tracing
from nexus_library.nexus_core import NexusClient
from nexus_library.langchain import LangHandler
nexus_key = "your_nexus_api_key"
nexus_client = NexusClient( api_key = nexus_key)
callback_handler = LangHandler(nexus_client)
# Attach `callback_handler` to your LangChain runnable / agent callbacks
Add OpenAI Agents SDK tracing
import asyncio
import os
from agents import Agent, Runner, set_trace_processors
from nexus_library.nexus_core import NexusClient
from nexus_library.openai import NexusOpenAITracingProcessor
nexus_client = NexusClient( api_key = os.environ[ "NEXUS_API_KEY" ])
dev_mode = os.getenv( "NEXUS_DEV_MODE" , "false" ).lower() == "true"
tracing_processor = NexusOpenAITracingProcessor(nexus_client, dev_mode = dev_mode)
set_trace_processors([tracing_processor])
async def main ():
agent = Agent( name = "my-agent" , instructions = "You are a helpful assistant." )
result = await Runner.run(agent, "Hello!" )
print (result.final_output)
asyncio.run(main())
Set NEXUS_DEV_MODE=true locally to disable external triggers. Set it to false (or omit it) in production.
Verify the trace exists
After your run finishes:
use client.get_all_events() to fetch stored rows
use client.print_tree_structure() to inspect hierarchy in terminal
use client.get_trace_tree_string() to get an LLM-readable tree dump
Next steps
Manual tracing guide Deep dive into span nesting and flush semantics.
LangChain guide Understand callback lifecycle and event categories.
OpenAI Agents SDK guide Trace OpenAI agents with NexusOpenAITracingProcessor.
Configuration Set DB URLs and trigger endpoints safely.
Python reference Review method-level behavior for NexusClient.
nexus_key should be your Nexus platform nexus_api_key. Keep it secret and load it from environment variables in production.