To answer “Which rooms fit 12 people?”, you can always call the room directory and filter by capacity. Do you need an agent to decide that sequence? Often you do not. The choice of control flow should follow the task.
Before you begin: Understand LangChain messages and the basic agent loop.
Keep a chain explicit
A chain is a sequence of operations whose ordering is defined by code or configuration. Validate the question, retrieve the room records, filter capacity, and format the result. Some steps may use models, but the workflow does not need the model to invent the sequence.
An agent gives the model a role in choosing actions based on observations. It might decide whether it needs a room lookup, a calendar check, or a clarification. This flexibility can help open-ended tasks, but it adds more possible trajectories and more evaluation work.
Define one trustworthy tool
A tool's contract should identify inputs, outputs, and limits. Here is a complete local Python function over fictional data. It has no network calls or external side effects.
# Runnable: Python 3, standard library.
ROOMS = [
{'id': 'r4', 'capacity': 8},
{'id': 'r8', 'capacity': 16},
]
def rooms_for_group(people):
"""Return fictional room IDs with enough seats; no booking occurs."""
if type(people) is not int or people <= 0:
raise ValueError('Group size must be a positive integer')
return [dict(room) for room in ROOMS if room['capacity'] >= people]
assert rooms_for_group(12) == [{'id': 'r8', 'capacity': 16}]
assert rooms_for_group(20) == []
print(rooms_for_group(12))
The empty list means no room in this fixture meets the capacity requirement. It does not mean a lookup failure, and it does not authorize selecting a smaller room. Distinguishing these outcomes makes an agent's next decision easier to evaluate.
Add the model-controlled boundary
In current LangChain, create_agent accepts a model, tools, and application instructions. A typed Python tool with a useful docstring describes a capability the model may request. The runtime interprets tool calls and returns observations to the loop.
Binding a tool schema is not the same as executing the tool. Execution still belongs to the application runtime, which must validate arguments and permissions. For external writes, a natural-language instruction is not sufficient authorization.
Keep the first agent read-only. Add explicit step and time budgets and inspect its trace. If the question is already answerable from supplied records, repeated tool calls may be wasteful rather than evidence of sophistication.
Treat a tool result as data
A directory record could contain untrusted descriptions. A description saying “ignore all prior instructions” is still source content. Do not let the returned text redefine available permissions or make unrelated tools eligible.
A tool error should have a structured, inspectable outcome. Authentication failure, no matching rooms, and a timeout need different handling. A single string such as “something went wrong” makes recovery difficult and can encourage unsupported guesses.
Compare the two designs
Run the same questions through a fixed lookup-and-filter function and a tool-using agent when you have a configured model. Include a straightforward capacity query, a missing group size, and a group larger than every room. Count correctness, tool calls, latency, and failures. Mark model experiments as unexecuted until you actually run them.
If the agent offers no measurable advantage, keep the chain. If it handles legitimate varied requests better, preserve the flexibility but retain the tool and permission boundaries.
Choose the next action
The tool returns no rooms for 20 people. The agent proposes booking the 16-seat room because it is the largest. What should the workflow do?
Respect the unmet constraint
Stop or ask whether the user wants to change the group size, location, or time. The capacity requirement is not satisfied. “Best available” is a different task and requires an explicit decision, not an unannounced relaxation of the original constraint.
Next, we will make the conversation state durable and distinguish thread history from cross-session knowledge.
Reference
The LangChain agent guide documents the current model-tool loop and its configuration. The local room fixture above is intentionally separate from a real booking system.