Inferensys

Prompt

Dynamic Tool List Adaptation Few-Shot Prompt Template

A practical prompt playbook for building agents that adapt tool selection when the available tool list changes per session, tenant, or deployment. Includes copy-ready few-shot examples, eval checks for deprecated tool selection, and failure mode analysis.
Developer demonstrating multi-agent tool use, agent tool selection interface on laptop, casual tech demo moment.
PROMPT PLAYBOOK

When to Use This Prompt

Defines the ideal deployment scenario for a few-shot prompt that teaches an LLM to adapt its tool selection to a dynamic, per-request list of available tools.

This prompt template is designed for agent developers building multi-tenant or session-scoped systems where the set of available tools varies per request. Instead of hardcoding tool selection rules or retraining models for each tool configuration, this few-shot prompt teaches the model to inspect the provided tool list and select only from currently available tools. Use this when your agent serves different customers with different API subscriptions, when tools are feature-flagged per user, or when you deploy the same agent across environments with different capability sets. The prompt works by presenting contrasting examples: some where the tool list is full, some where it is reduced, and some where deprecated tools appear in conversation history but are absent from the current list. The model learns to ground every tool selection decision in the provided [AVAILABLE_TOOLS] block rather than relying on memorized tool names from training data.

You should not use this prompt when the tool list is static and known at development time. In that case, a standard system prompt with explicit tool descriptions is more efficient and less error-prone. Similarly, do not use this approach if your model has been fine-tuned for a specific tool set; the few-shot examples may conflict with the model's trained behavior, causing unpredictable selection patterns. This prompt is also inappropriate for single-tool agents where selection is trivial. The primary risk this prompt addresses is tool hallucination—the model calling a tool that is not in the current list. A secondary risk is capability assumption, where the model refuses to attempt a task because it assumes a tool is missing, even when a new or alternative tool in the list could accomplish it. The examples must explicitly teach the model to trust the provided list over its internal knowledge.

Before implementing this prompt, audit your tool delivery pipeline to ensure the [AVAILABLE_TOOLS] block is always a complete and accurate reflection of the current session's capabilities. A mismatch between the declared tools and the actual API gateway permissions will lead to runtime failures that the prompt cannot prevent. After deploying, monitor for tool_not_found errors and instances where the model selects a deprecated tool mentioned in the conversation history. These are the leading indicators that the few-shot examples need to be strengthened or that the tool list injection is failing. Proceed to the next section to copy the prompt template and begin adapting it to your specific tool schemas.

PRACTICAL GUARDRAILS

Use Case Fit

Where this prompt works, where it fails, and the operational conditions required for production use.

01

When the Tool List Changes Per Session

Use when: Your agent operates in multi-tenant environments where available tools differ per user, session, or deployment. Avoid when: The tool set is static and known at build time—static few-shot examples are simpler and more reliable.

02

Deprecated Tool Still Present in Examples

Risk: Few-shot examples referencing removed tools cause the model to hallucinate deprecated function names. Guardrail: Validate that every tool name in your example set exists in the current session's tool list before prompt assembly. Strip or regenerate stale examples.

03

New Tools Ignored by the Model

Risk: The model overfits to familiar tools in the examples and ignores newly added tools, even when they are the best choice. Guardrail: Include at least one example per new tool in the few-shot set. Test with inputs that should route to the new tool before deployment.

04

Reduced Capability Set Causes Silent Fallback

Risk: When high-capability tools are removed, the model may attempt to approximate their behavior with remaining tools, producing incorrect results instead of refusing. Guardrail: Include negative examples showing appropriate refusal or clarification when the ideal tool is unavailable. Log and alert on tool-call patterns that match deprecated tool signatures.

05

Example Drift Under Changing Tool Schemas

Risk: Tool argument schemas change, but few-shot examples retain old parameter names or types, causing validation failures. Guardrail: Version your example sets alongside tool schemas. Run automated validation that checks example arguments against current tool signatures on every deploy.

06

Token Budget Bloat from Large Example Sets

Risk: Covering every tool with multiple examples blows out the context window, increasing latency and cost. Guardrail: Use a dynamic example selector that retrieves the most relevant 2-4 examples based on the user's input, rather than packing all examples into every request.

PROMPT PLAYBOOK

Copy-Ready Prompt Template

A reusable few-shot prompt that teaches a model to adapt its tool selection when the available tool list changes per session or tenant.

