GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing doc.agentscope.io — Tracing - AgentScope Note Go to the end to download the full example code. Tracing¶AgentScope implements OpenTelemetry-based tracing to monitor and debug the execution of agent applications, which features
Setting Up¶Note Connecting to the AgentScope Studio or third-party tracing endpoint should be done at the beginning of your application by the AgentScope Studio¶
Tracing in AgentScope Studio¶ When connecting to AgentScope Studio, just provide import agentscope agentscope.init(studio_url="http://xxx:port") Third-party Platforms¶To connect to third-party tracing platforms, set the import agentscope # Connect to OpenTelemetry-compatible backends agentscope.init(tracing_url="https://your-tracing-backend:port/traces") Taking Alibaba Cloud CloudMonitor, Arize-Phoenix, and Langfuse as examples: Alibaba Cloud CloudMonitor: A fully-managed observability platform. Connect to Alibaba Cloud CloudMonitor¶
agentscope.init(tracing_url="https://tracing-cn-hangzhou.arms.aliyuncs.com/adapt_xxx/api/otlp/traces") Tip Get your Endpoint: In the ARMS Console under Access Center > OpenTelemetry,
select the Public Endpoint matching your deployment region. Customize your app name via the Arize-Phoenix: You need to set the Connect to Arize Phoenix¶
# Arize Phoenix Integration import os PHOENIX_API_KEY = os.environ.get("PHOENIX_API_KEY") os.environ["OTEL_EXPORTER_OTLP_HEADERS"] = f"api_key={PHOENIX_API_KEY}" agentscope.init(tracing_url="https://app.phoenix.arize.com/v1/traces") LangFuse: You need to set the Connect to LangFuse¶
import os, base64 LANGFUSE_PUBLIC_KEY = os.environ["LANGFUSE_PUBLIC_KEY"] LANGFUSE_SECRET_KEY = os.environ["LANGFUSE_SECRET_KEY"] LANGFUSE_AUTH_STRING = f"{LANGFUSE_PUBLIC_KEY}:{LANGFUSE_SECRET_KEY}" LANGFUSE_AUTH = base64.b64encode(LANGFUSE_AUTH_STRING.encode("utf-8")).decode("ascii") os.environ["OTEL_EXPORTER_OTLP_HEADERS"] = f"Authorization=Basic {LANGFUSE_AUTH}" # EU data region agentscope.init(tracing_url="https://cloud.langfuse.com/api/public/otel/v1/traces") # US data region # agentscope.init(tracing_url="https://us.cloud.langfuse.com/api/public/otel/v1/traces") Customizing Tracing¶As stated above, the tracing in AgentScope is implemented based on OpenTelemetry. That means your own tracing code implemented by OpenTelemetry sdk is compatible with AgentScope natively. Besides, AgentScope has built-in the following decorators to trace the corresponding modules:
Tracing LLMs¶The Note Your LLM class must inherit from Tracing new ChatModel class¶
class ExampleChatModel(ChatModelBase): """An example Model""" ... @trace_llm async def __call__( self, *args: Any, **kwargs: Any, ) -> AsyncGenerator[ChatResponse, None] | ChatResponse: """LLM call""" ... Tracing Agent¶The Note Your agent class must inherit from Tracing new Agent class¶
class ExampleAgent(AgentBase): """An example agent class""" @tracer_reply async def reply(self, *args: Any, **kwargs: Any) -> Msg: """Reply to the message.""" ... Tracing Formatter¶The Note Your formatter class must inherit from Tracing new Formatter class¶
class ExampleFormatter(FormatterBase): """A simple example formatter class""" @trace_format async def format(self, *args: Any, **kwargs: Any) -> list[dict]: """Example formatting""" General Tracing¶The
General tracing example¶
# 1. Synchronous function @trace(name='simple_function') def simple_function(name: str, age: int) -> str: """A simple function with automatic tracing.""" return f"Hello, {name}! You are {age} years old." # 2. Synchronous generator function @trace(name='number_generator') def number_generator(n: int) -> Generator[int, None, None]: """Generate numbers from 0 to n-1.""" for i in range(n): yield i # 3. Asynchronous function @trace(name='async_function') async def async_function(data: dict) -> dict: """Process data asynchronously.""" return {"processed": data} # 4. Asynchronous generator function @trace(name='async_stream') async def async_stream(n: int) -> AsyncGenerator[str, None]: """Generate stream of data asynchronously.""" for i in range(n): yield f"data_{i}" Total running time of the script: (0 minutes 0.000 seconds) |
| You are visitor 01402775 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |