Agents And Tool Use medium
Your `update_order` tool takes a free-text `action` string. The model sometimes passes values like 'cancel it please' or 'refund+cancel', which the backend misinterprets. What is the most robust fix?
- A Replace the free-text param with typed fields and an enum of allowed actions, validate on the host, and return clear errors.
- B Keep the free-text param and add a parser that uses a second LLM call to interpret whatever action string the model sends.
- C Add dozens of few-shot examples of correct action strings to the system prompt so the model learns the expected phrasing reliably.
- D Split into one tool per possible action phrasing, so the model always has an exact match for whatever it intends to do.
Answer: A. Replace the free-text param with typed fields and an enum of allowed actions, validate on the host, and return clear errors.
**Constrained schemas** (enums, typed fields) plus host-side validation make invalid calls fail loudly, and the error gives the model a clear signal to correct itself. Few-shot examples (C) are tempting and lower the error rate, but they add prompt tokens and still do not guarantee valid values. The tradeoff is less flexibility, since new actions need schema changes. Free text fits only when the downstream system is itself built to interpret natural language.
One system design question a day, with spaced repetition so the ones you miss come back.
Get the appRelated questions
- You are defining a 'schedule_meeting' tool for an agent. Which schema decision most reduces wrong or malformed calls?
- A model emits three parallel tool calls: `get_inventory`, `get_price`, and `get_shipping`. To cut latency, the host appends each result to the transcript as it arrives and immediately re-invokes the model. Runs start failing with malformed-request errors, and some produce hallucinated shipping costs. What should the host do?
- A team splits a coding agent into planner, coder, tester, and reviewer agents, and each receives the full transcript of the previous agent. The expected quality gains did not appear. Cost tripled, and the reviewer often fixates on approaches that earlier agents abandoned. When is a multi-agent split actually justified?
- A support agent should remember each customer's preferences across months of sessions. The team appends every past session summary to the system prompt. After six months, prompts exceed 80,000 tokens, latency has doubled, and the agent sometimes ships to an address the customer replaced weeks ago. What redesign fixes both problems?
- A teammate proposes splitting a single coding agent into five agents, arguing that more agents means smarter results. When is a multi-agent split actually justified?
- A data-analysis agent runs model-generated Python inside the same container as your API service. That container has database admin credentials in environment variables. A security review flags this as critical. What is the best mitigation?