This template uses a small set of worked examples to demonstrate the core behavior: selecting the right tool from a dynamic list, ignoring tools that are no longer available, and correctly adopting new tools that appear in the list. The examples are designed to be compact but high-signal, showing the model how to reason about tool availability rather than memorizing a fixed set. Copy the template below and replace every square-bracket placeholder with your actual values before wiring it into your agent harness.

text
SYSTEM: You are an agent that selects the most appropriate tool from a provided list to fulfill a user's request. The list of available tools will change between requests. You must only select tools that are present in the current [TOOLS] list. Do not hallucinate tools that are not listed. If no tool is appropriate, respond with [NO_TOOL_RESPONSE].

[EXAMPLES]

USER: [USER_INPUT_1]
TOOLS: [TOOLS_LIST_1]
ASSISTANT: [CORRECT_TOOL_SELECTION_1]

USER: [USER_INPUT_2]
TOOLS: [TOOLS_LIST_2]
ASSISTANT: [CORRECT_TOOL_SELECTION_2]

USER: [USER_INPUT_3]
TOOLS: [TOOLS_LIST_3]
ASSISTANT: [CORRECT_TOOL_SELECTION_3]

---

USER: [USER_INPUT]
TOOLS: [TOOLS]
ASSISTANT:

To adapt this template, start by defining your [TOOLS] placeholder as a structured list of tool names and brief descriptions. Your [EXAMPLES] should cover at least three scenarios: a full tool list where the correct choice is obvious, a reduced list where the previously correct tool is absent and a different one must be chosen, and a list containing a new tool that was not present in prior examples. The [NO_TOOL_RESPONSE] placeholder should be a clear, safe default like {"tool": null, "reason": "No appropriate tool available."}. After copying, validate that the model's output schema is consistent across all examples—mixing JSON and plain text in few-shot demonstrations is a common source of production drift. For high-stakes environments, add a validation step that checks the selected tool name against the provided [TOOLS] list before execution.

IMPLEMENTATION TABLE

Prompt Variables

Inputs the prompt needs to work reliably. Each variable must be populated by your application before sending the prompt to the model.

PlaceholderPurposeExampleValidation Notes

[AVAILABLE_TOOLS]

JSON array of tool definitions available for the current session or tenant, including name, description, and parameter schema.

[{"name": "search_kb", "description": "Search internal docs", "parameters": {"type": "object", "properties": {"query": {"type": "string"}}, "required": ["query"]}}]

Must be valid JSON array. Each object must contain name, description, and parameters fields. Empty array allowed for no-tool scenarios. Validate against JSON Schema before prompt assembly.

[TOOL_SELECTION_EXAMPLES]

Array of few-shot input-output pairs demonstrating correct tool selection and argument construction for the current tool set.

[{"input": "Find the Q4 report", "output": {"tool": "search_kb", "arguments": {"query": "Q4 report"}}}]

Each example must reference only tools present in [AVAILABLE_TOOLS]. Output must match the expected tool call format. Validate tool names exist in current tool list; reject examples referencing deprecated or unavailable tools.

[NEGATIVE_EXAMPLES]

Array of examples showing incorrect tool selections, hallucinated tool names, or invalid argument patterns to teach avoidance.

[{"input": "Delete the staging database", "bad_output": {"tool": "run_sql", "arguments": {"query": "DROP DATABASE staging"}}, "why_bad": "Destructive action requires confirmation gate"}]

Each negative example must include a why_bad explanation field. Bad tool names must not match any tool in [AVAILABLE_TOOLS]. Validate structure before inclusion; missing why_bad field should trigger assembly error.

[CONFIRMATION_GATE_TOOLS]

List of tool names that require user confirmation before execution, used to teach the model when to request approval.

["run_sql", "send_email", "create_ticket"]

Must be array of strings matching tool names in [AVAILABLE_TOOLS]. Null or empty array means no confirmation gates. Validate each entry exists in current tool list; warn on orphaned gate references.

[DEPRECATED_TOOL_NAMES]

List of previously available tool names that are now removed, used to teach the model to avoid selecting them.

["legacy_search", "old_ticket_api"]

Must be array of strings. Entries must NOT appear in [AVAILABLE_TOOLS]. Used in negative examples to show deprecated tool rejection. Validate no overlap with current tool names; overlap indicates configuration error.

[USER_QUERY]

The current user input or task description that requires tool selection and argument construction.

"I need the latest sales numbers for the East region from last month"

Must be non-empty string. Length should be validated against model context limits. Contains the natural language request that the model must map to tool selection. No structural validation beyond non-empty string check.

[OUTPUT_FORMAT_SPEC]

The exact format specification for the model's tool call output, including required fields and their types.

{"tool": "string", "arguments": "object", "confidence": "number between 0 and 1"}

