Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Tracing Bug #193

@akshaylive

Description

@akshaylive

The @tool invocations are incorrectly traced.

Here's an example:

from enum import Enum

from langchain_core.messages.tool import tool_call
from langchain_core.tools import tool
from langgraph.constants import START, END
from langgraph.graph import StateGraph
from pydantic.dataclasses import dataclass
from uipath.tracing import traced


class Operator(Enum):
    ADD = "+"
    SUBTRACT = "-"
    MULTIPLY = "*"
    DIVIDE = "/"

@dataclass
class CalculatorInput:
    a: float
    b: float
    operator: Operator

@dataclass
class CalculatorOutput:
    result: float

@tool
async def example_tool(x: int) -> int:
    """
    Mock tool
    """
    return x


@traced(name="postprocess")
async def postprocess(x: float) -> float:
    """
    Example of nested traced invocation.
    """
    return x

@traced(name="calculate")
async def calculate(input: CalculatorInput) -> CalculatorOutput:
    result = 0
    match input.operator:
        case Operator.ADD: result = input.a + input.b
        case Operator.SUBTRACT: result = input.a - input.b
        case Operator.MULTIPLY: result = input.a * input.b
        case Operator.DIVIDE: result = input.a / input.b if input.b != 0 else 0
    result = await postprocess(result)
    result = await example_tool.ainvoke(input={"x": result})
    return CalculatorOutput(result=result)

builder = StateGraph(state_schema=CalculatorInput, input=CalculatorInput, output=CalculatorOutput)

builder.add_node("calculate", calculate)
builder.add_edge(START, "calculate")
builder.add_edge("calculate", END)

graph = builder.compile()

Here's what I see in the trace.

Image

The correct trace should be that example_tool should be placed under calculate.

However, if I write

@tool
@traced(name="example_tool")
async def ...

Then, the trace looks better:
Image

However the @tool is still being added to the tracing in the wrong spot.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions