Tool Use Example

Tool Use Example

This example shows an SFT dataset for training models on function calling.

File Structure

tool-use-dataset/
  metadata.json
  data/
    train.jsonl

metadata.json

{
  "schema_version": "llm-training-data/v1",
  "dataset": {
    "name": "tool-use-example",
    "description": "Example dataset for training tool use capabilities"
  },
  "defaults": {
    "system": [
      { "type": "text", "text": "You are a helpful assistant with access to tools. Use them when appropriate to answer user questions accurately." }
    ],
    "toolset_id": "assistant-tools"
  },
  "toolsets": [
    {
      "id": "assistant-tools",
      "tools": [
        {
          "name": "calculator",
          "description": "Evaluate mathematical expressions",
          "input_schema": {
            "type": "object",
            "properties": {
              "expression": { "type": "string", "description": "Math expression to evaluate" }
            },
            "required": ["expression"]
          }
        },
        {
          "name": "get_weather",
          "description": "Get current weather for a location",
          "input_schema": {
            "type": "object",
            "properties": {
              "location": { "type": "string", "description": "City name" },
              "units": { "type": "string", "enum": ["celsius", "fahrenheit"], "default": "celsius" }
            },
            "required": ["location"]
          }
        },
        {
          "name": "search_web",
          "description": "Search the web for information",
          "input_schema": {
            "type": "object",
            "properties": {
              "query": { "type": "string", "description": "Search query" },
              "num_results": { "type": "integer", "default": 5 }
            },
            "required": ["query"]
          }
        },
        {
          "name": "send_email",
          "description": "Send an email",
          "input_schema": {
            "type": "object",
            "properties": {
              "to": { "type": "string", "description": "Recipient email" },
              "subject": { "type": "string" },
              "body": { "type": "string" }
            },
            "required": ["to", "subject", "body"]
          }
        }
      ]
    }
  ],
  "files": [
    {
      "split": "train",
      "objective": "sft",
      "shards": [
        { "path": "data/train.jsonl" }
      ]
    }
  ]
}

data/train.jsonl

Simple Calculator

{
  "id": "tool-001",
  "messages": [
    {
      "role": "user",
      "content": [{ "type": "text", "text": "What is 15% of 240?" }]
    },
    {
      "role": "assistant",
      "content": [
        {
          "type": "tool_call",
          "name": "calculator",
          "call_id": "calc-001",
          "arguments": { "expression": "240 * 0.15" }
        }
      ]
    },
    {
      "role": "tool",
      "content": [
        {
          "type": "tool_result",
          "name": "calculator",
          "call_id": "calc-001",
          "result": { "value": 36 }
        }
      ]
    },
    {
      "role": "assistant",
      "content": [{ "type": "text", "text": "15% of 240 is 36." }]
    }
  ]
}

Weather Query

{
  "id": "tool-002",
  "messages": [
    {
      "role": "user",
      "content": [{ "type": "text", "text": "What's the weather like in Tokyo right now?" }]
    },
    {
      "role": "assistant",
      "content": [
        {
          "type": "tool_call",
          "name": "get_weather",
          "call_id": "weather-001",
          "arguments": { "location": "Tokyo", "units": "celsius" }
        }
      ]
    },
    {
      "role": "tool",
      "content": [
        {
          "type": "tool_result",
          "name": "get_weather",
          "call_id": "weather-001",
          "result": { "temperature": 22, "condition": "partly cloudy", "humidity": 65 }
        }
      ]
    },
    {
      "role": "assistant",
      "content": [{ "type": "text", "text": "In Tokyo right now, it's 22°C and partly cloudy with 65% humidity." }]
    }
  ]
}

Multiple Tool Calls

{
  "id": "tool-003",
  "messages": [
    {
      "role": "user",
      "content": [{ "type": "text", "text": "Compare the weather in London and Paris today." }]
    },
    {
      "role": "assistant",
      "content": [
        {
          "type": "tool_call",
          "name": "get_weather",
          "call_id": "weather-london",
          "arguments": { "location": "London" }
        },
        {
          "type": "tool_call",
          "name": "get_weather",
          "call_id": "weather-paris",
          "arguments": { "location": "Paris" }
        }
      ]
    },
    {
      "role": "tool",
      "content": [
        {
          "type": "tool_result",
          "name": "get_weather",
          "call_id": "weather-london",
          "result": { "temperature": 12, "condition": "rainy" }
        },
        {
          "type": "tool_result",
          "name": "get_weather",
          "call_id": "weather-paris",
          "result": { "temperature": 18, "condition": "sunny" }
        }
      ]
    },
    {
      "role": "assistant",
      "content": [{ "type": "text", "text": "Today's comparison:\n\n**London**: 12°C and rainy\n**Paris**: 18°C and sunny\n\nParis is 6 degrees warmer with much nicer weather for outdoor activities." }]
    }
  ]
}

