tencentcloud-agentobs-sdk-openai-agent to automatically collect Trace data from OpenAI Agents and report it to CLS (Cloud Log Service).Runner.run() or Runner.run_sync() invocation, as well as the parent-child relationships among Agents, inference turns, model calls, and tool calls.Access Method | Description | Recommended Scenario |
Use an AI tool that supports Skill to have AI create or reuse a log topic and complete SDK installation, configuration, and verification. | Prefer to minimize manual configuration and analyze Trace data through natural language after access. | |
Install the SDK, configure the CLS Endpoint, log topic, and access credentials, and call setup() in the code. | Requires fine-grained control over access parameters, or the tool in use does not support Skill. |
Region (such as ap-guangzhou) for method 1. For method 2, enter the domain name. The private network domain name is ap-guangzhou.cls.tencentyun.com, and the public network domain name is ap-guangzhou.cls.tencentcs.com.Use the Tencent Cloud Agent Observability Assistant Skill:https://skillhub.cn/skills/tencentcloud-cls-agent-obsHelp me integrate the current OpenAI Agent into Tencent Cloud Agent Observability.
Analyze the running status of this Agent over the last hour, and identify the model or tool calls with the highest latency, the highest Token consumption, and the most failures.
CLS_TOPIC_ID in subsequent configurations.pip install tencentcloud-agentobs-sdk-openai-agent
py -m pip install tencentcloud-agentobs-sdk-openai-agent
export CLS_ENDPOINT=ap-guangzhou.cls.tencentcs.comexport CLS_TOPIC_ID=your-topic-idexport CLS_SECRET_ID=your-secret-idexport CLS_SECRET_KEY=your-secret-keyexport OPENAI_API_KEY=sk-xxx
$env:CLS_ENDPOINT = "ap-guangzhou.cls.tencentcs.com"$env:CLS_TOPIC_ID = "your-topic-id"$env:CLS_SECRET_ID = "your-secret-id"$env:CLS_SECRET_KEY = "your-secret-key"$env:OPENAI_API_KEY = "sk-xxx"
Environment Variable | Required | Description |
CLS_ENDPOINT | Yes | CLS region Endpoint. The Endpoint and the Trace log topic must be in the same region. See Regions and Access Domain Names. For example, in the Guangzhou region, the private network domain name is ap-guangzhou.cls.tencentyun.com, and the public network domain name is ap-guangzhou.cls.tencentcs.com. |
CLS_TOPIC_ID | Yes | Trace log topic ID corresponding to the Agent observable application. Do not enter the application ID. |
CLS_SECRET_ID | Yes | Tencent Cloud access key ID. The access key must have write permission on the target log topic. |
CLS_SECRET_KEY | Yes | Tencent Cloud access Key. |
OPENAI_API_KEY | Yes | API Key for the OpenAI model service. |
setup() before the first invocation of Runner.run() or Runner.run_sync(). No changes are required to your existing Agent code.import osfrom tencentcloud_agentobs_sdk_openai_agent import CLSConfig, setupsetup(CLSConfig(endpoint=os.environ["CLS_ENDPOINT"],topic_id=os.environ["CLS_TOPIC_ID"],secret_id=os.environ["CLS_SECRET_ID"],secret_key=os.environ["CLS_SECRET_KEY"],))# The following is the existing OpenAI Agents SDK code.from agents import Agent, Runneragent = Agent(name="assistant",instructions="You are a helpful assistant.",model="gpt-4o",)result = Runner.run_sync(agent, "What's the weather like in Beijing?")print(result.final_output)
from tencentcloud_agentobs_sdk_openai_agent import setupsetup()
setup() must be called before the Agent is run for the first time. It is recommended to call it once at the application entry point to avoid duplicate handler registration and duplicate traces.setup() has been called before the first invocation of Runner.run() or Runner.run_sync().CLS_ENDPOINT is in the same region as the Trace log topic.CLS_TOPIC_ID is the log topic ID, not the Agent Observability application ID.off and whether the OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT environment variable has disabled message content collection. Disabling content collection does not affect the reporting of data such as call trees, tokens, duration, and status.setup() repeatedly, or whether the same data is sent to the same log topic through multiple collection components. Except for comparison verification, it is recommended to initialize this SDK only once in the same process.Runner. The SDK restores the parent-child relationship based on span.parent_id.Was this page helpful?
You can also Contact sales or Submit a Ticket for help.
Help us improve! Rate your documentation experience in 5 mins.
Feedback