Let models invoke your functions to fetch live data and take actions.
Tool calling (also called function calling) lets an AI model request that your application execute a specific function and return the result. The model decides when to use a tool, what arguments to pass, and how to incorporate the result into its final response.
Routeway supports the OpenAI tool calling format. Any code that works with OpenAI function calling works with Routeway unchanged — just swap the base_url.
Models may request multiple tools simultaneously. Iterate over message.tool_calls, execute each in parallel, and send all results back before requesting the final answer.
import asyncioimport json# After receiving a response with multiple tool_calls:async def execute_all_tools(tool_calls): results = await asyncio.gather(*[run_tool(tc) for tc in tool_calls]) return resultsasync def run_tool(tool_call): args = json.loads(tool_call.function.arguments) # dispatch to the right function... return {"tool_call_id": tool_call.id, "result": "..."}
Send all role: "tool" messages in the same follow-up request. The model needs all results together to compose its final answer.
Tool names should clearly describe the action. The model uses the name and description to decide when to call the tool.
// Good"name": "search_knowledge_base"// Too vague"name": "search"
Write clear descriptions
Descriptions directly influence the model’s decision to call a tool. Be specific about what the tool does and when to use it.
"description": "Search the internal knowledge base for articles about a topic. Use this when the user asks about product features, pricing, or support issues."
Keep schemas narrow
Avoid free-form string fields when enums or typed fields work. Tight schemas reduce parsing errors and improve reliability.
Don’t expose tools with dangerous side effects without application-level guards. The model can call tools in unexpected sequences. Always validate arguments before executing writes, deletions, or external API calls.
Forgetting to replay the assistant message — the messages array must include the assistant turn containing tool_calls before any role: "tool" messages.
Parsing arguments before the stream ends — when streaming, accumulate delta.tool_calls fragments before calling JSON.parse.
Assuming a final text response always follows — on the first turn, the model may return only tool calls with no content. Handle both cases.