MSBA-370 · Lesson 4 of 12 · 19 min

Tool use and function calling

▶ Video coming soon A video version of this lesson is on the way.

Lena arrived at the fourth session with a complaint. She had asked agent mode to find which trails had no reports in the last month, and it had answered by opening forty data files one at a time, slowly filling the conversation until it lost track of the question. "It did the right thing in the wrong way," she said. Priya agreed. "It used the tools it had. If you want it to work differently, give it a better tool." This lesson is about tools: how a model asks to use them, how to design them, how to choose and limit them, and how to handle the errors they produce.

The GH-600 domain on tool use and environment interaction carries the most weight on the exam, 20 to 25 percent. Its first skill is selecting and configuring agent tools: identifying the tools a task needs, configuring them, and configuring their permissions.

How function calling works

Models do not run code. Function calling, also called tool calling, is the convention by which a model asks the controller to run something on its behalf. The controller gives the model a list of tools, each with a name, a description and a schema that defines its parameters, usually written in JSON Schema. When the model decides a tool would help, it returns a structured request naming the tool and supplying arguments that fit the schema. The controller runs the tool and sends back the result, and the model continues.

A tool definition of the kind an MCP server publishes. The description tells the model when to use the tool; the schema constrains its arguments.
{
  "name": "list_stale_trails",
  "description": "Return trails with no hiker report since the given date. Use this instead of reading report files one by one.",
  "inputSchema": {
    "type": "object",
    "properties": {
      "since": { "type": "string", "format": "date", "description": "Earliest report date to count, YYYY-MM-DD" },
      "region": { "type": "string", "enum": ["fundy", "highlands", "valley", "all"] }
    },
    "required": ["since"]
  }
}
What a tool request from the model looks like in principle. Each product wraps this in its own message format.
{ "tool": "list_stale_trails", "arguments": { "since": "2026-10-01", "region": "all" } }

Two consequences follow. The model chooses tools from their descriptions, so a vague description leads to wrong choices. And the model fills in arguments from its understanding of the task, so a loose schema invites wrong arguments. Writing a tool is partly writing documentation for a reader that takes every word literally.

A sequence diagram with three lanes: model, controller and tool. The controller sends the task and tool list to the model. The model returns a tool request with arguments. The controller validates the arguments against the schema, checks permissions and calls the tool. The tool returns a result, which the controller trims if it is too long and sends back to the model. The model returns a final answer.
One function call from request to result.

Built-in tools

Copilot's agents come with built-in tools for the everyday work of software development. In editors and in Copilot CLI these include reading and editing files, searching the workspace by text and by meaning, listing directories, running terminal commands and reading their output, and fetching web content. The cloud agent has similar tools inside its cloud environment, plus the GitHub MCP server and a browser automation server configured by default, which let it read issues and pull requests and look at a web page it has built. Tool names differ between products and versions, so the exam asks about what kinds of tools exist and how to control them rather than about exact names.

Designing good tools

Most teams will not write many tools, but every team chooses among them, and the same principles apply to both. Seraphine shared the design rules Skerry's platform team used when it built internal MCP servers.

Tool design principles used by Skerry's platform team.
PrincipleWhy it mattersExample
One clear job per toolThe model picks tools by purposelist_stale_trails rather than query_anything
Descriptions say when to use itPrevents the slow, generic path"Use this instead of reading report files"
Tight schemasFewer invalid argumentsEnums for regions, a date format for dates
Small, structured resultsSaves context and keeps the goal visibleReturn ten rows and a count, not every row
Read-only unless neededLimits damage from a wrong choiceSeparate read tools from write tools
Helpful errorsThe model can correct itself"region must be one of fundy, highlands, valley, all"

The result size rule surprised the team most. A tool that returns a 5,000-line log fills the context window, pushes the original task further from the model's attention and costs more on every following step. Good tools summarize, paginate or filter. When an agent must read something large, the controller usually truncates the result and tells the model it was truncated, so the model can ask for a narrower slice.

Worked problem

