Skip to content

Tool Calling

Prompty separates tool definitions from tool implementations. Tool definitions live in .prompty frontmatter under tools. Tool implementations are supplied at runtime through per-call tool maps, global name registrations, or kind handlers.

When the model requests a tool call, runtimes resolve it in this order:

  1. Per-call tools passed to turn.
  2. Name registry entries registered with registerTool / register_tool / ToolDispatch.RegisterTool.
  3. Kind handlers registered with registerToolHandler / register_tool_handler / ToolDispatch.RegisterToolHandler.
  4. Wildcard kind handler ("*") when supported.
  5. Error if no implementation can handle the call.

Name registrations are for a specific tool name. Kind handlers are for a whole tool family such as function, prompty, mcp, openapi, or a custom kind.

Use the name registry when one callable should handle one named tool globally. Per-call tools still take priority.

import prompty
def get_weather(location: str) -> str:
return f"Sunny in {location}"
prompty.register_tool("get_weather", get_weather)
handler = prompty.get_tool("get_weather")
prompty.clear_tools()

Use kind handlers when a provider or extension owns a category of tools. Built-in handlers are registered for common kinds such as function, prompty, mcp, and openapi; runtimes can also register custom handlers.

import prompty
class MyToolHandler:
def execute_tool(self, tool, args, agent, parent_inputs):
return "handled"
async def execute_tool_async(self, tool, args, agent, parent_inputs):
return "handled"
prompty.register_tool_handler("my_kind", MyToolHandler())
handler = prompty.get_tool_handler("my_kind")
prompty.clear_tool_handlers()

For one-off agent turns, pass callables directly to turn. This is the highest priority and avoids global state.

result = prompty.turn(
"agent.prompty",
inputs={"question": "Weather?"},
tools={"get_weather": get_weather},
)

Tool bindings inject values from parent prompt inputs into tool arguments at execution time. Bound parameters should not be exposed as model-controllable schema parameters.

inputs:
- name: tenantId
kind: string
tools:
- kind: function
name: search_orders
bindings:
- name: tenantId
input: tenantId

If the model calls search_orders, the runtime merges tenantId from the prompt inputs into the tool arguments before executing the implementation.

For tool data shapes, see Tool, FunctionTool, PromptyTool, McpTool, and OpenApiTool.