Skip to main content

Quick start example

Export your API key as an environment variable in your terminal.

Tool calling parameters

  • tool_choice Use tool_choice to enforce the tool calling behavior that you desire. By default, tool_choice is set to "auto". This means that the model will choose to either emit tool calls or output text. if set to "none", tool calls are prevented. if set to "required", the model is forced to emit a tool call in that turn. Use this to enforce the behavior you desire. Just add tool_choice to the payload to use it. See below for an example:
  • strict Use strict to force the model to output the correct tool calling schema that you have specified. We recommend setting this field to True for best results. To do this, add "strict": True to your tool definition. See below for an example.

Coding agent tool calling demo

See how you can use tool calling with Mercury 2 with the following simple coding agent example. We assume a small codebase of the following structure:

Define tools

First, define your tools. Here, we define two tools for a read-only coding agent: list_directory and read_file.

Prompt your model

We prompt the model to search the code base for a specific function and return its definition to the user.

Run your agent

Results

When we run the above code, we get the following results: Step 1: Model’s tool call:
Tool call output:
Step 2: Model’s tool call:
Tool call output:
Step 3: Model’s output:
See the full demo’s code in this cookbook. Currently, the Inception API only supports sequential tool calling. Parallel tool calling will be supported soon!