Choosing tools for a task

Malik wants an agent to answer: which trail pages show a closure that has since been reopened? The data is in report files in the TrailCheck repository, and the deployed site shows each page. Which tools should the agent have?

Show solution
  1. It needs to read report data, so a file-reading or search tool, or better a purpose-built query tool like list_stale_trails, is required.
  2. It needs to see what the site shows, so a web fetch or browser tool is useful.
  3. It does not need to edit files, run arbitrary commands or create pull requests, because the task is a question.
  4. Giving only read tools keeps the context small and makes a harmful action impossible.

Too many tools

It is tempting to connect every available tool. More tools mean more descriptions in every prompt, more chances to choose the wrong one, and more ways to cause harm. GitHub's own guidance for the GitHub MCP server is to enable only the toolsets you need, such as issues and pull requests, rather than all of them. Editors let users switch individual tools on and off for agent mode, and custom agents, covered in lesson 9, can list exactly which tools they may use. Tidewater's rule became: start with the fewest tools that can do the job, and add one only when a session log shows the agent needed it.

Tool permissions

The third part of the skill is configuring tool permissions. Permissions answer two questions: may the agent use this tool at all, and does it need a person's approval each time? In agent mode the editor asks before running terminal commands unless the user has approved them, and users can approve a command once, for the session, or always. Copilot CLI asks before running commands or changing files, and its documented options let users pre-approve or deny specific tools when it starts, for example allowing git commands while denying file deletion. In the cloud agent, permissions come from the environment: what the GitHub token can do, which network destinations the firewall allows and which MCP servers are configured.

An illustration of Copilot CLI tool permission options. Check copilot --help for the exact syntax in your version.
# Start Copilot CLI with some tools pre-approved and others denied
copilot --allow-tool 'shell(git status)' \
        --allow-tool 'shell(npm test)' \
        --deny-tool 'shell(rm)' \
        --deny-tool 'shell(git push)'
Tidewater's tool permission defaults for local agents.
Tool typeTidewater defaultReason
Read files and searchAllowedNo side effects
Run tests and lintersAllowedSide effects limited to the workspace
Edit files in the workspaceAllowed, reviewed afterwardsChanges can be undone before commit
Install packagesApproval each timeSupply chain risk
Delete files or rewrite historyApproval each timeHard to undo
Push, deploy or call external servicesDenied in local agentsDone through reviewed workflows instead

When tools fail

Tools fail all the time: a test command times out, a file is missing, a network call is blocked, an argument is invalid. The GH-600 outline asks candidates to implement error handling and retries. At the tool level that means returning errors as information the model can act on rather than crashing the session. A good error says what went wrong and what would work. Retrying is the controller's job for transient failures such as a network timeout, with a limit on attempts. It is the model's job for logical failures such as a wrong argument, which it can correct after reading the error. Repeated failure of the same kind is a signal to stop and ask a person rather than to loop.

Lena rewrote her stale-trails request after the session, this time with the purpose-built tool that Malik had added to a small local MCP server. The agent called it once, received twelve trails, and answered in a few seconds. The forty-file version had taken several minutes and nearly a tenth of the context window.

Tool descriptions are prompts

A model chooses tools by reading their names and descriptions, so those descriptions are part of the prompt as much as the instructions are. A description that says only "runs tests" leaves the model to guess which tests, how long they take and what the output means. A description that says "runs the unit tests for one file and returns only failing test names and messages" tells it when to use the tool and what to expect back. Malik rewrote the descriptions of the two small tools he had added to open-trail-report's development setup and saw the agent call them correctly on the first try far more often.

Parameter descriptions matter just as much. A parameter called path with no description could be absolute or relative, a file or a folder. A parameter called test_file described as "path to a test file relative to the repository root, such as test/units.test.js" removes the ambiguity. Types and allowed values in the schema help too: an enumeration of three allowed formats is easier for a model to use correctly than a free text field.

Tool results that help

