Skip to content

.NET: execute_tool double escapes gen_ai.tool.call.result #2231

@zakimaksyutov

Description

@zakimaksyutov

Description

execute_tool span double escapes tool output in gen_ai.tool.call.result. Note, gen_ai.tool.call.arguments doesn't have this issue.

{
    "gen_ai.operation.name": "execute_tool",
    "gen_ai.tool.type": "function",
    "gen_ai.tool.call.id": "call_qhSRsKd0mVfzp1QsZUHhxTGo",
    "gen_ai.tool.name": "ExecuteCommand",
    "gen_ai.tool.description": "Execute a command (cmd.exe) in Windows terminal.",
    "gen_ai.tool.call.arguments": "{\r\n  \"command\": \"dir\",\r\n  \"arguments\": \"/b *CmdAgent*\"\r\n}",
    "gen_ai.tool.call.result": "\"OUTPUT:\\r\\nCmdAgent.deps.json\\r\\nCmdAgent.dll\\r\\nCmdAgent.exe\\r\\nCmdAgent.pdb\\r\\nCmdAgent.runtimeconfig.json\\r\\n\\r\\nEXIT CODE: 0\""
}

Example

Agent interaction:

You> list files which have CmdAgent in its name in current folder
About to execute command:
> dir /b *CmdAgent*
Do you want to proceed? (y/yes): y
Executing command...
----------------------
CmdAgent.deps.json
CmdAgent.dll
CmdAgent.exe
CmdAgent.pdb
CmdAgent.runtimeconfig.json
----------------------
Files with "CmdAgent" in their name in the current folder:
- CmdAgent.deps.json
- CmdAgent.dll
- CmdAgent.exe
- CmdAgent.pdb
- CmdAgent.runtimeconfig.json
You>

This resulted in the following trace.

Image

(1) has gen_ai.tool.call.arguments from description above.

(2) has the following content in gen_ai.input.messages:

[
  {
    "role": "user",
    "parts": [
      {
        "type": "text",
        "content": "list files which have CmdAgent in its name in current folder"
      }
    ]
  },
  {
    "role": "assistant",
    "parts": [
      {
        "type": "tool_call",
        "id": "call_qhSRsKd0mVfzp1QsZUHhxTGo",
        "name": "ExecuteCommand",
        "arguments": {
          "command": "dir",
          "arguments": "/b *CmdAgent*"
        }
      }
    ]
  },
  {
    "role": "tool",
    "parts": [
      {
        "type": "tool_call_response",
        "id": "call_qhSRsKd0mVfzp1QsZUHhxTGo",
        "response": "OUTPUT:\r\nCmdAgent.deps.json\r\nCmdAgent.dll\r\nCmdAgent.exe\r\nCmdAgent.pdb\r\nCmdAgent.runtimeconfig.json\r\n\r\nEXIT CODE: 0"
      }
    ]
  }
]

This shows that tool returned non-escaped string. And it logged correctly in LLM span but not in execute_tool span.

Expectation

gen_ai.tool.call.result should have

"gen_ai.tool.call.result": "OUTPUT:\r\nCmdAgent.deps.json\r\nCmdAgent.dll\r\nCmdAgent.exe\r\nCmdAgent.pdb\r\nCmdAgent.runtimeconfig.json\r\n\r\nEXIT CODE: 0"

instead of

"gen_ai.tool.call.result": "\"OUTPUT:\\r\\nCmdAgent.deps.json\\r\\nCmdAgent.dll\\r\\nCmdAgent.exe\\r\\nCmdAgent.pdb\\r\\nCmdAgent.runtimeconfig.json\\r\\n\\r\\nEXIT CODE: 0\""

Metadata

Metadata

Assignees

Labels

Type

Projects

Status

No status

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions