Working with tools

Tools let your flows call APIs, run code, search the web, generate images, and connect to external services.

Tool types overview

Use the following tool types in a prompt step:

TypeDescriptionUse case
ExternalSend HTTP requests.Integrate with a REST API.
CustomRun code in the Runtype sandbox.Transform data or perform calculations.
FlowCall another flow as a tool.Reuse a multi-step workflow.
Built-inUse provider-specific tools.Generate images or search the web.
MCPConnect to Model Context Protocol (MCP) servers.Use tools from external services.

Add tools to a flow

Configure tools in the tools object of a prompt step. The following examples attach a saved tool to a prompt step.

Use the TypeScript SDK to attach a saved tool:

TypeScript SDK
1import { FlowBuilder, RuntypeClient } from '@runtypelabs/sdk'
2
3const client = new RuntypeClient({
4 apiKey: process.env.RUNTYPE_API_KEY,
5})
6
7const result = await new FlowBuilder()
8 .createFlow({ name: 'Agent with tools' })
9 .prompt({
10 name: 'Agent',
11 model: 'gpt-5.4',
12 userPrompt: 'Help the user with their request',
13 tools: {
14 toolIds: ['YOUR_TOOL_ID'],
15 maxToolCalls: 10,
16 toolCallStrategy: 'auto',
17 },
18 })
19 .run(client, { streamResponse: true })

Use the Python SDK to attach the same saved tool:

Python SDK
1import os
2
3from runtype import RuntypeClient
4
5client = RuntypeClient(api_key=os.environ["RUNTYPE_API_KEY"])
6
7for event in client.dispatch({
8 "flow": {
9 "name": "Agent with tools",
10 "steps": [{
11 "type": "prompt",
12 "config": {
13 "model": "gpt-5.4",
14 "userPrompt": "Help the user with their request",
15 "tools": {
16 "toolIds": ["YOUR_TOOL_ID"],
17 "maxToolCalls": 10,
18 "toolCallStrategy": "auto"
19 }
20 }
21 }]
22 }
23}):
24 print(event)

Send the same flow definition with cURL:

cURL
$curl https://api.runtype.com/v1/dispatch \
> -H "Authorization: Bearer YOUR_API_KEY" \
> -H "Content-Type: application/json" \
> -d '{
> "flow": {
> "name": "Agent with tools",
> "steps": [{
> "type": "prompt",
> "config": {
> "model": "gpt-5.4",
> "userPrompt": "Help the user with their request",
> "tools": {
> "toolIds": ["YOUR_TOOL_ID"],
> "maxToolCalls": 10,
> "toolCallStrategy": "auto"
> }
> }
> }]
> }
> }'

Replace the placeholders in these examples with your values:

  • YOUR_TOOL_ID: The ID of the saved tool that you want to use.
  • YOUR_API_KEY: Your Runtype API key.
  • RUNTYPE_API_KEY: The environment variable that contains your Runtype API key.

Configure tool call strategy

Set toolCallStrategy to control how the model uses the available tools. The following table describes each strategy.

StrategyBehavior
autoThe model chooses whether to call a tool.
requiredThe model must call an available tool.
noneThe model cannot call tools.

Use required only for one forced tool call, such as a structured-output or routing tool. Set maxToolCalls to 1 and omit an agent loop.

Don’t combine required with maxToolCalls greater than 1 or loopConfig.maxTurns greater than 1. The model is then forced to call a tool on each step and cannot finish with a text answer, so the output is empty.

For multi-step agents, set toolCallStrategy to auto.

Use external tools

External tools send HTTP requests to an API. Define the tool’s parameters with JSON Schema and configure the request:

External tool
1const externalTool = {
2 name: 'get_weather',
3 description: 'Get the weather for a city',
4 toolType: 'external',
5 parametersSchema: {
6 type: 'object',
7 properties: {
8 city: { type: 'string', description: 'City name' },
9 },
10 required: ['city'],
11 },
12 config: {
13 url: 'https://api.example.com/weather?city={{city}}',
14 method: 'GET',
15 headers: {
16 Authorization: 'Bearer {{secret:WEATHER_API_KEY}}',
17 },
18 },
19}

Use {{city}} in the URL or headers to insert the matching tool-call parameter. Use {{secret:WEATHER_API_KEY}} to resolve the managed secret named WEATHER_API_KEY.

Create custom tools

Runtype runs custom tool code in a sandbox. The following tool calculates a discount and returns the original price, discounted price, and savings:

Custom tool
1const customTool = {
2 name: 'calculate_discount',
3 description: 'Calculate a discounted price',
4 toolType: 'custom',
5 parametersSchema: {
6 type: 'object',
7 properties: {
8 price: { type: 'number' },
9 discount: { type: 'number' },
10 },
11 required: ['price', 'discount'],
12 },
13 config: {
14 code: `
15 const { price, discount } = parameters;
16 const discounted = price * (1 - discount / 100);
17 return {
18 original: price,
19 discounted: discounted.toFixed(2),
20 savings: (price - discounted).toFixed(2),
21 };
22 `,
23 timeout: 5000,
24 allowedApis: [],
25 },
26}