Must define the expected output schema. Validate that required fields are present. Confidence field should be constrained to 0-1 range. Format must match the consuming application's tool execution harness.

[MAX_TOOLS_PER_TURN]

Integer limit on how many tools the model can select in a single response, preventing excessive parallel calls.

3

Must be positive integer. Used to constrain parallel tool selection and prevent resource exhaustion. Validate as integer greater than 0. Should align with application rate limits and execution capacity.

PROMPT PLAYBOOK

Implementation Harness Notes

How to wire the dynamic tool list adaptation prompt into an application or agent workflow, including tool injection, validation, retry, and logging.

The core challenge of dynamic tool adaptation is that the prompt template must be assembled at runtime with a variable set of tool definitions. The application layer is responsible for injecting the correct [TOOLS] block before every request. This block should be a serialized representation of the currently available tools—typically a JSON array of function definitions following the target model's native tool-use schema. The prompt's few-shot examples must be dynamically filtered or regenerated to match the active tool set, ensuring that demonstrations never reference unavailable tools. A common failure mode is leaving stale examples that teach the model to call a deprecated tool, which the harness must prevent by validating that every tool name in the [EXAMPLES] block exists in the current [TOOLS] list before assembly.

After the model returns a tool selection, the harness must validate the response before execution. First, confirm the selected tool name exists in the active tool list—reject hallucinated or deprecated tool names immediately. Second, validate that all required arguments are present and that argument types match the tool's schema. If validation fails, the harness should enter a structured retry loop: append the validation error to the conversation, re-inject the same [TOOLS] block, and request a corrected selection. Limit retries to a maximum of two attempts before escalating to a fallback path—either a human review queue or a safe default action. Log every validation failure, retry, and escalation for observability. For high-stakes actions, insert a confirmation gate after successful validation but before tool execution, presenting the proposed action to a human operator.

Model choice matters here. Smaller or older models struggle more with tool list changes and are more likely to hallucinate deprecated tools or ignore newly added ones. Prefer models with strong instruction-following and tool-use benchmarks for this workflow. If you must use a smaller model, reduce the number of tools in the active list per request and increase the number of few-shot examples showing adaptation behavior. The eval harness should include regression tests that simulate tool list changes—removing a commonly used tool, adding a new tool, and reducing the list to a single option—and verify that the model adapts correctly without hallucination. Monitor production traces for tool selection accuracy, argument validity, and retry frequency. A sudden increase in validation failures often signals that the tool list has changed in a way the examples no longer cover.

IMPLEMENTATION TABLE

Expected Output Contract

Every model response must conform to this contract before your application acts on the tool selection. Validate each field programmatically.

Field or ElementType or FormatRequiredValidation Rule

tool_selections

array of objects

Must be a non-empty JSON array. Reject if missing, null, or empty when tools are available.

tool_selections[].tool_name

string

Must exactly match a tool name in the provided [AVAILABLE_TOOLS] list. Reject on partial matches, hallucinated names, or deprecated tool references.

tool_selections[].arguments

object

Must be a valid JSON object. All required parameters from the tool's schema must be present. No invented parameter names allowed.

tool_selections[].confidence

number (0.0-1.0)

Must be a float between 0.0 and 1.0 inclusive. Reject if string, integer, out of range, or missing. Values below [CONFIDENCE_THRESHOLD] should trigger clarification.

tool_selections[].rationale

string

Must be a non-empty string explaining why this tool was selected. Reject if empty, null, or fewer than 10 characters.

adaptation_notes

string or null

If the [AVAILABLE_TOOLS] list differs from prior turns, this field must explain the adaptation decision. Required when tool list changed; null allowed on first turn or unchanged lists.

deprecated_tool_warnings

array of strings

If any tool in [AVAILABLE_TOOLS] is marked deprecated, this array must list warnings. Empty array allowed when no deprecated tools present. Reject if deprecated tool used without warning.

missing_capability_flag

boolean

Must be true if the user's intent requires a tool not in [AVAILABLE_TOOLS], false otherwise. Reject if true but tool_selections is non-empty, or false but tool_selections is empty when tools are available.

PRACTICAL GUARDRAILS

Common Failure Modes

What breaks first in production when a dynamic tool list changes between sessions or tenants. These failure modes are based on observed behavior in multi-tenant agent deployments.

01

Hallucinated Tool Selection

What to watch: The model selects a tool that was available in a previous session but is absent from the current tool list. This is common when tool names are similar across deployments. Guardrail: Include a negative example in the few-shot prompt showing the model refusing to call a removed tool and selecting the closest available alternative or asking for clarification.

