Interview concept

Agent Tool Use And Function Calling Systems

Asked of: ML Engineer

Last updated

What's being tested

Interviewers are probing your ability to design, deploy, and operate production-grade agent and function-calling pipelines so language models can reliably invoke external tools. Expect emphasis on interface design (schemas, validation), runtime orchestration (latency, retries, idempotency), and evaluation/monitoring (correct-tool selection, hallucination rates). OpenAI cares because ML Engineers must make model-driven tool use robust, observable, and safe in deployed products.

Core knowledge

  • Function calling semantics: define a strict JSON schema (types, required fields) for each callable endpoint so the model's structured output can be parsed deterministically; prefer declarative schemas over free-text parsing.

  • Tool interface design: minimal surface area per tool, idempotent operations, explicit success/failure codes, and request_id correlation to support retries and audit trails.

  • Model-to-tool mapping: represent tool selection as a classification/regression problem (score distribution over tools); measure tool selection accuracy = correct_calls / total_calls, and calibrate logits or thresholds to control false positives.

  • Latency budget: set an SLO (e.g., 200–500ms for interactive agents); budget = model infer + marshaling + network + tool exec. Use p95totalSLO\text{p95}_{\text{total}} \le \text{SLO} and shard timeouts by component.

  • Fallback & orchestration: use async orchestration (task queues, retries) for long-running tools; return incremental responses or "thinking" states for UX. Ensure clear semantic distinctions between sync vs async tools.

  • Security & safety: minimize tool privileges and use least-privilege service accounts; sanitize model-provided arguments before invoking external actions; apply fine-grained rate limits and quotas.

  • Observability: log raw prompts, model outputs, tool invocations, latencies, and outcomes; compute metrics like tool-usage distribution, hallucination rate, and end-to-end success. Instrument per-model-version and per-tool.

  • Offline/online parity: maintain a replayable deterministic sandbox that can re-run model outputs through tools for debugging; seed training data from production-labeled invocations to reduce distribution gap.

  • Testing & CI: unit-test tool wrappers with mocked responses, fuzz invalid schemas, and run integration tests with contractual assertions (schema-consumer checks, idempotency).

  • Model training / fine-tuning signals: capture (prompt, tool_call, tool_result, human_feedback) tuples; use supervised fine-tuning or preference learning to improve tool selection and argument generation.

  • Versioning & compatibility: version schemas and tool endpoints; provide feature flags to route traffic between old/new tool parsers; maintain backward compatibility layers for stored agent transcripts.

  • Privacy & retention: mask PII upstream of logs, set TTLs for stored invocations, and ensure compliance boundaries between model context and tool payloads.

Worked example

(Design a function-calling interface for a model to perform calendar operations) In the first 30 seconds ask: which calendar systems must be supported, authentication model, and latency/consistency requirements. Organize your answer around three pillars: (1) schema design for operations (create_event, list_availability) with explicit types and validation, (2) runtime flow (model output → schema validator → sanitizer → tool invocation → confirm back to model/user), and (3) observability & safety (audit logs, PII masking, permission checks). Flag the tradeoff between strict schemas (safer, easier parsing) vs expressive arguments (more flexible natural usage); lean toward strict schemas and a lightweight preprocessor that maps natural language to schema fields. Close by noting you'd add end-to-end integration tests, collect real-world tool-call failures to refine schemas, and run an A/B test comparing strict vs flexible schema on task success and latency.

A second angle

(Real-time chat assistant that calls external knowledge APIs under a tight latency SLO) The framing shifts constraints: prioritize aggressive caching, local embeddings for common queries, and speculative prefetching to meet a 200ms p95. The same core pieces apply—schemas, validation, observability—but you now emphasize edge optimizations: synchronous vs asynchronous decisions, cache TTL strategy, and graceful degradation when external APIs are slow (e.g., return partial answer with provenance and scheduled follow-up). You'd instrument cold-start rates and cache hit ratios as key signals and consider model-side fallback templates when tools time out.

Common pitfalls

Pitfall: Over-trusting model outputs.
Teams often invoke tools directly on model-provided arguments without validation, leading to injection-style failures; always validate and sanitize, and implement a safe-execution sandbox.

Pitfall: Ignoring observability for early failures.
A tempting shortcut is to log only successful tool calls; instead log raw model output, validated payload, tool response, and error codes so you can compute root causes and retrain.

Pitfall: Tight-coupling schema with model prompts.
Hardcoding schema shapes in prompts without versioning breaks backwards compatibility; use explicit schema versions, and a translation layer to map older transcripts to new schemas.

Connections

This topic often pivots to retrieval-augmented generation (RAG) and vector search integration, or to workflow orchestration patterns (e.g., Temporal, Celery) for managing long-running tool calls. Interviewers may also shift to model-evaluation topics like calibration and human-in-the-loop labeling strategies.

Further reading

  • OpenAI Function Calling Guide — practical spec and examples for schema-driven function outputs.

  • LangChain Agents — common orchestration patterns and agent abstractions you’ll encounter in production.

  • Toolformer (arXiv) — research on models learning to use external APIs; useful for understanding training signals and supervision approaches.

Related concepts

Agent Tool Use And Function Calling Systems — Tech Interview Concept | PracHub