What a tool returns shapes the next step. A test runner that prints thousands of lines of passing tests buries the one failure the agent needs. A search that returns whole files fills the context with irrelevant code. Good tool results are short, structured and focused on what the agent will do next: the failing test names and messages, the matching lines with a little surrounding context, a clear error that says what went wrong and what to try. When a result must be long, the controller or the tool can trim it and say so, so that the agent knows to ask for more if it needs it.

An illustrative tool definition with a description written for the model.
{
  "name": "run_unit_test",
  "description": "Runs the unit tests in one test file and returns only failures. Use after editing a source file to check its tests.",
  "parameters": {
    "type": "object",
    "properties": {
      "test_file": {
        "type": "string",
        "description": "Path relative to the repository root, such as test/units.test.js"
      }
    },
    "required": ["test_file"]
  }
}

Read tools and write tools

Tools fall into two broad groups. Read tools observe without changing anything: reading files, searching, listing issues, fetching documentation. Write tools change something: editing files, running commands that modify the environment, creating branches, commenting on issues, calling APIs that update data. The distinction drives permissions. Read tools inside the agent's own environment rarely need approval. Write tools that affect anything outside the sandbox, such as posting a comment that other people will see, deserve more thought. Some tools are both, and the safest assumption about a terminal command is that it can do anything the account running it can do.

Testing tools before agents use them

Tidewater treated a new tool like any other piece of code. Before an agent could use it, someone called it by hand with normal, empty and malformed arguments, checked that errors were clear, and checked that results stayed small. Lena found that one internal search tool returned an empty list both when nothing matched and when the search service was unreachable. To an agent the two looked the same, so it confidently reported that no matches existed. A clear error for the second case fixed the problem.

Tools in the GH-600 outline

The tool use domain is the most heavily weighted in the GH-600 study guide, and its skills map closely onto this lesson: choosing and configuring tools for a task, designing tool interfaces, configuring MCP servers, and controlling how agents interact with environments. Exam questions in this area tend to describe a situation, such as an agent choosing the wrong tool or flooding its context with output, and ask for the best fix. The answers usually involve narrower tools, clearer descriptions, smaller results or tighter permissions, rather than a different model or longer instructions. Malik made flash cards from each mistake he saw in session logs, which turned out to be good practice for that style of question.

Common mistakes

  • MistakeWriting tool descriptions that say what the tool is but not when to use it.

    InsteadTell the model when to prefer the tool and what it returns.

  • MistakeReturning huge tool results.

    InsteadSummarize, filter or paginate so the context stays focused.

  • MistakeEnabling every toolset on every server.

    InsteadEnable only the toolsets and tools the task needs.

  • MistakeApproving all commands always to save time.

    InsteadPre-approve safe commands, require approval for risky ones and deny those that should go through reviewed workflows.

Summary and key terms

  • In function calling the model returns a structured tool request; the controller validates, runs and returns the result.
  • Models choose tools from descriptions and fill arguments from schemas, so both must be precise.
  • Good tools do one job, return small structured results, are read-only where possible and give helpful errors.
  • Fewer tools improve choice, reduce context use and limit harm; enable only the toolsets needed.
  • Tool permissions decide which tools are allowed, which need approval and which are denied; errors should be returned as useful information.
Function calling
The convention by which a model requests that the controller run a defined tool with given arguments.
Tool schema
A definition, usually JSON Schema, of a tool's parameters.
Toolset
A group of related tools, such as issues or pull requests, that can be enabled together.
Pre-approval
Allowing a tool to run without asking a person each time.
Transient failure
A temporary error, such as a timeout, that may succeed on retry.

Practice problems

Work each problem on paper first, then reveal the answer to check.

  1. From what does a model decide which tool to call?

    Show answer

    The tool names and descriptions it is given.

  2. Why should tools return small results?

    Show answer

    Large results fill the context window, cost more and push the task out of focus.

  3. Whose job is retrying a network timeout?

    Show answer

    The controller's, with a limit on attempts.

Lesson quiz · 5 questions

Score 60% or more to complete this lesson.

Take the quiz