Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions src/rius/_semconv_generated.py
Original file line number Diff line number Diff line change
Expand Up @@ -1466,10 +1466,17 @@ class SpanKind(str, Enum):
# are LLM calls the same way chat is, and create_agent is an AGENT span
# just as invoke_agent is, so the mapping is many-to-one and only the
# chat/invoke_agent entries round-trip.
# - CHAIN has no operation of its own, but four operations land on it.
# invoke_workflow and plan are real GenAI operations with no taxonomy
# value of their own; CHAIN is the honest home for both, and the reverse
# direction is the only one that can say so. agent_step is not a
# - CHAIN has no operation of its own, but five operations land on it.
# invoke_workflow, invoke_runner and plan are real GenAI operations with
# no taxonomy value of their own; CHAIN is the honest home for all three,
# and the reverse direction is the only one that can say so.
# invoke_runner is a framework entrypoint (the call that starts a
# framework's run loop), which the conventions define as not being an
# agent, so CHAIN rather than AGENT. The conventions name entrypoint
# operations invoke_{framework_entrypoint} in general, so a table cannot
# list them all: every consumer maps an operation that starts with
# invoke_ and is not in this table to CHAIN as well. invoke_agent is in
# the table, so it keeps AGENT. agent_step is not a
# conventions operation: the Vercel AI SDK's @ai-sdk/otel writes it on
# each step of an agent run (one model call and the tools it asked
# for), a step within the run rather than an agent invocation, so
Expand Down Expand Up @@ -1500,6 +1507,7 @@ class SpanKind(str, Enum):
"retrieval": SpanKind.RETRIEVER,
"rerank": SpanKind.RERANKER,
"invoke_workflow": SpanKind.CHAIN,
"invoke_runner": SpanKind.CHAIN,
"plan": SpanKind.CHAIN,
"agent_step": SpanKind.CHAIN,
"compaction": SpanKind.CHAIN,
Expand Down
15 changes: 13 additions & 2 deletions src/rius/semconv.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,20 @@ def operation_for_kind(kind: str) -> str | None:


def kind_for_operation(operation: str) -> str | None:
"""The taxonomy value for a ``gen_ai.operation.name``, or None if unknown."""
"""The taxonomy value for a ``gen_ai.operation.name``, or None if unknown.

The conventions name a framework entrypoint ``invoke_{framework_entrypoint}``
(``invoke_runner`` is one) and define it as not being an agent, so no table
can list them all. An ``invoke_`` operation the table does not know is a
CHAIN span; ``invoke_agent`` is in the table and stays AGENT.
"""
kind = _KIND_BY_OPERATION.get(operation)
return kind.value if kind is not None else None
if kind is not None:
return kind.value
entrypoint = operation.removeprefix("invoke_")
if entrypoint and entrypoint != operation:
return SpanKind.CHAIN.value
return None


def otel_span_kind(kind: SpanKind) -> OtelSpanKind:
Expand Down
23 changes: 23 additions & 0 deletions tests/test_semconv.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,29 @@ def test_reranker_round_trips_with_the_ai_sdks_rerank_operation() -> None:
assert kind_for_operation("rerank") == "RERANKER"


def test_framework_entrypoint_operations_are_chain_spans() -> None:
"""The conventions name a framework entrypoint ``invoke_runner``, and
``invoke_{framework_entrypoint}`` in general, and define it as not being an
agent. The table lists ``invoke_runner``; any other ``invoke_`` operation
the table does not list lands on CHAIN too, while ``invoke_agent`` stays
AGENT."""
from rius.semconv import kind_for_operation

assert kind_for_operation("invoke_runner") == "CHAIN"
assert kind_for_operation("invoke_crew") == "CHAIN"
assert kind_for_operation("invoke_workflow") == "CHAIN"
assert kind_for_operation("invoke_agent") == "AGENT"


def test_an_unknown_operation_without_the_entrypoint_prefix_has_no_kind() -> None:
from rius.semconv import kind_for_operation

assert kind_for_operation("invoke_") is None
assert kind_for_operation("invoke") is None
assert kind_for_operation("reinvoke_runner") is None
assert kind_for_operation("made_up") is None


def test_data_source_id_is_set_only_on_retriever_spans() -> None:
from rius.semconv import GEN_AI_DATA_SOURCE_ID, kind_attributes

Expand Down
Loading