Designing an AI Tool-Calling Assistant for Biomedical Research

    This article explains why general-purpose LLMs fail on biomedical tasks and how to build a reliable tool-calling assistant around them. It covers a four-layer architecture (tool registry, planner, execution sandbox, and verification), context engineering practices that replace few-shot imitation, an evaluation framework for tool selection, argument validity, and end-to-end factual accuracy, plus common deployment pitfalls and a vendor-neutral cloud capability mapping.

    1. Where the Problem Starts: A Confident Outsider

    A biology graduate student obtained an unknown sequence and casually handed it to a general-purpose chat model to ask about its origin. The model produced a long explanation and confidently declared that it belonged to a common gut bacterium. A subsequent homology search in an authoritative sequence database, however, pointed to a completely different group of actinomycetes as the best match. The answer was not wrong in an obscure way — it was wrong in an extremely fluent way, and that is what makes it dangerous.

    Such failures are not occasional; they are structural. Typical failure modes of general models on biomedical tasks include:

    • Sequence and structure judgments lack verifiable grounding and rely on language priors to “guess” a conclusion;
    • Database identifiers (gene IDs, protein IDs, variant IDs) are remembered fuzzily, so the model easily fabricates IDs that look plausible but do not exist;
    • Insensitivity to parameter formats, version differences, and species-specific constraints, so the calling intent is correct but the call fails;
    • No confidence expression when errors occur, leaving the user without a signal to double-check.

    2. Root Cause: A “Mouth” Without “Hands”

    Comparing a general model to a well-read humanities student is not unfair: it can accurately recite that “a gene is the carrier of genetic information,” yet it cannot actually open a species record stored deep inside a national bioinformation center. To determine a protein’s function, the professional approach is to look up entries in a protein annotation database; to assess a variant’s potential impact, it is to run a variant effect prediction pipeline; to confirm a sequence’s origin, it is to perform homology search and taxonomic placement.

    These professional services and tools are the “hands” of biomedical research, while the model is currently more like a “mouth” that can only talk. The gap is essentially a difference in how knowledge is acquired: the model’s parametric memory is compressed and lagging, whereas domain facts are massive, dynamic, and strongly identifier-based.

    An early improvement idea was to let the model “learn to call by watching examples” — placing one or two demonstrations in the conversation context so the model imitates the form of API calls. This path has a clear ceiling:

    1. The context window is limited, and a few lines of examples cannot hold the full specifications of dozens of tools;
    2. Biological identifiers require exact matching, and examples cannot cover long-tail formats;
    3. Multi-step tasks need intermediate results to be fed back, and example-based imitation struggles to maintain state reliably;
    4. Tool versions and parameters evolve, so static examples go stale quickly.

    The conclusion is clear: tool-use capability cannot be acquired through “demonstration imitation.” It must be built with an externalized tool registry + a controlled execution environment + an observable evaluation loop.

    3. Target Architecture: A Four-Layer Decoupled Tool-Calling Assistant

    3.1 Tool Registry Layer

    Wrap each professional capability as a standardized entry that the model retrieves on demand during reasoning, instead of stuffing all specifications into the context. An entry contains at least:

    1. {
    2. "name": "sequence_similarity_search",
    3. "description": "Run homology search on a nucleic acid or protein sequence and return candidate organisms with similarity",
    4. "input_schema": {
    5. "sequence": "string, FASTA or raw sequence",
    6. "database": "enum: nucleotide | protein",
    7. "top_k": "integer, default 5"
    8. },
    9. "output_schema": {
    10. "hits": [{"accession": "string", "organism": "string", "identity": "float"}]
    11. },
    12. "constraints": ["sequence length limit", "IUPAC character set only"],
    13. "version": "semantic version",
    14. "idempotent": true
    15. }

    Engineering notes: description text should be written for selection rather than usage, so the model can distinguish near-synonymous tools from the description alone; parameters should use strong typing and enum constraints; entries should support version coexistence to make experiments reproducible.

    3.2 Planner and Retrieval Layer

    For a question like “which organism does this sequence come from,” the planner first decomposes it into executable steps: character set validation → sequence search → taxonomic placement → result aggregation. Tool selection uses a two-stage “coarse ranking then fine ranking” retrieval to avoid injecting all tool descriptions into the context at once.

    1. # Pseudocode: a constrained tool-calling loop
    2. for step in plan:
    3. tool = registry.retrieve(step.intent, top_n=3)
    4. args = arg_builder.fill(tool.input_schema, step.slots)
    5. if not tool.validate(args):
    6. return ask_user_for_missing_slots(tool, args)
    7. result = sandbox.invoke(tool, args, timeout_s=30)
    8. memory.append(result) # persist intermediate results explicitly for later steps

    The key design is explicit state: intermediate artifacts are written to structured memory rather than carried implicitly by the context, so multi-step tasks do not lose earlier conclusions under window pressure.

    3.3 Execution Sandbox Layer

    Model-generated call arguments are untrusted and must run in an isolated environment:

    • An outbound network allowlist that permits access only to registered professional service endpoints;
    • Resource quotas (timeout, concurrency, response body size) so one runaway query cannot take down the whole system;
    • Input pre-validation (character set, length, ID format) that blocks errors before execution;
    • Full call logging with inputs, outputs, latency, and status codes for later review.

    3.4 Verification and Expression Layer

    This layer decides whether the assistant is trustworthy. It includes at least three checks:

    1. Identifier back-check: any ID the model mentions must have a matching item in the returned results, otherwise it is marked unverified;
    2. Cross-consistency: confidence is raised only when the same conclusion is reached by two independent paths (e.g., search plus taxonomic placement);
    3. Explicit uncertainty: the output distinguishes “facts returned by tools,” “model inferences based on those facts,” and “unverifiable guesses.”

    A practical output template:

    1. conclusion: The best match for this sequence is an actinomycete
    2. evidence:
    3. - source: sequence similarity search tool
    4. best_hit_identity: 0.97
    5. organism_class: actinomycetes
    6. verified_identifiers: [acc_1, acc_2]
    7. confidence: high
    8. unverified: []
    9. next_suggestion: run phylogenetic analysis to confirm genus-level placement

    4. Context Engineering: The Right Alternative to Piling Up Examples

    Since demonstration imitation does not scale, the context budget must be spent where it matters. Suggested priority:

    1. Compact descriptions of candidate tools for the current step (not the full list);
    2. Intermediate results already obtained and an allowlist of identifiers;
    3. Failure records and repair hints (turn the previous error into a constraint);
    4. The output format contract.

    Anti-patterns should be stated just as clearly: do not inject large passages of domain textbook content into the context as a substitute for knowledge; do not let the model freely generate IDs without tool support; do not repeatedly paste lengthy raw response bodies across turns — pass references instead of full text.

    5. Evaluation: Turning “Looks Right” into “Measurable”

    An assistant without evaluation cannot be iterated. A three-layer dataset is recommended:

    • Tool selection accuracy: given an intent, is the correct tool chosen;
    • Argument validity rate: does the call pass validation on the first attempt, and how many repair rounds does it take on average;
    • End-to-end factual accuracy: whether the final conclusion matches authoritative databases, and the rate of hallucinated IDs.

    Evaluation must cover the long tail: rare species, non-standard character sets, very long sequences, and compound questions requiring multi-hop reasoning. Cost metrics (average number of calls, average latency) should also be recorded, because multi-step tool calling is inherently more expensive and a balance must be found between quality and overhead.

    6. Common Deployment Pitfalls

    • Over-authorization: exposing too many tools to the model actually lowers selection accuracy; the tool set should be trimmed per scenario.
    • Silent errors: after a failed call, the model fabricates a result; failures must be forced to surface and fall back to human confirmation.
    • Version drift: underlying database updates make historical conclusions non-reproducible, so version numbers and snapshots must be pinned.
    • Blurred responsibility boundaries: the assistant is positioned as “research assistance,” and final conclusions must be reviewed by the researcher — this must be stated clearly in both the interface and the documentation.

    7. Mapping to Common Cloud Capabilities

    The engineering implementation can reuse common cloud capabilities without binding to any specific vendor: a container platform hosts the sandbox and tool gateway; object storage keeps sequence files and result snapshots; a message queue smooths peaks and chains multi-step tasks; logging and monitoring with alerting cover success rate and latency across the call chain; key management handles access credentials. Baidu AI Cloud likewise provides these general capability categories in such scenarios, making it easy for teams to combine them according to their own compliance requirements.

    8. Conclusion

    The core proposition of a biomedical AI assistant is not to make the model sound more like an expert, but to make it actually go look things up when facts are needed. By standardizing tools, isolating execution, making state explicit, and making conclusions verifiable, a general model can shift from a fluent “outsider” to a reliable research collaborator. To judge whether such a system is mature, look at a single metric: whether every key conclusion it gives can be traced back to a real, logged, reproducible tool call.