loongsuite-python-agent 0.2.0
loongsuite-python-agent 0.2.0
Installation
pip install loongsuite-distro==0.2.0
loongsuite-bootstrap -a install --version 0.2.0Package Versions
- loongsuite-* packages: 0.2.0
- opentelemetry-* packages: 0.61b0
loongsuite-util-genai
Added
- Add
RetrievalDocumentdataclass for typed retrieval document representation (id, score, content, metadata). (#145) - Control RetrievalDocument serialization: when content capturing is NO_CONTENT, only serialize id and score; when SPAN_ONLY/SPAN_AND_EVENT, serialize full (id, score, content, metadata) (#145)
- Add Entry span (
gen_ai.span.kind=ENTRY) and ReAct Step span (gen_ai.span.kind=STEP) support inExtendedTelemetryHandlerwith types, utilities, and context-manager APIs (#135) - Propagate
gen_ai.session.idandgen_ai.user.idinto Baggage duringstart_entry, enabling traffic coloring viaBaggageSpanProcessorfor all child spans within the entry block (#135)
Changed
- Retrieval semantic convention: Align retrieval spans with LoongSuite spec (#145)
gen_ai.operation.name:retrieve_documents→retrievalgen_ai.retrieval.query→gen_ai.retrieval.query.textfor query text- Span name:
retrieval {gen_ai.data_source.id}whendata_source_idis set - Add
RetrievalInvocationfields:data_source_id,provider,request_model,top_k
- Add optional
contextparameter to allstart_*methods inTelemetryHandlerandExtendedTelemetryHandlerfor explicit parent-child span linking (#135) - Unify
attach/detachstrategy inExtendedTelemetryHandler: alwaysattachregardless of whethercontextis provided;stop_*/fail_*guards restored tocontext_token is None or span is None(#135)
Fixed
- Fix
gen_ai.retrieval.queryto respect content capturing mode: whenOTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENTisNO_CONTENT, both query and documents are now omitted from retrieve spans (previously only documents were gated) (#139) - Fix
_safe_detachto use_RUNTIME_CONTEXT.detachdirectly, avoiding noisyERRORlog from OTel SDK'scontext_api.detachwrapper (#135) - Fix undefined
otel_contextreference in_multimodal_processing.pyprocess_multimodal_fail, replaced with_safe_detach(#135)
loongsuite-instrumentation-langchain
Added
-
ReAct Step instrumentation for AgentExecutor (#139)
- Monkey-patch
AgentExecutor._iter_next_stepand_aiter_next_stepto instrument each ReAct iteration - Dual patch: patch both
langchain.agents(0.x) andlangchain_classic.agents(1.x) when available, so either import path works - Covers invoke, ainvoke, stream, astream, batch, abatch
- ReAct Step spans:
gen_ai.span.kind=STEP,gen_ai.operation.name=react,gen_ai.react.round,gen_ai.react.finish_reason - Span hierarchy: Agent > ReAct Step > LLM/Tool
- Monkey-patch
-
LangGraph ReAct agent support (requires
loongsuite-instrumentation-langgraph) (#139)- Detect LangGraph agents via
Run.metadata["_loongsuite_react_agent"]
(metadata injected by the LangGraph instrumentation) - Disambiguate the top-level graph (Agent span) from child nodes (chain
spans) usinginside_langgraph_reactpropagation - Agent name resolution: when the ReAct agent is invoked inside an outer
graph node, inherit the node's name (e.g.invoke_agent product_agent)
instead of the generic default (invoke_agent LangGraph) - Track ReAct step boundaries via callback-based detection of the
"agent"node within the graph - Span hierarchy: Agent > ReAct Step > LLM/Tool (same as AgentExecutor)
- Detect LangGraph agents via
Breaking Changes
- Rewrite the instrumentation for LangChain with
genai-util(#139)- Replaced the legacy
wrapt-based function wrapping withBaseTracercallback mechanism - Migrated to
ExtendedTelemetryHandlerfromopentelemetry-util-genaifor standardized GenAI semantic conventions - Added Agent detection by
run.name, TTFT tracking, content capture gating, andRLockthread safety - Added new test suite with
oldest/latestdependency matrices
- Replaced the legacy
loongsuite-instrumentation-langgraph
Added
- Initial instrumentation framework for LangGraph (#143)
- Patch
create_react_agentto set_loongsuite_react_agent = Trueflag
onCompiledStateGraph - Patch
Pregel.stream/Pregel.astreamto inject
metadata["_loongsuite_react_agent"]intoRunnableConfig, enabling
LangChain instrumentation to detect ReAct agents via callback metadata - All patches use
wrapt.wrap_function_wrapper/
opentelemetry.instrumentation.utils.unwrap(consistent with
loongsuite-instrumentation-langchain)
- Patch
loongsuite-instrumentation-litellm
Added
- Initialize the instrumentation for Litellm (#88)