Implement generative AI and agentic solutions 2.2 Build agents by using Foundry

You add a get_order_status function definition to a chat completions request, and the…

Study guide skill: Build agents that integrate retrieval, function-calling, and conversation memory

Question B1-017

You add a get_order_status function definition to a chat completions request, and the model responds with a tool call. What happens next?

Select one answer.

  • A The tool call is ignored unless tool_choice is set to none
  • B The model service runs the function in a sandbox and returns the final answer
  • C Azure OpenAI calls your function's HTTP endpoint automatically
  • D Your application runs the function with the returned arguments and sends the result back to the model in a follow-up message ✓ Correct answer

Answer: D

With function calling, the model only generates the function name and structured arguments. Your application executes the function and returns the result to the model, so you stay in control of the actions taken. The service doesn't execute your code or call your endpoints for you.

Deep dive

How it works

With function calling, you describe functions in the request's tools parameter, and the model decides from the prompt's context whether to call any of them. When it does, it returns a JSON object with the arguments. The model generates the function call and its structured arguments, and your application executes the function and returns the result, so you stay in control of the actions taken.

The loop has three steps:

  1. Call the Chat Completions API with your functions and the user's input.
  2. Use the model's response to call your API or function.
  3. Call the Chat Completions API again with your function's result to get a final response.

In the follow-up request, you append the assistant message that contains the tool call, then add a message with role set to tool and a tool_call_id that matches the call's id. With parallel function calling, one response can hold several tool calls, each with its own id, and you answer each one with its own message.

The other options, and when you'd use them

  • The call is ignored unless tool_choice is none: It's the opposite. tool_choice set to none forces a user-facing message instead of a tool call. The default, auto, lets the model decide whether to call a function and which one, and you can name a specific tool to force that call.
  • The service runs the function in a sandbox: That describes Code Interpreter, an agent tool that runs Python code the model writes in a sandboxed environment. That's a different tool from function calling, where your app runs the function.
  • Azure OpenAI calls your HTTP endpoint automatically: In Chat Completions function calling, your application runs the function and sends the result back. That's what keeps you in control of the actions taken.

Exam tip

The model proposes and your app executes. In Chat Completions, use tools and tool_choice. The older functions and function_call parameters are deprecated.

References

Last reviewed:

Ready to test yourself? The quiz asks this and every other AI-103 question, with instant feedback. Practice this in a quiz →

All Generative AI & agents questions · AI-103 study guide

Thanks for your feedback!