Gen AI Systems

Agentic Patterns and Tool Use: ReAct, Function Calling, and Orchestration

Design LLM systems that use tools safely, including ReAct loops, function calling, planning, supervisor-worker orchestration, multi-agent patterns, and safety controls.

agentsReActfunction callingtool usemulti-agent

What Is an Agent?

An LLM agent is a system where the model can decide steps, call tools, observe results, and continue until it completes a task or stops. The model is not just generating text; it is participating in a control loop.

⚠️

Tool access changes the risk model: A model that can call tools can spend money, change data, leak information, or trigger side effects if controls are weak.


Tool Calling

Tool calling lets the model produce structured arguments for code you own.

json
{
  "tool": "get_order_status",
  "arguments": {
    "orderId": "ord_123"
  }
}

Tool Design Rules

RuleReason
Use narrow toolsEasier to validate and authorize
Define schemas strictlyReduces malformed calls
Separate read and write toolsWrite tools need stronger controls
Return compact observationsAvoid context bloat
Make tools idempotent when possibleRetries become safer

ReAct Pattern

ReAct combines reasoning and acting in a loop: think about the next step, act with a tool, observe the result, then continue.

Use ReAct when the answer requires external information or step-by-step interaction. Avoid unbounded loops; set max steps, timeouts, and stop conditions.


Planning Patterns

PatternUse CaseRisk
Plan-and-executeMulti-step task with known phasesPlan may become stale
ReActSearch, inspect, act iterativelyLoop can drift
ReflectionCritique and revise outputExtra cost and possible overthinking
Tree searchExplore alternativesExpensive and complex
Checklist executionRegulated or operational tasksLess flexible

For production systems, explicit workflows are often safer than letting the model freely invent long plans.


Multi-Agent Orchestration

Multiple agents can be useful when tasks have distinct roles, but they add coordination overhead.

Supervisor-Worker

Common Topologies

TopologyDescriptionBest For
Supervisor-workerOne coordinator delegates tasksClear ownership
HierarchicalManagers coordinate subteamsLarge decomposable work
Peer-to-peerAgents debate or collaborateExploration and critique
PipelineOutput of one agent feeds nextRepeatable workflows

Do not use multiple agents just because it sounds advanced. Use them when roles are naturally separable and coordination cost is justified.


Memory

Agent memory can mean different things.

Memory TypeExample
Short-term contextCurrent conversation and observations
Episodic memoryPast task summaries
Semantic memoryFacts about user, product, or domain
Working stateCurrent plan, completed steps, pending actions

Memory needs consent, privacy controls, deletion, and conflict handling. Bad memory can make agents confidently wrong.


Safety Architecture

Required Controls

ControlPurpose
Tool allowlistOnly expose intended capabilities
AuthorizationEnforce user and tenant permissions
Argument validationPrevent malformed or malicious inputs
Confirmation gatesProtect side-effecting actions
Audit logRecord who asked, what ran, and why
SandboxingLimit code execution and file/network access

Separate decision from execution: The LLM may propose an action, but deterministic code should validate and execute it.


Common Failure Modes

FailureCauseMitigation
Infinite loopNo stop conditionStep budget and convergence checks
Wrong toolAmbiguous tool descriptionsNarrow schemas and examples
Data leakTool returns unauthorized dataEnforce ACL in tool code
Unsafe side effectModel acts without confirmationHuman approval for risky writes
Prompt injectionTool output contains instructionsTreat tool output as untrusted data
Context bloatToo many observationsSummarize and cap tool output

What to Remember for Interviews

  1. Agents are control loops: model, tools, observations, and stop conditions.
  2. Function calling is structured IO: the model proposes arguments; code validates them.
  3. ReAct is useful for iterative tasks: but must be bounded.
  4. Multi-agent adds coordination cost: use it for separable roles, not decoration.
  5. Safety is architectural: permissions, validation, confirmations, and audit logs are mandatory.

Practice: Design an agent that can troubleshoot failed deployments. Include read-only tools, write tools, approval gates, audit logs, and how you prevent prompt injection from logs.