Multi-Version LLM Selection and Multi-Agent Engineering Practices

    This article explains how to choose among multiple LLM tiers by task requirements, latency, cost, and reasoning trade-offs, then how to design multi-agent workflows with clear boundaries, concurrency limits, timeouts, retries, least-privilege tool access, conflict handling, and rollback. It also covers empirical evaluation of reasoning modes and the expanded risk surface of third-party tool integrations, including server-side permission checks.

    1. Define the Problem First

    Many teams’ first question when integrating an LLM is “which model should we use?” A more practical question is: how fast does this task need to respond, how strong does its reasoning need to be, what is the acceptable cost per call, and who provides fallback when it fails? Once these questions are clear, model selection becomes much simpler.

    LLM providers usually offer multiple tiers. Tiers differ in response latency, price, and reasoning capability; refer to each provider’s official documentation for specific parameters. Before selecting, test with your own business samples.

    2. Version Selection: Split by Task, Not One Size Fits All

    Common tiers can be understood as three categories: lightweight, standard, and large. The table below provides a rough common division; specific values must be based on actual measurements.

    Dimension Lightweight Standard Large
    Response latency Lowest; suitable for interactive scenarios Moderate Higher; suitable for offline or latency-tolerant tasks
    Cost per call Lowest Moderate Highest
    Suitable tasks Classification, information extraction, simple rewriting, request routing General Q&A, summarization, routine code assistance Complex reasoning, long-chain planning, troubleshooting difficult issues
    Common failure modes Complex logic may be missed Details in long documents may be missed Slow responses, cost can spiral, possible over-reasoning

    In practice, start by running the entire workflow with the standard tier. Then move high-frequency, structurally simple steps down to the lightweight tier, and move a small number of difficult steps up to the large tier. This layered approach can reduce cost while keeping quality loss manageable; the extent of the reduction must be validated with your own data.

    3. Multi-Agent Collaboration: Design Boundaries Before Concurrency

    Multi-agent collaboration means the orchestrator model splits a task into subtasks, assigns them to multiple sub-agents, and aggregates the results. Each sub-agent can have its own system prompt, context, and tool permissions.

    Implementation needs to address the following:

    1. The number of subtasks is determined jointly by task complexity and platform quotas; there is no universal fixed number. Set a concurrency limit to avoid exhausting quotas or triggering rate limits.
    2. When subtasks have dependencies, execute them in dependency order; do not run everything in parallel.
    3. Set timeouts and retry limits for every subtask. Retry only retryable errors, such as network jitter and rate limiting. Errors such as invalid parameters or insufficient permissions should fail directly.
    4. Assign tool permissions according to least privilege. A sub-agent should receive only the tools needed for its task; steps involving write operations should require human confirmation by default.
    5. Results from different sub-agents may conflict. The aggregation step needs to detect conflicts and, when necessary, route them to human review.
    6. There needs to be a rollback plan for failures. Steps that have already produced side effects, such as creating a ticket or sending a message, must be recorded and reversible.

    Below is illustrative code. It is pseudocode; the llm_api interface is hypothetical. Actual SDK names and parameters are subject to the official documentation and must not be used directly in production.

    1. import asyncio
    2. import logging
    3. MAX_CONCURRENCY = 4 # Concurrency cap, set according to platform quota
    4. SUBTASK_TIMEOUT_S = 60 # Timeout per subtask in seconds
    5. MAX_RETRIES = 2 # Retry only retryable errors
    6. ALLOWED_TOOLS = {"search_kb", "read_ticket"} # Tool allowlist for sub-agents
    7. logger = logging.getLogger("workflow")
    8. class RetryableError(Exception):
    9. """Retryable errors such as rate limiting and network jitter"""
    10. def check_permissions(requested_tools):
    11. illegal = set(requested_tools) - ALLOWED_TOOLS
    12. if illegal:
    13. raise PermissionError(f"Subtask requested unauthorized tools: {illegal}")
    14. async def run_subtask(llm_api, sub_task, semaphore):
    15. check_permissions(sub_task["required_tools"])
    16. async with semaphore:
    17. for attempt in range(MAX_RETRIES + 1):
    18. try:
    19. agent = llm_api.create_agent(
    20. role=sub_task["role"],
    21. tools=sub_task["required_tools"],
    22. )
    23. return await asyncio.wait_for(
    24. agent.execute(task_prompt=sub_task["prompt"]),
    25. timeout=SUBTASK_TIMEOUT_S,
    26. )
    27. except RetryableError as exc:
    28. logger.warning("Subtask %s failed on attempt %d: %s",
    29. sub_task["id"], attempt + 1, exc)
    30. if attempt == MAX_RETRIES:
    31. raise
    32. await asyncio.sleep(2 ** attempt)
    33. async def execute_dynamic_workflow(user_query, llm_api):
    34. if not user_query or not user_query.strip():
    35. raise ValueError("User request is empty")
    36. plan = await llm_api.plan_tasks(query=user_query)
    37. sub_tasks = plan.get("sub_tasks", [])
    38. # Dependency topological sorting is omitted here: subtasks with
    39. # prerequisites should run after their prerequisites complete
    40. semaphore = asyncio.Semaphore(MAX_CONCURRENCY)
    41. results = await asyncio.gather(
    42. *(run_subtask(llm_api, t, semaphore) for t in sub_tasks),
    43. return_exceptions=True,
    44. )
    45. ok, failed = [], []
    46. for task, res in zip(sub_tasks, results):
    47. if isinstance(res, BaseException):
    48. failed.append(task["id"])
    49. logger.error("Subtask %s failed: %r", task["id"], res)
    50. else:
    51. ok.append(res)
    52. # Handling strategy for partial failure (degraded output or human
    53. # handoff) must be decided by the business
    54. return await llm_api.synthesize(ok, failed=failed)

    This code demonstrates four control points: concurrency limit, timeout, bounded retries, and tool allowlist. Dependency ordering, rollback, and audit logs are not implemented and must be added before launch.

    4. Reasoning Mechanisms: What Can and Cannot Be Said

    Some models perform internal reasoning before outputting final text, sometimes called a thinking process. Implementations and visibility vary widely across vendors; some provide only a summary, while others do not expose it at all.

    Whether this kind of reasoning helps a given task is an empirical question. Prepare 50 to 200 representative samples, run them with reasoning mode enabled and disabled, and compare accuracy, response time, and cost. Reasoning usually increases latency and expense; do not assume by default that “more reasoning” means “better results.”

    The reasoning process a model displays also does not necessarily faithfully reflect the actual path by which it reached the answer. During debugging, rely on input/output evaluation results rather than only on the reasoning text.

    5. Third-Party Tools and Open Integrations

    Models increasingly interact with external tools, data sources, and development frameworks through function calling or protocolized connectors. This expands what models can accomplish, and it also expands the risk surface. The main risks include the following:

    • Tool invocation overreach: the model may call tools beyond the intent of the task. Permissions must be validated on the server side.