No Tool Needed

{
  "id": "tool-004",
  "messages": [
    {
      "role": "user",
      "content": [{ "type": "text", "text": "What is the capital of France?" }]
    },
    {
      "role": "assistant",
      "content": [{ "type": "text", "text": "The capital of France is Paris." }]
    }
  ]
}

Tool Error Handling

{
  "id": "tool-005",
  "messages": [
    {
      "role": "user",
      "content": [{ "type": "text", "text": "What's the weather in Atlantis?" }]
    },
    {
      "role": "assistant",
      "content": [
        {
          "type": "tool_call",
          "name": "get_weather",
          "call_id": "weather-err",
          "arguments": { "location": "Atlantis" }
        }
      ]
    },
    {
      "role": "tool",
      "content": [
        {
          "type": "tool_result",
          "name": "get_weather",
          "call_id": "weather-err",
          "result": { "error": "Location not found", "code": "INVALID_LOCATION" }
        }
      ]
    },
    {
      "role": "assistant",
      "content": [{ "type": "text", "text": "I couldn't find weather data for Atlantis. This appears to be a fictional or unrecognized location. Could you provide a real city name?" }]
    }
  ]
}

Sequential Tool Use with Reasoning

{
  "id": "tool-006",
  "messages": [
    {
      "role": "user",
      "content": [{ "type": "text", "text": "I need to calculate the tip for a $85 dinner. We want to leave 18%. Also, what's the weather like outside in New York?" }]
    },
    {
      "role": "assistant",
      "content": [
        { "type": "reasoning", "text": "User has two requests: calculate 18% tip on $85 and get New York weather. I'll handle both." },
        {
          "type": "tool_call",
          "name": "calculator",
          "call_id": "tip-calc",
          "arguments": { "expression": "85 * 0.18" }
        },
        {
          "type": "tool_call",
          "name": "get_weather",
          "call_id": "nyc-weather",
          "arguments": { "location": "New York" }
        }
      ]
    },
    {
      "role": "tool",
      "content": [
        {
          "type": "tool_result",
          "name": "calculator",
          "call_id": "tip-calc",
          "result": { "value": 15.3 }
        },
        {
          "type": "tool_result",
          "name": "get_weather",
          "call_id": "nyc-weather",
          "result": { "temperature": 8, "condition": "clear" }
        }
      ]
    },
    {
      "role": "assistant",
      "content": [{ "type": "text", "text": "Here's what you need:\n\n**Tip**: An 18% tip on $85 comes to $15.30, making your total $100.30.\n\n**Weather in New York**: It's 8°C and clear outside. You might want a jacket!" }]
    }
  ]
}

Full JSONL

{"id":"tool-001","messages":[{"role":"user","content":[{"type":"text","text":"What is 15% of 240?"}]},{"role":"assistant","content":[{"type":"tool_call","name":"calculator","call_id":"calc-001","arguments":{"expression":"240 * 0.15"}}]},{"role":"tool","content":[{"type":"tool_result","name":"calculator","call_id":"calc-001","result":{"value":36}}]},{"role":"assistant","content":[{"type":"text","text":"15% of 240 is 36."}]}]}
{"id":"tool-002","messages":[{"role":"user","content":[{"type":"text","text":"What's the weather in Tokyo?"}]},{"role":"assistant","content":[{"type":"tool_call","name":"get_weather","call_id":"weather-001","arguments":{"location":"Tokyo"}}]},{"role":"tool","content":[{"type":"tool_result","name":"get_weather","call_id":"weather-001","result":{"temperature":22,"condition":"partly cloudy"}}]},{"role":"assistant","content":[{"type":"text","text":"In Tokyo, it's 22°C and partly cloudy."}]}]}
{"id":"tool-003","messages":[{"role":"user","content":[{"type":"text","text":"What is the capital of France?"}]},{"role":"assistant","content":[{"type":"text","text":"The capital of France is Paris."}]}]}