ch03_the_loop

show:
mock turns=3 · messages=7
live turns=3 · messages=7
scenario agent_with_tool_chain
scenario agent_with_tool_chain · 3.2ms · 3 turns · ended: no_tool_calls
turn 1 · 2.5ms · asked for: lowest_stock_item
model mock · 2.2ms · asked for: lowest_stock_item
context sent — 2 message(s)
rolecontent
[0]systemYou answer briefly and plainly. Use the tools you are given.
[1]humanWhatever we are lowest on -- what does one of them cost?
tools declared to the mock model {"names": ["lowest_stock_item", "price_of"], "consulted": false}
context ignored by the mock model {"messages": 2, "roles": ["system", "human"]}
reply
rolecontent
[0]ai
lowest_stock_item({})
tool lowest_stock_item · 0.2ms · returned: butter
args {}
result {"value": "butter"}
turn 2 · 0.4ms · asked for: price_of
model mock · 0.3ms · asked for: price_of
context sent — 4 message(s)
rolecontent
[0]systemYou answer briefly and plainly. Use the tools you are given.
[1]humanWhatever we are lowest on -- what does one of them cost?
[2]ai
lowest_stock_item({})
[3]toolbutter
tools declared to the mock model {"names": ["lowest_stock_item", "price_of"], "consulted": false}
context ignored by the mock model {"messages": 4, "roles": ["system", "human", "ai", "tool"]}
reply
rolecontent
[0]ai
price_of({"item": "butter"})
tool price_of · 0.2ms · given: item=butter · returned: 3.10
args {"item": "butter"}
result {"value": "3.10"}
turn 3 · 0.2ms · responded with: You are lowest on butter, and one costs 3.10.
model mock · 0.2ms · responded with: You are lowest on butter, and one costs 3.10.
context sent — 6 message(s)
rolecontent
[0]systemYou answer briefly and plainly. Use the tools you are given.
[1]humanWhatever we are lowest on -- what does one of them cost?
[2]ai
lowest_stock_item({})
[3]toolbutter
[4]ai
price_of({"item": "butter"})
[5]tool3.10
tools declared to the mock model {"names": ["lowest_stock_item", "price_of"], "consulted": false}
context ignored by the mock model {"messages": 6, "roles": ["system", "human", "ai", "tool", "ai", "tool"]}
reply
rolecontent
[0]aiYou are lowest on butter, and one costs 3.10.
ended {"reason": "no_tool_calls"}
scenario agent_with_tool_chain · 3489.5ms · 3 turns · ended: no_tool_calls
turn 1 · 1426.7ms · 375 in / 43 out · asked for: lowest_stock_item
model live · 1426.1ms (model provider 1229.4 · library 196.7) · 375 in / 43 out · asked for: lowest_stock_item
context sent — 2 message(s)
rolecontent
[0]systemYou answer briefly and plainly. Use the tools you are given.
[1]humanWhatever we are lowest on -- what does one of them cost?
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-length655
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": "Whatever we are lowest on -- what does one of them cost?",
      "role": "user"
    }
  ],
  "model": "deepseek-flash",
  "stream": false,
  "tools": [
    {
      "type": "function",
      "function": {
        "name": "lowest_stock_item",
        "description": "Which item there is least of in stock.",
        "parameters": {
          "properties": {},
          "type": "object"
        }
      }
    },
    {
      "type": "function",
      "function": {
        "name": "price_of",
        "description": "The current shelf price of one of an item, in pounds.",
        "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:51:16 GMT
serverelb
strict-transport-securitymax-age=31536000; includeSubDomains; preload
transfer-encodingchunked
varyorigin, access-control-request-method, access-control-request-headers
via1.1 d367a81605c570be8f51546cf4468ece.cloudfront.net (CloudFront)
x-amz-cf-id5eOmJFkNHB3U1aFE-zzzvEvCATY4tLyWnt42MJ7lQNb1thMw7_bnhA==
x-amz-cf-popDEN53-P4
x-cacheMiss from cloudfront
x-content-type-optionsnosniff
x-ds-trace-id38330bd4e4a54e274267fe85fb488866
{
  "id": "39f6b093-4b42-4629-9fdc-9366d5a22020",
  "object": "chat.completion",
  "created": 1789336276,
  "model": "deepseek-flash",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "",
        "reasoning_content": "We need: find lowest stock item, then price. First call lowest_stock_item.",
        "tool_calls": [
          {
            "index": 0,
            "id": "call_00_YaL61ZhzZgMnSbF9PmBV2266",
            "type": "function",
            "function": {
              "name": "lowest_stock_item",
              "arguments": "{}"
            }
          }
        ]
      },
      "logprobs": null,
      "finish_reason": "tool_calls"
    }
  ],
  "usage": {
    "prompt_tokens": 375,
    "completion_tokens": 43,
    "total_tokens": 418,
    "prompt_tokens_details": {
      "cached_tokens": 128
    },
    "completion_tokens_details": {
      "reasoning_tokens": 18
    },
    "prompt_cache_hit_tokens": 128,
    "prompt_cache_miss_tokens": 247
  },
  "system_fingerprint": "aeb56401ca74e127821c4f9126dcb669"
}
reply
rolecontent
[0]ai
lowest_stock_item({})
tool lowest_stock_item · 0.6ms · returned: butter
args {}
result {"value": "butter"}
turn 2 · 1049.5ms · 432 in / 44 out · asked for: price_of
model live · 1049.0ms (model provider 1040.1 · library 8.9) · 432 in / 44 out · asked for: price_of
context sent — 4 message(s)
rolecontent
[0]systemYou answer briefly and plainly. Use the tools you are given.
[1]humanWhatever we are lowest on -- what does one of them cost?
[2]ai
lowest_stock_item({})
[3]toolbutter
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-length1005
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": "Whatever we are lowest on -- what does one of them cost?",
      "role": "user"
    },
    {
      "content": null,
      "role": "assistant",
      "tool_calls": [
        {
          "type": "function",
          "id": "call_00_YaL61ZhzZgMnSbF9PmBV2266",
          "function": {
            "name": "lowest_stock_item",
            "arguments": "{}"
          }
        }
      ],
      "reasoning_content": "We need: find lowest stock item, then price. First call lowest_stock_item."
    },
    {
      "content": "butter",
      "role": "tool",
      "tool_call_id": "call_00_YaL61ZhzZgMnSbF9PmBV2266"
    }
  ],
  "model": "deepseek-flash",
  "stream": false,
  "tools": [
    {
      "type": "function",
      "function": {
        "name": "lowest_stock_item",
        "description": "Which item there is least of in stock.",
        "parameters": {
          "properties": {},
          "type": "object"
        }
      }
    },
    {
      "type": "function",
      "function": {
        "name": "price_of",
        "description": "The current shelf price of one of an item, in pounds.",
        "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:51:17 GMT
serverelb
strict-transport-securitymax-age=31536000; includeSubDomains; preload
transfer-encodingchunked
varyorigin, access-control-request-method, access-control-request-headers
via1.1 e5eb6c7f102110906ece71324dc7e664.cloudfront.net (CloudFront)
x-amz-cf-idgfTSCrKF6ycERa61UxnDkbT5EkTjI2E6Iiz2MldaNSNBvW9Ulune3g==
x-amz-cf-popDEN52-P3
x-cacheMiss from cloudfront
x-content-type-optionsnosniff
x-ds-trace-id73ea735e578de407ce9d48073effc9c1
{
  "id": "de060aeb-39c0-4c94-81e0-2a2189803bad",
  "object": "chat.completion",
  "created": 1789336277,
  "model": "deepseek-flash",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "",
        "reasoning_content": "Now price of butter.",
        "tool_calls": [
          {
            "index": 0,
            "id": "call_00_DTbrz0gP6JLLzx7xD9Mk3535",
            "type": "function",
            "function": {
              "name": "price_of",
              "arguments": "{\"item\": \"butter\"}"
            }
          }
        ]
      },
      "logprobs": null,
      "finish_reason": "tool_calls"
    }
  ],
  "usage": {
    "prompt_tokens": 432,
    "completion_tokens": 44,
    "total_tokens": 476,
    "prompt_tokens_details": {
      "cached_tokens": 256
    },
    "completion_tokens_details": {
      "reasoning_tokens": 5
    },
    "prompt_cache_hit_tokens": 256,
    "prompt_cache_miss_tokens": 176
  },
  "system_fingerprint": "aeb56401ca74e127821c4f9126dcb669"
}
reply
rolecontent
[0]ai
price_of({"item": "butter"})
tool price_of · 0.5ms · given: item=butter · returned: 3.10
args {"item": "butter"}
result {"value": "3.10"}
turn 3 · 1013.0ms · 491 in / 18 out · responded with: Butter is what you're lowest on, and one costs £3.10.
model live · 1013.0ms (model provider 1005.0 · library 8.0) · 491 in / 18 out · responded with: Butter is what you're lowest on, and one costs £3.10.
context sent — 6 message(s)
rolecontent
[0]systemYou answer briefly and plainly. Use the tools you are given.
[1]humanWhatever we are lowest on -- what does one of them cost?
[2]ai
lowest_stock_item({})
[3]toolbutter
[4]ai
price_of({"item": "butter"})
[5]tool3.10
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-length1310
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": "Whatever we are lowest on -- what does one of them cost?",
      "role": "user"
    },
    {
      "content": null,
      "role": "assistant",
      "tool_calls": [
        {
          "type": "function",
          "id": "call_00_YaL61ZhzZgMnSbF9PmBV2266",
          "function": {
            "name": "lowest_stock_item",
            "arguments": "{}"
          }
        }
      ],
      "reasoning_content": "We need: find lowest stock item, then price. First call lowest_stock_item."
    },
    {
      "content": "butter",
      "role": "tool",
      "tool_call_id": "call_00_YaL61ZhzZgMnSbF9PmBV2266"
    },
    {
      "content": null,
      "role": "assistant",
      "tool_calls": [
        {
          "type": "function",
          "id": "call_00_DTbrz0gP6JLLzx7xD9Mk3535",
          "function": {
            "name": "price_of",
            "arguments": "{\"item\": \"butter\"}"
          }
        }
      ],
      "reasoning_content": "Now price of butter."
    },
    {
      "content": "3.10",
      "role": "tool",
      "tool_call_id": "call_00_DTbrz0gP6JLLzx7xD9Mk3535"
    }
  ],
  "model": "deepseek-flash",
  "stream": false,
  "tools": [
    {
      "type": "function",
      "function": {
        "name": "lowest_stock_item",
        "description": "Which item there is least of in stock.",
        "parameters": {
          "properties": {},
          "type": "object"
        }
      }
    },
    {
      "type": "function",
      "function": {
        "name": "price_of",
        "description": "The current shelf price of one of an item, in pounds.",
        "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:51:18 GMT
serverelb
strict-transport-securitymax-age=31536000; includeSubDomains; preload
transfer-encodingchunked
varyorigin, access-control-request-method, access-control-request-headers
via1.1 7b328e4408e2a8cfbffacb28f807717e.cloudfront.net (CloudFront)
x-amz-cf-idr-NYI9b-5bcaH-GAfEMQwGzO3Cal7nBOVin3I60sJKWPwnCUZs5JNw==
x-amz-cf-popDEN53-P6
x-cacheMiss from cloudfront
x-content-type-optionsnosniff
x-ds-trace-idf6012f17ea45073caef47d415d41e79a
{
  "id": "a737cf84-2e11-42cc-895a-d6f7c1c67a63",
  "object": "chat.completion",
  "created": 1789336278,
  "model": "deepseek-flash",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "Butter is what you're lowest on, and one costs \u00a33.10.",
        "reasoning_content": ""
      },
      "logprobs": null,
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 491,
    "completion_tokens": 18,
    "total_tokens": 509,
    "prompt_tokens_details": {
      "cached_tokens": 256
    },
    "completion_tokens_details": {
      "reasoning_tokens": 0
    },
    "prompt_cache_hit_tokens": 256,
    "prompt_cache_miss_tokens": 235
  },
  "system_fingerprint": "aeb56401ca74e127821c4f9126dcb669"
}
reply
rolecontent
[0]aiButter is what you're lowest on, and one costs £3.10.
ended {"reason": "no_tool_calls"}