Web search and code execution

Web search finds public information; code execution can check a calculation.

What you will learn

  • Explain: the model proposes, the tool executes
  • Apply the idea in an example: Web search and code execution
  • Recognize limitations and verify the exercise outcome

Web search finds public information; code execution can check a calculation. These are separate capabilities with their own permissions and costs.

These steps refer to features identified in the application code. This material has not been validated on a live instance; check the documentation and the options in your version.

How it works, step by step

The model proposes, the tool executes

Tool calling produces a call request with a name and arguments. The application validates the schema, permissions and limits before execution. The result returns to context for the next step. For example, get_product_stock takes a SKU and returns a quantity; its description should explain that it does not reserve products. Distinguish empty results, validation errors, missing access and timeouts. Valid JSON does not prove the arguments are correct or the action is authorized. For external effects, also consider duplicate execution.

Fluency and truth are checked separately

A hallucination is unsupported or incorrect content presented as an answer. It can arise from missing information, ambiguity or incorrectly combined patterns. Ask for evidence and check the original document, date, units and conditions. A real citation may still fail to support the claim. Use current sources for current facts, a calculator for arithmetic, and “cannot determine” when evidence is missing. Do not treat confidence expressed in prose as a calibrated probability.

Cost belongs to the whole path

Count model calls, input and output tokens, embeddings, reranking, vision and tools. Reasoning can consume billable tokens without an equally long visible response. Indexing costs and conversation costs differ. Use current prices rather than a permanent number from a course. A simple estimate is tokens/1,000,000 × price plus additional operations; application credits may have their own conversion. Compare cost per successful task, not just per call. Parallel execution can reduce latency while increasing total consumption. A budget needs a verified stopping condition.

The visual map

Web search and code execution Follow the solid arrows for the main flow. Dashed blue arrows supply data or context; dashed pink arrows show feedback or returning results. Colors and shapes distinguish models, stores, decisions and outputs. Connections: User request → Agent / LLM; Agent / LLM → Web search results; Web search results → Tool results; Tool results → Result to verify; Result to verify → Human verification; Agent / LLM → Code execution; Code execution → Tool results; Agent / LLM → Calculator or executable check; Calculator or executable check → Tool results; Instructions and context → Agent / LLM; Isolated execution environment → Code execution; Original sources → Web search results; Tool results → Agent / LLM. A05 · Relationship map Web search and code execution Input User request Data Instructions and context Decision / control Isolated execution environment AI model / agent Agent / LLM Tool / service Web search results Tool / service Code execution Tool / service Calculator or executable check Store / index Original sources Data Tool results Output Result to verify Decision / control Human verification Main flow Data and context Feedback and return

Follow the solid arrows for the main flow. Dashed blue arrows supply data or context; dashed pink arrows show feedback or returning results. Colors and shapes distinguish models, stores, decisions and outputs. On smaller screens, scroll horizontally to follow the entire diagram.

A complete example

For a recent announcement, check the official page and date. For synthetic CSV data, compute 2×120 + 1×80 = 320 lei. Keep keys and private data out of public search.

Try it yourself

  1. Test public search and arithmetic separately, checking permissions and results.
  2. Record the input, source and expected outcome before running the experiment. Use only the fictional data in the example.
  3. Follow the diagram stages. At every step record what information is received and produced; do not confuse intermediate output with the final outcome.
  4. Repeat after removing necessary information or making the input ambiguous. Check whether the system clarifies, stops or invents an answer.
  5. Compare with the explained solution. Keep the configuration, date, result and an explanation for differences. Change one thing and retest.

An explained solution

The report separates verified web sources from the computed total and explains input data. A successful exercise lets you show the connection between input, stages and outcome. When information is missing, a cautious answer is more useful than invented details. Compare more than style: check conditions, sources and operations too.

When it helps and what can go wrong

Availability depends on model, provider and integration. Choose this approach when it improves a measured need. Keep a simple baseline and compare outcomes using identical inputs. One successful example does not establish reliability in every situation.

Check your understanding

Who executes a call proposed by the model?

The application or host service after validation. The model does not automatically gain unrestricted access.

Is a link in an answer enough?

No; it must support the specific claim and fit the time and circumstances.

What outcome should this exercise produce?

The report separates verified web sources from the computed total and explains input data.

Words to remember

  • Tool calling: A structured request to use an external capability.
  • Grounding: Grounding an answer in verifiable evidence.
  • Latență / Latency: Time until a useful result.

Sources and your next step

To prepare: A04 — An agent using MCP tools