SuperAPI AI 工具集

maple-agent-tracing-dspy

智能体与模型

查看项目

更新于 10-16 00:05

技能介绍

用途:把 DSPy 程序与 ReAct 智能体的每次对话接入 Maple Agent Sessions,一个会话一个 session,一次程序调用一个 turn,包含对话记录、带 token 与成本的模型调用、带参数与结果的工具调用,以及每个 worker 模块一条 lane。

主要能力:基于 openinference-instrumentation-dspy 的 span,再通过自定义 MapleCallback 补齐插桩缺失的信息——agent span、工具名、token 与成本、session id。使用 TraceConfig(enable_genai_semconv=True) 启用 GenAI 双写;用 ThreadingInstrumentor 支持 dspy.Parallel、Evaluate 等线程场景;用 using_session(conversation_id) 绑定会话。

使用方式:要求 dspy>=3.4,安装 openinference-instrumentation-dspy>=0.1.45、openinference-instrumentation>=0.1.66、opentelemetry-sdk>=1.45、opentelemetry-exporter-otlp-proto-http>=1.45、opentelemetry-instrumentation-threading>=0.66b0。配置 OTEL_EXPORTER_OTLP_ENDPOINT(美国 https://ingest.maple.dev,欧盟 https://ingest.eu.maple.dev)、OTEL_EXPORTER_OTLP_HEADERS、OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf。创建 tracing.py 设置 TracerProvider、BatchSpanProcessor(OTLPSpanExporter()) 并 instrument;创建 maple_dspy.py 注册 MapleCallback;在 dspy.configure(callbacks=[...]) 中追加该实例。每轮对话用 using_session 包裹;流式需在 dspy.configure 之后调用 dspy.streamify,并用 using_session 包住消费循环。脚本/CLI 结束调用 provider.shutdown(),Serverless 与 notebook 用 provider.force_flush()。

适用场景:DSPy 程序的会话级可观测性、ReAct 工具调用追踪、并行 worker 与子智能体分析、token 与成本统计。

限制:不支持 multiprocessing;流式调用无 gen_ai.response.id 与 TTFT;工具 span 无 gen_ai.tool.call.id;成本为 DSPy 估算,无法定价的模型显示未定价;缺少 ingest key 时应跳过导出而非报错;key 与区域绑定,401 时尝试另一区域。可设置 OPENINFERENCE_HIDE_INPUTS / OPENINFERENCE_HIDE_OUTPUTS 关闭内容采集。