02

Ignoring Newly Added Tools

What to watch: A new, more appropriate tool is added to the list, but the model defaults to an older, less optimal tool it has seen in prior examples. Guardrail: Place a demonstration example early in the prompt that uses the new tool for a clear use case. Validate with an eval that checks whether the new tool is selected when its specific trigger condition is met.

03

Argument Shape Drift

What to watch: The model uses the correct tool name but constructs arguments matching the schema of a deprecated version of that tool, leading to runtime errors. Guardrail: Always pair the tool's current JSON schema directly alongside its usage example in the prompt. Add an output validator that checks argument keys against the active schema before execution.

04

Capability Overestimation on Reduced Lists

What to watch: When a tenant has a restricted tool set, the model attempts to perform a blocked action by misusing a general-purpose tool (e.g., using a generic API call tool to perform a restricted action). Guardrail: Include a system-level constraint that explicitly lists prohibited action categories for the session, and show a refusal example where the model states the limitation instead of improvising.

05

Context Contamination from Prior Tool Results

What to watch: The model references data or entity IDs returned by a tool in a previous turn that is no longer available, fabricating a tool call to retrieve it. Guardrail: Clear the tool result context explicitly in the system prompt when the tool list changes. Add a few-shot example where the model acknowledges the data is no longer accessible and asks for it again.

06

Silent Fallback to Text-Only Mode

What to watch: Faced with an unfamiliar or reduced tool list, the model abandons tool use entirely and attempts to answer from its training data, bypassing the required tool-calling workflow. Guardrail: Add a strict instruction that every response of a certain type must include a tool call. Use an eval that fails the output if a required tool call is missing, even if the text answer looks plausible.

IMPLEMENTATION TABLE

Evaluation Rubric

Run these checks against a golden dataset of queries paired with varying tool lists. Each check should produce a pass/fail or score that gates your deployment.

CriterionPass StandardFailure SignalTest Method

Tool Selection Accuracy

Selected tool matches the golden label for the given query and tool list

Model selects a deprecated tool, hallucinates a tool not in the list, or picks a semantically wrong tool

Exact match against golden tool name; run on 50+ query/tool-list pairs

Argument Schema Compliance

All required arguments are present and match the tool's parameter types

Missing required field, wrong type (string for integer), or extra hallucinated parameter

JSON Schema validation against the selected tool's input schema; flag any validation errors

Hallucinated Argument Values

All argument values are derived from the user query or explicitly stated defaults

Argument contains an invented ID, date, or entity not present in the query or context

String match and entity presence check; compare arguments against source query tokens

Deprecated Tool Avoidance

Model never selects a tool marked as deprecated in the provided tool list

Model selects a tool with a deprecated flag or version marker in its description

Scan selected tool name against deprecated tool list; fail if any match

New Tool Adoption

Model correctly uses a newly introduced tool when the query matches its purpose

Model ignores a new tool and selects a less appropriate legacy tool, or fails to call any tool

Golden set includes queries designed for new tools; check if new tool is selected when expected

Reduced Capability Adaptation

Model selects the best available tool when the usual tool is missing from the list

Model outputs a tool name not in the list, or refuses to act when a viable alternative exists

Provide tool lists with key tools removed; verify model selects a valid alternative or appropriately escalates

Clarification vs. Action Boundary

Model asks for clarification when no tool clearly matches, acts when intent is unambiguous

Model calls a tool with low-confidence arguments, or asks for clarification when a clear tool match exists

Score clarification requests against golden labels; flag premature action and excessive clarification

Multi-Tool Sequence Ordering

Tool calls are ordered correctly when dependencies exist between tools

Model calls a dependent tool before its prerequisite, or omits a required intermediate call

Dependency graph validation; check call order against predefined dependency edges in golden sequences

ADAPTATION OPTIONS

Adapt This Prompt

How to adapt

Start with a static tool list of 3-5 tools in the system prompt. Use 2-3 few-shot examples showing correct tool selection when all tools are available. Keep the dynamic list logic out of the prompt initially—hardcode the available tools and focus on selection accuracy.

code
[TOOLS]
- search_knowledge_base
- create_ticket
- get_account_status

[EXAMPLES]
User: "Find docs on password reset"
Assistant: search_knowledge_base(query="password reset")

Watch for

  • Model ignoring tool descriptions and guessing
  • Hallucinated tool names when the list is small
  • No validation of tool call arguments against schema
Prasad Kumkar

About the author

Prasad Kumkar

CEO & MD, Inference Systems

Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.

His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.