Skip to content

[bug] Smolagents Trace doesn't Log Tool outputs that are tuples into a single span. #1412

Open
@njbrake

Description

@njbrake

Describe the bug
Smolagents have tools attached: if the custom tool returns an int/str, all is well and output.value gets added to the span. If it's a tuple though, then the output.value isn't added to the span, but has a new "Step 1" span added after the SimpleTool span, which makes it harder to parse.

To Reproduce
make a tool called

def return_str():
    return "IM A STRING"

then make a tool called

def return_tuple():
    return "I'M A TUPLE", "I'M A TUPLE"

Add the tools to a smolagent, make them be called, and observe how return_str function output gets put in the span, but not the return_tuple function output.

Expected behavior
I would expect for the tuple output to show up as output.value in the "SimpleTool" invocation.

Screenshots
macos

Additional context

Here's a span from when the function is a str:

{
    "name": "SimpleTool",
    "context": {
      "trace_id": "0xe45053b15efac0c1e0491ae15c9ad48c",
      "span_id": "0x4142e403271a83a3",
      "trace_state": "[]"
    },
    "kind": "SpanKind.INTERNAL",
    "parent_id": "0x0f70eb08a7fac4e5",
    "start_time": "2025-03-22T19:30:28.929903Z",
    "end_time": "2025-03-22T19:30:29.502678Z",
    "status": {
      "status_code": "OK"
    },
    "attributes": {
      "input.value": "{\"args\": [], \"sanitize_inputs_outputs\": false, \"kwargs\": {\"area_name\": \"Vigo\"}}",
      "tool.name": "get_area_lat_lon",
      "tool.description": "Get the latitude and longitude of an area from Nominatim.\n\nUses the [Nominatim API](https://nominatim.org/release-docs/develop/api/Search/).",
      "tool.parameters": "{\"area_name\": {\"type\": \"string\", \"description\": \"The name of the area.\"}}",
      "output.value": "I'M A STRING",
      "output.mime_type": "text/plain",
      "openinference.span.kind": "TOOL"
    },
    "events": [],
    "links": [],
    "resource": {
      "attributes": {
        "telemetry.sdk.language": "python",
        "telemetry.sdk.name": "opentelemetry",
        "telemetry.sdk.version": "1.31.1",
        "service.name": "unknown_service"
      },
      "schema_url": ""
    }
  },

Here's a span from when the function is a tuple:

{
    "name": "SimpleTool",
    "context": {
      "trace_id": "0x73ec83a565342cd47b30ceb0d71566e9",
      "span_id": "0x8993ae993dedd8e3",
      "trace_state": "[]"
    },
    "kind": "SpanKind.INTERNAL",
    "parent_id": "0xb2e904a7a812a0b5",
    "start_time": "2025-03-22T19:32:19.878726Z",
    "end_time": "2025-03-22T19:32:20.317132Z",
    "status": {
      "status_code": "OK"
    },
    "attributes": {
      "input.value": "{\"args\": [], \"sanitize_inputs_outputs\": false, \"kwargs\": {\"area_name\": \"Vigo\"}}",
      "tool.name": "get_area_lat_lon",
      "tool.description": "Get the latitude and longitude of an area from Nominatim.\n\nUses the [Nominatim API](https://nominatim.org/release-docs/develop/api/Search/).",
      "tool.parameters": "{\"area_name\": {\"type\": \"string\", \"description\": \"The name of the area.\"}}",
      "openinference.span.kind": "TOOL"
    },
    "events": [],
    "links": [],
    "resource": {
      "attributes": {
        "telemetry.sdk.language": "python",
        "telemetry.sdk.name": "opentelemetry",
        "telemetry.sdk.version": "1.31.1",
        "service.name": "unknown_service"
      },
      "schema_url": ""
    }
  },
  {
    "name": "Step 1",
    "context": {
      "trace_id": "0x73ec83a565342cd47b30ceb0d71566e9",
      "span_id": "0xb2e904a7a812a0b5",
      "trace_state": "[]"
    },
    "kind": "SpanKind.INTERNAL",
    "parent_id": "0x5dc291cfa1536391",
    "start_time": "2025-03-22T19:32:05.247173Z",
    "end_time": "2025-03-22T19:32:20.319740Z",
    "status": {
      "status_code": "OK"
    },
    "attributes": {
      "input.value": "{\"memory_step\": \"ActionStep(model_input_messages=None, tool_calls=None, start_time=1742671925.246196, end_time=None, step_number=1, error=None, duration=None, model_output_message=None, model_output=None, observations=None, observations_images=None, action_output=None)\"}",
      "output.value": "Execution logs:\n('IM A TUPLE', 'IM A TUPLE')\nLast output from code snippet:\nNone",
      "openinference.span.kind": "CHAIN"
    },
    "events": [],
    "links": [],
    "resource": {
      "attributes": {
        "telemetry.sdk.language": "python",
        "telemetry.sdk.name": "opentelemetry",
        "telemetry.sdk.version": "1.31.1",
        "service.name": "unknown_service"
      },
      "schema_url": ""
    }
  },

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions