RUNLOCALAIv38
->Will it run?Best GPUCompareTroubleshootStartLearnPulseModelsHardwareToolsBench
Run check
RUNLOCALAI

Independently operated catalog for local-AI hardware and software. Hand-written verdicts. Source-cited claims. Reproducible commands when we have them.

OP·Fredoline Eruo
DIR
  • Models
  • Hardware
  • Tools
  • Benchmarks
TOOLS
  • Will it run?
  • Compare hardware
  • Cost vs cloud
  • Choose my GPU
  • Prompting kits
  • Quick answers
REF
  • All buyer guides
  • Learn local AI
  • Methodology
  • Glossary
  • Errors KB
  • Trust
EDITOR
  • About
  • Author
  • How we make money
  • Editorial policy
  • Contact
LEGAL
  • Privacy
  • Terms
  • Sitemap
MAIL · MONTHLY DIGEST
Get monthly local AI changes
Monthly recap. No spam.
DISCLOSURE

Some links on this site are affiliate links (Amazon Associates and other first-class retailers). When you buy through them, we earn a small commission at no extra cost to you. Affiliate links do not influence our verdicts — there are cards we rate highly that we don't have affiliate relationships with, and cards that sell well that we refuse to recommend. Read more →

© 2026 runlocalai.coIndependently operated
RUNLOCALAI · v38
  1. >
  2. Home
  3. /Learn
  4. /Courses
  5. /DeepSeek R1 and Reasoning Models
  6. /Ch. 15
DeepSeek R1 and Reasoning Models

15. R1 with Tools

Chapter 15 of 18 · 25 min
KEY INSIGHT

Tool integration extends reasoning models to real-time data and external capabilities. The model reasons about tool use, but operations must handle schema definition, execution, error handling, and retry logic.

DeepSeek R1 excels at reasoning but lacks real-time information access. Tool integration extends reasoning models beyond static knowledge to live data, calculations, and external services.

The Tool-Augmented Architecture

A reasoning model with tools doesn't call them automatically—it reasons about when and how to use them. The architecture separates concerns: the model handles "what should I do" reasoning, while tools handle "execute this operation" execution.

User Query → Reasoning Model → Decide to use tool → Tool execution → Result
                                                            ↓
                                                    Return to model
                                                            ↓
                                                    Continue reasoning
                                                            ↓
                                                    Final answer

This loop continues until the model decides it has sufficient information to answer.

Defining Tool Schemas

Tools expose functionality through JSON schemas that the model reads and interprets:

# Example tool schema for a calculator function
def get_calculator_schema():
    return {
        "name": "calculate",
        "description": "Perform mathematical calculations with arbitrary precision",
        "parameters": {
            "type": "object",
            "properties": {
                "expression": {
                    "type": "string",
                    "description": "Mathematical expression to evaluate"
                }
            },
            "required": ["expression"]
        }
    }

# Example tool schema for a search function
def get_search_schema():
    return {
        "name": "web_search",
        "description": "Search the web for current information",
        "parameters": {
            "type": "object",
            "properties": {
                "query": {
                    "type": "string",
                    "description": "The search query"
                }
            },
            "required": ["query"]
        }
    }

The model reads these schemas at inference time and decides which tool matches the current reasoning need.

Tool Selection Reasoning

The model must decide which tool to use. This requires both availability awareness and selection reasoning:

SYSTEM_PROMPT = """You have access to these tools:
- calculate(expression): Evaluate mathematical expressions
- web_search(query): Search for current information
- get_current_time(): Get current date and time

Decide which tool (if any) to use based on your reasoning needs.
If you need computation, use calculate.
If you need information after your training cutoff, use web_search.
When uncertain, prefer verification over assumption.
"""

Common failure mode: The model calls tools that don't exist because the schema was malformed or the model misunderstood capabilities. Always provide schema examples during inference.

Implementing Tool Calling

def call_tool(tool_name, parameters):
    """Execute a tool and return results"""
    tool_registry = {
        'calculate': calculate,
        'eval_math': calculate,  # Aliases help
        'web_search': web_search,
        'search': web_search,
        'get_current_time': get_current_time
    }
    
    if tool_name not in tool_registry:
        return {"error": f"Unknown tool: {tool_name}"}
    
    tool_func = tool_registry[tool_name]
    try:
        result = tool_func(**parameters)
        return {"success": True, "result": result}
    except Exception as e:
        return {"success": False, "error": str(e)}

Handling Tool Errors

Tool execution fails. The model must reason past failures:

  1. Network errors: Retry with exponential backoff, then gracefully degrade
  2. Invalid parameters: Log the attempted call, return error to model, let model reformulate
  3. Tool unavailable: Skip to alternative approach or inform user

A common failure pattern is models that treat tool errors as final. "The search failed" should trigger "try alternative search terms" not "I cannot answer."

def execute_with_fallback(tool_name, parameters, max_retries=2):
    for attempt in range(max_retries + 1):
        result = call_tool(tool_name, parameters)
        if result.get('success'):
            return result
        
        # Exponential backoff for transient errors
        if attempt < max_retries:
            wait_time = 2 ** attempt
            time.sleep(wait_time)
    
    return {"error": "max_retries_exceeded", "tool": tool_name}

Real-Time Data Integration

For applications requiring current data (prices, weather, schedules), tool integration is necessary:

def stock_price_inquiry(symbol):
    return web_search(f"{symbol} stock price today")

def weather_inquiry(location):
    return web_search(f"weather forecast {location}")

When combined with reasoning, the model can answer complex queries: "Should I buy TechCorp if the meeting is tomorrow and there's a storm forecast for their headquarters?"

EXERCISE

Define three tools for your application domain. Write tool schemas with descriptions specific enough for a reasoning model to know when to use each. Test by prompting the model to decide which tool to use for 10 sample queries.

← Chapter 14
Verification Loops
Chapter 16 →
Production Deployment