Use built-in tools

Built-in tools provide provider and platform capabilities. Use IDs that match the tool and the model in your prompt:

Built-in tools
1tools: {
2 toolIds: [
3 'builtin:gpt-image-2',
4 'builtin:openai_web_search',
5 ],
6}

Use MCP server tools

Model Context Protocol (MCP) servers expose tools through a standard protocol. Configure an MCP server as a saved server or as a runtime server.

Use saved MCP servers

Save an MCP server in your account, then reference its tools by ID:

Saved MCP server tools
1tools: {
2 toolIds: [
3 'mcp:YOUR_SERVER_NAME:YOUR_TOOL_NAME',
4 ],
5}

The tool ID format is mcp:SERVER_NAME:TOOL_NAME. Replace YOUR_SERVER_NAME with the saved server name and YOUR_TOOL_NAME with the MCP tool name.

Use runtime MCP servers

Pass an MCP server configuration inline when the server or its credentials vary by request:

Runtime MCP server
1tools: {
2 mcpServers: [
3 {
4 id: 'YOUR_MCP_SERVER_ID',
5 url: 'https://example.com/mcp',
6 auth: {
7 type: 'bearer',
8 token: process.env.MCP_TOKEN,
9 },
10 timeout: 30000,
11 },
12 ],
13}

Replace YOUR_MCP_SERVER_ID with the server ID for this request. Set MCP_TOKEN to the token that the MCP server accepts.

Use runtime tools

Define a tool inline without saving it to your account. The following example sends a request to an external API:

Runtime tool
1const runtimeTool = {
2 name: 'fetch_user',
3 description: 'Fetch a user by ID',
4 toolType: 'external',
5 parametersSchema: {
6 type: 'object',
7 properties: {
8 userId: { type: 'string' },
9 },
10 required: ['userId'],
11 },
12 config: {
13 url: 'https://api.example.com/users/{{userId}}',
14 method: 'GET',
15 },
16}
17
18const tools = {
19 runtimeTools: [runtimeTool],
20}

Runtime tools fit these use cases:

  • Dynamic tool definitions.
  • Testing a tool before saving it.
  • User-provided tool configurations.

Combine tool types

Add saved tools, built-in tools, runtime tools, and runtime MCP servers to one prompt. The following example combines these tool sources:

Combined tool configuration
1tools: {
2 toolIds: [
3 'YOUR_TOOL_ID',
4 'builtin:gpt-image-2',
5 'mcp:YOUR_SERVER_NAME:YOUR_TOOL_NAME',
6 ],
7 runtimeTools: [
8 {
9 name: 'fetch_user',
10 description: 'Fetch a user by ID',
11 toolType: 'external',
12 parametersSchema: {
13 type: 'object',
14 properties: {
15 userId: { type: 'string' },
16 },
17 required: ['userId'],
18 },
19 config: {
20 url: 'https://api.example.com/users/{{userId}}',
21 method: 'GET',
22 },
23 },
24 ],
25 mcpServers: [
26 {
27 id: 'YOUR_MCP_SERVER_ID',
28 url: 'https://example.com/mcp',
29 auth: {
30 type: 'bearer',
31 token: process.env.MCP_TOKEN,
32 },
33 timeout: 30000,
34 },
35 ],
36 maxToolCalls: 15,
37 toolCallStrategy: 'auto',
38}

Replace YOUR_TOOL_ID, YOUR_SERVER_NAME, YOUR_TOOL_NAME, and YOUR_MCP_SERVER_ID with your values. Set MCP_TOKEN to the runtime MCP server token.

Pass secrets

Keep API keys out of tool configuration. Store each credential on the Secrets page in Settings, then reference its managed name in the tool configuration:

Managed secret reference
1headers: {
2 Authorization: 'Bearer {{secret:WEATHER_API_KEY}}',
3}

Replace WEATHER_API_KEY with the name of the managed secret in your account. Hosted flow execution ignores the top-level secrets map. Use {{secret:NAME}}, where NAME is the managed secret name, for every flow credential. Managed secret values are encrypted at rest and are not logged or returned in responses.

Apply best practices

Use these practices when you configure tools:

Set maxToolCalls to limit tool-call rounds. Use a lower value for short tasks and a higher value for tasks that need more steps.

Describe the tool’s inputs, outputs, and intended use. Clear descriptions provide the model with information for tool selection and calls.

Set toolCallStrategy to auto for multi-step prompts and agents. The model chooses whether to call a tool and returns text when it finishes. Use required only for one forced tool call with maxToolCalls set to 1.

Plan for failed external API requests. Add flow logic that handles the response and continues or stops according to your use case.

Next steps

Use these guides to continue working with tools: