Inf. 00's TIL

Things I've learned.

LangGraph 맛보기 feat. tool 디버깅

2026-02-04 · langgraph

LangGraph 2가지 사용법



tool call 탐구

[INST] What's 2+2? [/INST]
[TOOL_CALLS]  # <- 아래 log 보면 이 token이 생성되는 것을 확인할 수 있음
 [{"name": "calculator", "arguments": {...}}]
2026-02-08 01:13:16 [DEBUG]
 Received request: POST to /v1/chat/completions with body  {
  "messages": [
    {
      "content": "You are a helpful assistant",
      "role": "system"
    },
    {
      "content": "1*2",
      "role": "user"
    }
  ],
  "model": "mistralai/ministral-3-14b-reasoning",
  "stream": false,
  "temperature": 0,
  "tools": [
    {
      "type": "function",
      "function": {
        "name": "add",
        "description": "Adds `a` and `b`.\n\n    Args:\n        a: First int\n        b: Second int",
        "parameters": {
          "properties": {
            "a": {
              "type": "integer"
            },
            "b": {
              "type": "integer"
            }
          },
          "required": [
            "a",
            "b"
          ],
          "type": "object"
        }
      }
    },
    {
      "type": "function",
      "function": {
        "name": "multiply",
        "description": "Multiply `a` and `b`.\n\n    Args:\n        a: First int\n        b: Second int",
        "parameters": {
          "properties": {
            "a": {
              "type": "integer"
            },
            "b": {
              "type": "integer"
            }
          },
          "required": [
            "a",
            "b"
          ],
          "type": "object"
        }
      }
    },
    {
      "type": "function",
      "function": {
        "name": "divide",
        "description": "Divide `a` and `b`.\n\n    Args:\n        a: First int\n        b: Second int",
        "parameters": {
          "properties": {
            "a": {
              "type": "integer"
            },
            "b": {
              "type": "integer"
            }
          },
          "required": [
            "a",
            "b"
          ],
          "type": "object"
        }
      }
    }
  ]
}

# 모델의 tool call
2026-02-08 01:13:17 [DEBUG]
 [SamplingSwitch] Entering switch 'mistralV13ToolsSamplingSwitch' (triggered by string: "[TOOL_CALLS]") # <----------- tool call 토큰 생성함. tool use 학습의 산물.
2026-02-08 01:13:17  [INFO]
 [mistralai/ministral-3-14b-reasoning] Start to generate a tool call...
2026-02-08 01:13:18  [INFO]
 [mistralai/ministral-3-14b-reasoning] Tool name generated:  multiply
2026-02-08 01:13:18  [INFO]
 [mistralai/ministral-3-14b-reasoning] Accumulating tool call arguments:  {"
...
 [mistralai/ministral-3-14b-reasoning] Accumulating tool call arguments:  {"a": 1, "b": 2}
2026-02-08 01:13:18  [INFO]
 [mistralai/ministral-3-14b-reasoning] Model generated a tool call.
2026-02-08 01:13:18  [INFO]
 [mistralai/ministral-3-14b-reasoning] Model generated tool calls:  [multiply(a=1, b=2)]

# 모델 response
2026-02-08 01:13:18  [INFO]
 [mistralai/ministral-3-14b-reasoning] Generated prediction:  {
  "id": "chatcmpl-37bu06198lu6b9atpcug9i",
  "object": "chat.completion",
  "created": 1770480796,
  "model": "mistralai/ministral-3-14b-reasoning",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "",
        "tool_calls": [ #<-------------- tool_call format에 맞춰서 response
          {
            "type": "function",
            "id": "570498487",
            "function": {
              "name": "multiply",
              "arguments": "{\"a\":1,\"b\":2}"
            }
          }
        ]
      },
      "logprobs": null,
      "finish_reason": "tool_calls"
    }
  ],
  "usage": {
    "prompt_tokens": 285,
    "completion_tokens": 17,
    "total_tokens": 302
  },
  "stats": {},
  "system_fingerprint": "mistralai/ministral-3-14b-reasoning"
}

# langgraph multiply tool의 결과값을 다시 llm으로 post
# function과  결과값을 돌려줌
2026-02-08 01:13:18 [DEBUG]
 Received request: POST to /v1/chat/completions with body  {
  "messages": [
    {
      "content": "You are a helpful assistant",
      "role": "system"
    },
    {
      "content": "1*2",
      "role": "user"
    },
    {
      "content": null,
      "role": "assistant",
      "tool_calls": [
        {
          "type": "function",
          "id": "570498487",
          "function": {
            "name": "multiply",
            "arguments": "{\"a\": 1, \"b\": 2}"
          }
        }
      ]
    },
    {
      "content": "2",
      "role": "tool",
      "tool_call_id": "570498487"
    }
  ],
  "model": "mistralai/ministral-3-14b-reasoning",
  "stream": false,
  "temperature": 0,
  "tools": [
    {
      "type": "function",
      "function": {
        "name": "add",
        "description": "Adds `a` and `b`.\n\n    Args:\n        a: First int\n        b: Second int",
        "parameters": {
          "properties": {
            "a": {
              "type": "integer"
            },
            "b": {
              "type": "integer"
            }
          },
          "required": [
            "a",
            "b"
          ],
          "type": "object"
        }
      }
    },
    {
      "type": "function",
      "function": {
        "name": "multiply",
        "description": "Multiply `a` and `b`.\n\n    Args:\n        a: First int\n        b: Second int",
        "parameters": {
          "properties": {
            "a": {
              "type": "integer"
            },
            "b": {
              "type": "integer"
            }
          },
          "required": [
            "a",
            "b"
          ],
          "type": "object"
        }
      }
    },
    {
      "type": "function",
      "function": {
        "name": "divide",
        "description": "Divide `a` and `b`.\n\n    Args:\n        a: First int\n        b: Second int",
        "parameters": {
          "properties": {
            "a": {
              "type": "integer"
            },
            "b": {
              "type": "integer"
            }
          },
          "required": [
            "a",
            "b"
          ],
          "type": "object"
        }
      }
    }
  ]
}

# llm 모델의 최종 response
2026-02-08 01:13:18  [INFO]
 [mistralai/ministral-3-14b-reasoning] Running chat completion on conversation with 4 messages.
2026-02-08 01:13:18  [INFO]
 [mistralai/ministral-3-14b-reasoning] Accumulated 1 tokens  The
...
2026-02-08 01:13:19  [INFO]
 [mistralai/ministral-3-14b-reasoning] Accumulated 14 tokens  The result of \(1 \times 2\) is **2**.
2026-02-08 01:13:19  [INFO]
 [mistralai/ministral-3-14b-reasoning] Model generated tool calls:  []
2026-02-08 01:13:19  [INFO]
 [mistralai/ministral-3-14b-reasoning] Generated prediction:  {
  "id": "chatcmpl-2ojj2bd99jrvma2y5bngh",
  "object": "chat.completion",
  "created": 1770480798,
  "model": "mistralai/ministral-3-14b-reasoning",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "The result of \\(1 \\times 2\\) is **2**.",
        "tool_calls": []
      },
      "logprobs": null,
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 305,
    "completion_tokens": 15,
    "total_tokens": 320
  },
  "stats": {},
  "system_fingerprint": "mistralai/ministral-3-14b-reasoning"
}

reference