ch10_routing

show:
mock turns=5 · messages=11
live turns=5 · messages=12
scenario the_question_needs_no_model
scenario the_question_needs_no_model · 0.2ms · 1 turn · ended: answered_without_a_model
turn 1 · 0.0ms
answered directly {"because": "the catalog is a known fact", "value": "bread, butter, chips, milk"}
ended {"reason": "answered_without_a_model"}
scenario the_question_needs_no_model · 0.2ms · 1 turn · ended: answered_without_a_model
turn 1 · 0.0ms
answered directly {"because": "the catalog is a known fact", "value": "bread, butter, chips, milk"}
ended {"reason": "answered_without_a_model"}
scenario a_write_takes_a_longer_path
scenario a_write_takes_a_longer_path · tools=place_order, price_of · 5.0ms · 2 turns · ended: no_tool_calls
turn 1 · 4.7ms · asked for: place_order
model mock · 4.1ms · asked for: place_order
context sent — 2 message(s)
rolecontent
[0]systemYou answer briefly and plainly. Use the tools you are given.
[1]humanOrder 2 bottles of milk.
declared tools (2)
tooldescriptionschema
place_orderOrder a quantity of an item. A write: routed through confirmation first.{"$defs": {"GroceryItem": {"enum": ["bread", "butter", "chips", "milk"], "type": "string"}}, "description": "Order a quantity of an item. A write: routed through confirmation first.", "properties": {"item": {"$ref": "#/$defs/GroceryItem"}, "quantity": {"title": "Quantity", "type": "integer"}}, "required": ["item", "quantity"], "title": "place_order", "type": "object"}
price_ofThe current shelf price of an item, in pounds. A read: routed directly.{"$defs": {"GroceryItem": {"enum": ["bread", "butter", "chips", "milk"], "type": "string"}}, "description": "The current shelf price of an item, in pounds. A read: routed directly.", "properties": {"item": {"$ref": "#/$defs/GroceryItem"}}, "required": ["item"], "title": "price_of", "type": "object"}
tools declared to the mock model {"names": ["place_order", "price_of"], "consulted": false}
context ignored by the mock model {"messages": 2, "roles": ["system", "human"]}
reply
rolecontent
[0]ai
place_order({"item": "milk", "quantity": 2})
tool place_order · 0.5ms · given: item=milk, quantity=2 · returned: ordered 2 x milk
args {"item": "milk", "quantity": 2}
routed {"to": "confirm_before_dispatch"}
confirmed {"summary": "2 x milk"}
result {"value": "ordered 2 x milk"}
turn 2 · 0.3ms · responded with: Ordered 2 bottles of milk.
model mock · 0.3ms · responded with: Ordered 2 bottles of milk.
context sent — 4 message(s)
rolecontent
[0]systemYou answer briefly and plainly. Use the tools you are given.
[1]humanOrder 2 bottles of milk.
[2]ai
place_order({"item": "milk", "quantity": 2})
[3]toolordered 2 x milk
declared tools (2)
tooldescriptionschema
place_orderOrder a quantity of an item. A write: routed through confirmation first.{"$defs": {"GroceryItem": {"enum": ["bread", "butter", "chips", "milk"], "type": "string"}}, "description": "Order a quantity of an item. A write: routed through confirmation first.", "properties": {"item": {"$ref": "#/$defs/GroceryItem"}, "quantity": {"title": "Quantity", "type": "integer"}}, "required": ["item", "quantity"], "title": "place_order", "type": "object"}
price_ofThe current shelf price of an item, in pounds. A read: routed directly.{"$defs": {"GroceryItem": {"enum": ["bread", "butter", "chips", "milk"], "type": "string"}}, "description": "The current shelf price of an item, in pounds. A read: routed directly.", "properties": {"item": {"$ref": "#/$defs/GroceryItem"}}, "required": ["item"], "title": "price_of", "type": "object"}
tools declared to the mock model {"names": ["place_order", "price_of"], "consulted": false}
context ignored by the mock model {"messages": 4, "roles": ["system", "human", "ai", "tool"]}
reply
rolecontent
[0]aiOrdered 2 bottles of milk.
ended {"reason": "no_tool_calls"}
scenario a_write_takes_a_longer_path · tools=place_order, price_of · 2039.3ms · 2 turns · ended: no_tool_calls
turn 1 · 1261.8ms · 421 in / 102 out · asked for: place_order
model live · 1260.8ms (model provider 1075.3 · library 185.5) · 421 in / 102 out · asked for: place_order
context sent — 2 message(s)
rolecontent
[0]systemYou answer briefly and plainly. Use the tools you are given.
[1]humanOrder 2 bottles of milk.
declared tools (2)
tooldescriptionschema
place_orderOrder a quantity of an item. A write: routed through confirmation first.{"$defs": {"GroceryItem": {"enum": ["bread", "butter", "chips", "milk"], "type": "string"}}, "description": "Order a quantity of an item. A write: routed through confirmation first.", "properties": {"item": {"$ref": "#/$defs/GroceryItem"}, "quantity": {"title": "Quantity", "type": "integer"}}, "required": ["item", "quantity"], "title": "place_order", "type": "object"}
price_ofThe current shelf price of an item, in pounds. A read: routed directly.{"$defs": {"GroceryItem": {"enum": ["bread", "butter", "chips", "milk"], "type": "string"}}, "description": "The current shelf price of an item, in pounds. A read: routed directly.", "properties": {"item": {"$ref": "#/$defs/GroceryItem"}}, "required": ["item"], "title": "price_of", "type": "object"}
wire request
attempt
1
method
POST
url
https://api.deepseek.com/v1/chat/completions
defaulted (6)
temperature, max_tokens, top_p, stop, seed, tool_choice
headers (18)
show
acceptapplication/json
accept-encodinggzip, deflate, zstd
authorizationnot recorded
connectionkeep-alive
content-length795
content-typeapplication/json
hostapi.deepseek.com
user-agentOpenAI/Python 3.6.0
x-stainless-archarm64
x-stainless-asyncfalse
x-stainless-langpython
x-stainless-osMacOS
x-stainless-package-version3.6.0
x-stainless-raw-responsetrue
x-stainless-read-timeout60.0
x-stainless-retry-count0
x-stainless-runtimeCPython
x-stainless-runtime-version3.14.7
{
  "messages": [
    {
      "content": "You answer briefly and plainly. Use the tools you are given.",
      "role": "system"
    },
    {
      "content": "Order 2 bottles of milk.",
      "role": "user"
    }
  ],
  "model": "deepseek-flash",
  "stream": false,
  "tools": [
    {
      "type": "function",
      "function": {
        "name": "place_order",
        "description": "Order a quantity of an item. A write: routed through confirmation first.",
        "parameters": {
          "properties": {
            "item": {
              "enum": [
                "bread",
                "butter",
                "chips",
                "milk"
              ],
              "type": "string"
            },
            "quantity": {
              "type": "integer"
            }
          },
          "required": [
            "item",
            "quantity"
          ],
          "type": "object"
        }
      }
    },
    {
      "type": "function",
      "function": {
        "name": "price_of",
        "description": "The current shelf price of an item, in pounds. A read: routed directly.",
        "parameters": {
          "properties": {
            "item": {
              "enum": [
                "bread",
                "butter",
                "chips",
                "milk"
              ],
              "type": "string"
            }
          },
          "required": [
            "item"
          ],
          "type": "object"
        }
      }
    }
  ]
}
wire response
status
200
headers (15)
show
access-control-allow-credentialstrue
connectionkeep-alive
content-encodinggzip
content-typeapplication/json
dateSun, 13 Sep 2026 21:52:17 GMT
serverelb
strict-transport-securitymax-age=31536000; includeSubDomains; preload
transfer-encodingchunked
varyorigin, access-control-request-method, access-control-request-headers
via1.1 153d2cbd7c83442a049eab26571069f6.cloudfront.net (CloudFront)
x-amz-cf-idHi5MNEFGuiotz45M8ma3fHy-DCNCasjl7qrjIm5rN4mcnbD2GxpakQ==
x-amz-cf-popDEN53-P6
x-cacheMiss from cloudfront
x-content-type-optionsnosniff
x-ds-trace-id7a5b6930741847e998022e2b1340a89a
{
  "id": "f83d8f02-ab2a-4258-80e3-96d6f8d550a9",
  "object": "chat.completion",
  "created": 1789336337,
  "model": "deepseek-flash",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "",
        "reasoning_content": "The user wants to order 2 bottles of milk. I should just place the order. Maybe check price? Not necessary. Let me place the order.\n\nNote: place_order is a write routed through confirmation. Let me call it.",
        "tool_calls": [
          {
            "index": 0,
            "id": "call_00_6pBNCumwqi6ooR2JlYIH6286",
            "type": "function",
            "function": {
              "name": "place_order",
              "arguments": "{\"item\": \"milk\", \"quantity\": 2}"
            }
          }
        ]
      },
      "logprobs": null,
      "finish_reason": "tool_calls"
    }
  ],
  "usage": {
    "prompt_tokens": 421,
    "completion_tokens": 102,
    "total_tokens": 523,
    "prompt_tokens_details": {
      "cached_tokens": 256
    },
    "completion_tokens_details": {
      "reasoning_tokens": 47
    },
    "prompt_cache_hit_tokens": 256,
    "prompt_cache_miss_tokens": 165
  },
  "system_fingerprint": "aeb56401ca74e127821c4f9126dcb669"
}
reply
rolecontent
[0]ai
place_order({"item": "milk", "quantity": 2})
tool place_order · 1.0ms · given: item=milk, quantity=2 · returned: ordered 2 x milk
args {"item": "milk", "quantity": 2}
routed {"to": "confirm_before_dispatch"}
confirmed {"summary": "2 x milk"}
result {"value": "ordered 2 x milk"}
turn 2 · 777.4ms · 540 in / 8 out · responded with: Done — ordered 2 milk.
model live · 777.4ms (model provider 765.0 · library 12.4) · 540 in / 8 out · responded with: Done — ordered 2 milk.
context sent — 4 message(s)
rolecontent
[0]systemYou answer briefly and plainly. Use the tools you are given.
[1]humanOrder 2 bottles of milk.
[2]ai
place_order({"item": "milk", "quantity": 2})
[3]toolordered 2 x milk
declared tools (2)
tooldescriptionschema
place_orderOrder a quantity of an item. A write: routed through confirmation first.{"$defs": {"GroceryItem": {"enum": ["bread", "butter", "chips", "milk"], "type": "string"}}, "description": "Order a quantity of an item. A write: routed through confirmation first.", "properties": {"item": {"$ref": "#/$defs/GroceryItem"}, "quantity": {"title": "Quantity", "type": "integer"}}, "required": ["item", "quantity"], "title": "place_order", "type": "object"}
price_ofThe current shelf price of an item, in pounds. A read: routed directly.{"$defs": {"GroceryItem": {"enum": ["bread", "butter", "chips", "milk"], "type": "string"}}, "description": "The current shelf price of an item, in pounds. A read: routed directly.", "properties": {"item": {"$ref": "#/$defs/GroceryItem"}}, "required": ["item"], "title": "price_of", "type": "object"}
wire request
attempt
1
method
POST
url
https://api.deepseek.com/v1/chat/completions
defaulted (6)
temperature, max_tokens, top_p, stop, seed, tool_choice
headers (18)
show
acceptapplication/json
accept-encodinggzip, deflate, zstd
authorizationnot recorded
connectionkeep-alive
content-length1318
content-typeapplication/json
hostapi.deepseek.com
user-agentOpenAI/Python 3.6.0
x-stainless-archarm64
x-stainless-asyncfalse
x-stainless-langpython
x-stainless-osMacOS
x-stainless-package-version3.6.0
x-stainless-raw-responsetrue
x-stainless-read-timeout60.0
x-stainless-retry-count0
x-stainless-runtimeCPython
x-stainless-runtime-version3.14.7
{
  "messages": [
    {
      "content": "You answer briefly and plainly. Use the tools you are given.",
      "role": "system"
    },
    {
      "content": "Order 2 bottles of milk.",
      "role": "user"
    },
    {
      "content": null,
      "role": "assistant",
      "tool_calls": [
        {
          "type": "function",
          "id": "call_00_6pBNCumwqi6ooR2JlYIH6286",
          "function": {
            "name": "place_order",
            "arguments": "{\"item\": \"milk\", \"quantity\": 2}"
          }
        }
      ],
      "reasoning_content": "The user wants to order 2 bottles of milk. I should just place the order. Maybe check price? Not necessary. Let me place the order.\n\nNote: place_order is a write routed through confirmation. Let me call it."
    },
    {
      "content": "ordered 2 x milk",
      "role": "tool",
      "tool_call_id": "call_00_6pBNCumwqi6ooR2JlYIH6286"
    }
  ],
  "model": "deepseek-flash",
  "stream": false,
  "tools": [
    {
      "type": "function",
      "function": {
        "name": "place_order",
        "description": "Order a quantity of an item. A write: routed through confirmation first.",
        "parameters": {
          "properties": {
            "item": {
              "enum": [
                "bread",
                "butter",
                "chips",
                "milk"
              ],
              "type": "string"
            },
            "quantity": {
              "type": "integer"
            }
          },
          "required": [
            "item",
            "quantity"
          ],
          "type": "object"
        }
      }
    },
    {
      "type": "function",
      "function": {
        "name": "price_of",
        "description": "The current shelf price of an item, in pounds. A read: routed directly.",
        "parameters": {
          "properties": {
            "item": {
              "enum": [
                "bread",
                "butter",
                "chips",
                "milk"
              ],
              "type": "string"
            }
          },
          "required": [
            "item"
          ],
          "type": "object"
        }
      }
    }
  ]
}
wire response
status
200
headers (15)
show
access-control-allow-credentialstrue
connectionkeep-alive
content-encodinggzip
content-typeapplication/json
dateSun, 13 Sep 2026 21:52:18 GMT
serverelb
strict-transport-securitymax-age=31536000; includeSubDomains; preload
transfer-encodingchunked
varyorigin, access-control-request-method, access-control-request-headers
via1.1 053c5da1899ec0e6bd16002f05ca768a.cloudfront.net (CloudFront)
x-amz-cf-idj4kA1S0xR54R6uVqsSVU2zZyuo_pQvk-IRYUPy5ZoEu7-_UqZ9RrAw==
x-amz-cf-popDEN53-P6
x-cacheMiss from cloudfront
x-content-type-optionsnosniff
x-ds-trace-id3dd40c3a29d351bc4bfb5fd96d9ff416
{
  "id": "c89ac149-dd1c-43ec-9601-f95f1eb11f6e",
  "object": "chat.completion",
  "created": 1789336338,
  "model": "deepseek-flash",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "Done \u2014 ordered 2 milk.",
        "reasoning_content": ""
      },
      "logprobs": null,
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 540,
    "completion_tokens": 8,
    "total_tokens": 548,
    "prompt_tokens_details": {
      "cached_tokens": 384
    },
    "completion_tokens_details": {
      "reasoning_tokens": 0
    },
    "prompt_cache_hit_tokens": 384,
    "prompt_cache_miss_tokens": 156
  },
  "system_fingerprint": "aeb56401ca74e127821c4f9126dcb669"
}
reply
rolecontent
[0]aiDone — ordered 2 milk.
ended {"reason": "no_tool_calls"}
scenario the_turns_are_running_out
scenario the_turns_are_running_out · tools=place_order, price_of · 0.5ms · 2 turns · ended: wrapped_up_early
turn 1 · 0.4ms · asked for: price_of
model mock · 0.2ms · asked for: price_of
context sent — 2 message(s)
rolecontent
[0]systemYou answer briefly and plainly. Use the tools you are given.
[1]humanHow much is milk, and how much are chips?
declared tools (2)
tooldescriptionschema
place_orderOrder a quantity of an item. A write: routed through confirmation first.{"$defs": {"GroceryItem": {"enum": ["bread", "butter", "chips", "milk"], "type": "string"}}, "description": "Order a quantity of an item. A write: routed through confirmation first.", "properties": {"item": {"$ref": "#/$defs/GroceryItem"}, "quantity": {"title": "Quantity", "type": "integer"}}, "required": ["item", "quantity"], "title": "place_order", "type": "object"}
price_ofThe current shelf price of an item, in pounds. A read: routed directly.{"$defs": {"GroceryItem": {"enum": ["bread", "butter", "chips", "milk"], "type": "string"}}, "description": "The current shelf price of an item, in pounds. A read: routed directly.", "properties": {"item": {"$ref": "#/$defs/GroceryItem"}}, "required": ["item"], "title": "price_of", "type": "object"}
tools declared to the mock model {"names": ["place_order", "price_of"], "consulted": false}
context ignored by the mock model {"messages": 2, "roles": ["system", "human"]}
reply
rolecontent
[0]ai
price_of({"item": "milk"})
tool price_of · 0.2ms · given: item=milk · returned: 1.20 for milk
args {"item": "milk"}
routed {"to": "dispatch_directly"}
result {"value": "1.20 for milk"}
turn 2 · 0.0ms
wrapped up {"because": "no turns left to ask again", "value": "Here's what I found before running out of turns: 1.20 for milk"}
ended {"reason": "wrapped_up_early"}
scenario the_turns_are_running_out · tools=place_order, price_of · 1385.4ms · 2 turns · ended: wrapped_up_early
turn 1 · 1385.3ms · 425 in / 84 out · asked for: price_of, price_of
model live · 1384.2ms (model provider 1371.2 · library 13.0) · 425 in / 84 out · asked for: price_of, price_of
context sent — 2 message(s)
rolecontent
[0]systemYou answer briefly and plainly. Use the tools you are given.
[1]humanHow much is milk, and how much are chips?
declared tools (2)
tooldescriptionschema
place_orderOrder a quantity of an item. A write: routed through confirmation first.{"$defs": {"GroceryItem": {"enum": ["bread", "butter", "chips", "milk"], "type": "string"}}, "description": "Order a quantity of an item. A write: routed through confirmation first.", "properties": {"item": {"$ref": "#/$defs/GroceryItem"}, "quantity": {"title": "Quantity", "type": "integer"}}, "required": ["item", "quantity"], "title": "place_order", "type": "object"}
price_ofThe current shelf price of an item, in pounds. A read: routed directly.{"$defs": {"GroceryItem": {"enum": ["bread", "butter", "chips", "milk"], "type": "string"}}, "description": "The current shelf price of an item, in pounds. A read: routed directly.", "properties": {"item": {"$ref": "#/$defs/GroceryItem"}}, "required": ["item"], "title": "price_of", "type": "object"}
wire request
attempt
1
method
POST
url
https://api.deepseek.com/v1/chat/completions
defaulted (6)
temperature, max_tokens, top_p, stop, seed, tool_choice
headers (18)
show
acceptapplication/json
accept-encodinggzip, deflate, zstd
authorizationnot recorded
connectionkeep-alive
content-length812
content-typeapplication/json
hostapi.deepseek.com
user-agentOpenAI/Python 3.6.0
x-stainless-archarm64
x-stainless-asyncfalse
x-stainless-langpython
x-stainless-osMacOS
x-stainless-package-version3.6.0
x-stainless-raw-responsetrue
x-stainless-read-timeout60.0
x-stainless-retry-count0
x-stainless-runtimeCPython
x-stainless-runtime-version3.14.7
{
  "messages": [
    {
      "content": "You answer briefly and plainly. Use the tools you are given.",
      "role": "system"
    },
    {
      "content": "How much is milk, and how much are chips?",
      "role": "user"
    }
  ],
  "model": "deepseek-flash",
  "stream": false,
  "tools": [
    {
      "type": "function",
      "function": {
        "name": "place_order",
        "description": "Order a quantity of an item. A write: routed through confirmation first.",
        "parameters": {
          "properties": {
            "item": {
              "enum": [
                "bread",
                "butter",
                "chips",
                "milk"
              ],
              "type": "string"
            },
            "quantity": {
              "type": "integer"
            }
          },
          "required": [
            "item",
            "quantity"
          ],
          "type": "object"
        }
      }
    },
    {
      "type": "function",
      "function": {
        "name": "price_of",
        "description": "The current shelf price of an item, in pounds. A read: routed directly.",
        "parameters": {
          "properties": {
            "item": {
              "enum": [
                "bread",
                "butter",
                "chips",
                "milk"
              ],
              "type": "string"
            }
          },
          "required": [
            "item"
          ],
          "type": "object"
        }
      }
    }
  ]
}
wire response
status
200
headers (15)
show
access-control-allow-credentialstrue
connectionkeep-alive
content-encodinggzip
content-typeapplication/json
dateSun, 13 Sep 2026 21:52:19 GMT
serverelb
strict-transport-securitymax-age=31536000; includeSubDomains; preload
transfer-encodingchunked
varyorigin, access-control-request-method, access-control-request-headers
via1.1 2870015ca1c40ef5342e0ec500437a72.cloudfront.net (CloudFront)
x-amz-cf-idtXfVyy9MKp1FQdhL7nHai-32eXzdCH2WZmuM7ILtREpGDuRngQyzow==
x-amz-cf-popDEN53-P6
x-cacheMiss from cloudfront
x-content-type-optionsnosniff
x-ds-trace-id184a52a9917e310e0782cf92da23b3ca
{
  "id": "673170f4-50d2-4799-9c01-7054860e77dc",
  "object": "chat.completion",
  "created": 1789336339,
  "model": "deepseek-flash",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "",
        "reasoning_content": "We need price_of milk and price_of chips. Independent calls, same block.",
        "tool_calls": [
          {
            "index": 0,
            "id": "call_00_Up4gOe9f8I4AwBbnHcql8655",
            "type": "function",
            "function": {
              "name": "price_of",
              "arguments": "{\"item\": \"milk\"}"
            }
          },
          {
            "index": 1,
            "id": "call_01_KgFli6DHC5ERusyys8YH6646",
            "type": "function",
            "function": {
              "name": "price_of",
              "arguments": "{\"item\": \"chips\"}"
            }
          }
        ]
      },
      "logprobs": null,
      "finish_reason": "tool_calls"
    }
  ],
  "usage": {
    "prompt_tokens": 425,
    "completion_tokens": 84,
    "total_tokens": 509,
    "prompt_tokens_details": {
      "cached_tokens": 256
    },
    "completion_tokens_details": {
      "reasoning_tokens": 16
    },
    "prompt_cache_hit_tokens": 256,
    "prompt_cache_miss_tokens": 169
  },
  "system_fingerprint": "aeb56401ca74e127821c4f9126dcb669"
}
reply
rolecontent
[0]ai
price_of({"item": "milk"})
price_of({"item": "chips"})
tool price_of · 0.6ms · given: item=milk · returned: 1.20 for milk
args {"item": "milk"}
routed {"to": "dispatch_directly"}
result {"value": "1.20 for milk"}
tool price_of · 0.4ms · given: item=chips · returned: 1.20 for chips
args {"item": "chips"}
routed {"to": "dispatch_directly"}
result {"value": "1.20 for chips"}
turn 2 · 0.0ms
wrapped up {"because": "no turns left to ask again", "value": "Here's what I found before running out of turns: 1.20 for milk; 1.20 for chips"}
ended {"reason": "wrapped_up_early"}