A Practical Guide to Compute, Model Serving, and AI Agent Deployment

    This article explains how to move AI from pilot projects to scaled production by treating it as an engineered pipeline rather than a single feature. It presents a four-layer architecture (infrastructure, model serving, capability orchestration, and application/governance), then covers workload profiling, resource pooling and quotas, storage and data paths, a unified MaaS gateway with routing and batching, token metering and cost optimization, agent design with tool contracts and human-in-the-loop control, observability and security governance, and a three-stage evolution roadmap. The guidance is vendor-neutral and focuses on general engineering practices.

    1. Why AI Adoption Stalls in the Middle Layer

    AI is moving from question answering and content generation toward task planning, tool invocation, and multi-step execution. For enterprises, this means AI is no longer just a feature module; it is a production line that must be operated with engineering discipline. Many teams perform well in pilots but hit three typical problems at scale: uneven compute utilization, model services that cannot reliably handle business peaks, and a lack of unified evaluation and governance on the application side.

    In public technical discussions, Baidu AI Cloud often frames this progression as layered coordination across compute, platform, and application. This article follows that layered view but focuses on general engineering practices and does not depend on any vendor-specific interfaces.

    2. Overall Architecture: Four Decoupled Layers

    Split the AI system into four layers that communicate through explicit contracts:

    1. Infrastructure layer: compute, storage, networking, and container orchestration.
    2. Model serving layer: model hosting, inference acceleration, batching, and queues.
    3. Capability orchestration layer: MaaS platform, tool registry, workflows, and agent runtime.
    4. Application and governance layer: business applications, evaluation, observability, cost, and permissions.

    The main benefit of decoupling is replaceability: the inference backend can be swapped, models can be rolled out gradually, and applications do not need to be rewritten.

    1. Business apps / agents
    2. │ (standard invocation contract)
    3. Capability orchestration (MaaS / tools / workflows)
    4. │ (inference requests / batch jobs)
    5. Model serving (hosting / acceleration / queues)
    6. │ (scheduling / storage / networking)
    7. Infrastructure (containers / object storage / message queues)

    3. Compute and Cloud Infrastructure: From Stacking GPUs to Scheduling

    3.1 Start with a Workload Profile

    Before purchasing or scaling up, profile the workload: distribution of input and output lengths, peak concurrency, latency targets (time to first token and end-to-end latency), and whether requests can be batched. The profile determines the resource shape: latency-sensitive workloads suit always-on inference clusters, while throughput-oriented workloads suit batch processing and elastic queues.

    3.2 Pooling and Quotas

    Split resources into a shared pool and a dedicated pool. The shared pool handles development, debugging, and low-priority jobs; the dedicated pool protects SLAs for core business. Allocate quotas by team rather than by individual, and set burst limits so a single team cannot fill the cluster.

    3.3 Storage and Data Paths

    Keep training and retrieval data in object storage, and use local caching to accelerate hot data. Data versioning (immutable buckets plus version numbers) is a prerequisite for reproducible experiments. On the data path, use message queues to absorb spikes and turn synchronous waiting into asynchronous confirmation.

    4. Model-as-a-Service (MaaS): A Unified Entry Point with Governance

    The value of MaaS is not connecting a few more models; it is treating models as services that can be operated.

    4.1 Unified Gateway

    The gateway handles authentication, rate limiting, routing, gradual rollout, and auditing. The routing layer selects backends by capability label rather than model name, which makes later replacement easier.

    1. # Example: capability-based routing with timeout and retry
    2. def call_model(capability: str, payload: dict):
    3. endpoint = registry.resolve(capability) # capability -> backend
    4. for attempt in range(2):
    5. try:
    6. return client.post(endpoint, json=payload, timeout=8)
    7. except TimeoutError:
    8. if attempt == 1:
    9. raise

    4.2 Batching and Priority

    Classify requests into real-time, near-real-time, and offline tiers. Offline jobs go through batch queues, which significantly improves overall resource efficiency; real-time requests keep a separate channel so they are not blocked by long-running jobs.

    4.3 Evaluation and Regression

    Before launch, establish an offline evaluation set plus online sampled evaluation. Metrics should cover at least task success rate, structured-output compliance rate, tool-call accuracy, and human takeover rate. Model iteration without a regression set is effectively a blind change.

    5. Token Production and Operations: Treat Usage as a Cost Center

    Tokens are the unit of measurement for model services and the smallest granularity for cost governance. Operate in three areas:

    • Metering: tag usage by tenant, application, and session to produce drill-down billing.
    • Budgets: set daily or monthly caps and alert thresholds for each application.
    • Optimization: prompt compression, context trimming, cache reuse (shared prefixes hit the cache), and routing to smaller models.
    1. Cost ≈ Σ(input tokens × unit_price_in + output tokens × unit_price_out) + resource usage cost
    2. Optimization priority: cut useless context > cache reuse > model tiering > batch discounts

    Note that unit prices and discounts are commercial and operational decisions and should follow the actual agreement. Architecturally, make pricing policy configurable rather than hard-coded.

    6. Agent Applications: From Generation to Execution

    The essential difference between an agent and a chatbot is that an agent calls tools and plans across multiple steps. Key practices:

    1. Tool contracts: each tool declares its name, purpose, input schema, permission scope, and failure semantics.
    2. Controllable planning: set a maximum number of steps, a per-step timeout, and rollback points to prevent infinite loops.
    3. Human in the loop: high-risk actions (write operations, external publishing, anything involving funds) require human confirmation.
    4. Externalized state: store session and task state in external storage to support resume-from-breakpoint and audit replay.
    1. {
    2. "tool": "create_ticket",
    3. "input_schema": {"type": "object", "properties": {"title": {"type": "string"}}},
    4. "permission": "write:ticket",
    5. "require_human_approval": true
    6. }

    7. Observability and Security Governance

    • Observability: tracing must span the gateway, orchestration layer, and inference layer; key metrics include queue time, time to first token, failure rate, and tool error rate.
    • Log redaction: prompts and outputs may contain sensitive information, so classify and redact before storage.
    • Least privilege: separate permissions for models, tools, and data, and issue short-lived credentials per application.
    • Content safety: filter both input and output, and keep disposition records for traceability.

    8. Evolution Roadmap: Three Stages

    Stage 1 (0–1 month): connect the gateway and metering, and close the loop on one or two high-frequency scenarios.
    Stage 2 (1–3 months): introduce batching and caching, and establish evaluation regression and alerting.
    Stage 3 (3 months and beyond): let agents take over multi-step processes, and complete the cost center and governance dashboard.

    9. Conclusion

    The difficulty of scaling AI lies not in the capability of a single model but in the coordination efficiency across compute scheduling, model serving, capability orchestration, and governance operations. Make each layer replaceable, measurable, and observable, and enterprises can maintain stable intelligent output despite business fluctuations.