Ai Interview Questions
Browse through all 40 Ai interview questions and challenges below.
MCP is an open protocol that standardises how an AI application connects to external tools and data, so one server can work with many AI apps instead of every app writing its own integration. It has three roles: a host (the AI app), a client inside the host that talks to exactly one server, and a server that exposes tools, resources and prompts. Messages are JSON-RPC, sent over stdio for local servers or Streamable HTTP for remote ones.
Tool calling lets a model ask your app to run a function: you describe each tool with a name, a description and an input schema, and the model replies with a structured request (tool name plus JSON arguments) instead of plain text. The model never runs anything itself. Your code validates the arguments, runs the function, sends the result back, and the model uses it to continue; the exception is provider-executed tools like hosted web search, which run on the provider side.
First treat the key as leaked: rotate it in the provider dashboard, because NEXT_PUBLIC_ values are inlined into the JavaScript bundle at build time. Then move the model call into a Route Handler, store the key in a variable without the NEXT_PUBLIC_ prefix, and import "server-only" in the module that uses it so a Client Component import fails the build. The browser only talks to your route, which adds auth and limits before calling the provider.
At each step the model produces a probability for every possible next token, and temperature reshapes that distribution before one token is sampled. Lower temperature makes the likeliest tokens even more likely, so output is more focused and repeatable; higher temperature flattens it, so output is more varied. Lower it for extraction, classification and code, but check your model first: several newer models only accept the default value.
A token is the unit of text a model reads and writes: usually a word, part of a word, a punctuation mark or a space-plus-word chunk. Providers bill and rate-limit by tokens, not characters or words, so the same text can cost different amounts on models with different tokenizers. Count tokens with the provider's tokenizer or counting API instead of guessing from string length.
Test it in layers: unit test the business logic inside each handler, then drive the whole server through a real MCP client in-process so you test listing, schemas, results and errors exactly as a host sees them. Add a smoke test that spawns the real stdio or HTTP server, use the MCP Inspector for manual and scripted checks, and keep a separate eval for whether models actually pick your tools correctly.
All three are things an MCP server exposes, but they differ in who decides when they are used. Tools are model-controlled actions the model can ask to run, resources are read-only context the host application chooses to include, and prompts are templates the user explicitly picks, often as a slash command. Picking the right primitive decides who is in control, which matters for safety, cost and UX.
Define tools directly when one app owns the feature, the tool needs tight access to your app state, and you want the simplest, fastest path. Reach for MCP when the same capability should work across several AI hosts or teams, when another team or vendor already ships an MCP server, or when you want the tool to live and deploy separately. MCP adds a process, a protocol and a security surface, so it should earn its place.
Start from requirements, not popularity: list what you need (streaming to a React UI, tool calling, memory, human approval, durable long-running runs, tracing) and check which you can already do with a lightweight SDK. Many teams can start with the Vercel AI SDK and plain TypeScript, and adopt a heavier framework such as Mastra, LangGraph.js or the OpenAI Agents SDK only when they need its specific features. Build the same small agent as a spike in your top two options, and keep the framework behind your own interface so you can switch later.
A model has no memory of its own: every call only sees what you send in that request. Agent "memory" is your app deciding what to put back into the context: short-term memory is the current conversation (message history for one thread), working memory is a small set of key facts kept in the prompt, and long-term memory is data stored in a database across sessions and pulled in when relevant, often by semantic search. Each type trades accuracy against tokens, cost and privacy.
A workflow is LLM calls and tools wired together by your code along a path you decided in advance. An agent is a model running in a loop that decides its own next step and which tools to call. Use a workflow when the steps are known and you need predictable cost and latency, and reach for an agent only when the number and order of steps genuinely depend on the input.
An agent loop keeps calling the model, running the tools it asks for and feeding results back. It stops naturally when the model finishes without requesting a tool, when it calls a tool that has no server-side execute (so the client or a human must act), or when a call needs approval. On top of that you add hard limits: a maximum step count, a stop-on-specific-tool rule, and custom conditions such as a token budget, because the model deciding to stop is not a guarantee.
Render the assistant message as a list of parts, and give each tool part its own small component that switches on its state: input-streaming, input-available, approval-requested, output-available, output-error or output-denied. Show a short human label while the tool runs, the result in a compact card when it finishes, and a clear error or denial message when it fails. Announce changes politely to screen readers and keep raw JSON out of the main view.
Design the schema like a form for a new teammate: clear key names with units, a short description on every field, enums instead of free text where the values are known, and an explicit null or "not found" option so the model never has to invent data. Keep it shallow, order fields so context comes before conclusions, and stay inside the schema features your provider supports. Then measure it with a small set of test inputs instead of guessing.
JSON mode only promises that the reply parses as JSON, not that it has the fields you need. Structured output goes further and constrains the reply to a JSON Schema you send, so the shape is enforced at generation time. Function calling uses the same schema machinery for a different job: the model asks your code to run a tool with typed arguments, instead of answering the user in a fixed shape.
Treat model output like any untrusted API response: parse it against a Zod schema at the server boundary before it reaches React. Use safeParse so a failure becomes a value you can branch on, log the raw text and the Zod issues, and return a typed error state the UI knows how to render. With the AI SDK, Output.object runs this validation for you and throws NoObjectGeneratedError when the object does not match.
useChat keeps an array of UIMessage objects, each with an id, a role and a list of parts. sendMessage adds your message right away, sets status to submitted, posts the conversation through a transport and then applies each streamed chunk to the assistant message, moving status to streaming and finally to ready or error. Helpers like stop, regenerate and setMessages change that same array, and the throttle option limits how often React re-renders.
The server owns everything that must be trusted: the API key, the model choice, the system instructions, tool execution, auth, input validation, rate limits and saving the conversation. The client owns everything the user touches: the input box, the message list, rendering streamed parts, the stop button and loading or error states. In the App Router that usually means a Route Handler that returns a UI message stream and a Client Component that uses useChat.
An AI SDK gives you one API (generateText, streamText, tools, structured output and a UI message stream) on top of a shared language model specification, so switching providers is mostly a change to the model argument. What stays provider-specific is capability and behaviour: which models support tools, images or reasoning, how they tokenize and price, features like prompt caching, and extra settings you pass through providerOptions keyed by provider name.
Follow the stream only while the user is already at the bottom. Track a "stick to bottom" flag from scroll position, turn it off as soon as the user scrolls up, and show a "Jump to latest" button instead of pulling them back down. Scroll when the content actually grows (a ResizeObserver on the message container works well), and turn sticking back on when the user sends a new message or clicks the button.