Embedded function calling is (currently) designed as an all-in-one solution. runWithTools maintains

Embedded function calling is (currently) designed as an all-in-one solution. runWithTools maintains and adds to a copy of the message history internally, and the final output is always a plain response. (I.e. not a tool call.) When the model's response is a tool call, the matching user-defined function is called and both the tool call and the function's (stringified) return value is appended to the history.

In your example, the internal message history might look something like this after the first "iteration".
  { role: "system", content: "Put user given values in KV" },
  { role: "user", content: "Set the value of banana to yellow." },
  { role: "assistant", content: '{"arguments":{"key":"banana","value":"yellow"},"name":"KV update"}' },
  { role: "tool", "content": '"Successfully updated key-value pair in database."', "name": "KV update" }

Inference is run again with this as input and the result might be something like 'I have successfully updated the key-value pair for you. The value of "banana" is now set to "yellow" in the database.'
Was this page helpful?