Return a tool result to DeepSeek
Follow a weather example: your application supplies the result that the model describes.
In this article
Prepare the API client
This exercise is for developers using Python. Follow the setup instructions: obtain a DeepSeek API key, install the OpenAI SDK with pip3 install openai, and configure its client with your key and the DeepSeek base URL shown there. Use deepseek-flash; a non-streaming request returns the response for inspection together.
Choose non-thinking mode explicitly. In the OpenAI SDK, pass extra_body={"thinking":{"type":"disabled"}} to the completion request. Thinking is enabled by default; leaving the setting out does not select this exercise's mode. Thinking-mode tool conversations have different requirements for returning earlier reasoning content.
Inspect before executing
The API reference says the default choice with tools is automatic: the model may answer or request tools. Inspect message.tool_calls before expecting a call. Its function arguments are a JSON-formatted string, but may contain invalid JSON or parameters absent from your schema. Validate them in your code before invoking the function.
Hand back the example result
Use the non-thinking sample: declare get_weather with a required string location, then ask about Hangzhou. After a call arrives, append the assistant message, then a tool message whose tool_call_id matches that call, with the sample's fixed 24℃ result. Send the updated messages again. The model does not execute your function; this fixed value demonstrates the handoff, not actual weather.
As a practical check, compare the returned function name and argument fields with your declared schema. A fluent answer alone does not establish that the arguments passed validation.
Sources(4)
- SetupChecked:
- ModeChecked:
- Tool callsChecked:
- APIChecked:
Original CurioFuse editorial. A guide to explore and evaluate AI, without an implied product test.
