A Practical Guide to Building AI Agents on a Platform

    This guide explains how to build AI agents quickly using a platform-based approach. It covers how to define task boundaries before development, the six core capability layers (model access, prompt and context management, RAG, tool calling, workflow orchestration, and observability), key data security and permission practices, common anti-patterns to avoid, and a four-week rollout plan focused on closing the loop on a small scenario first and expanding through data feedback.

    1. Why Fast Agent Development Has Become a Common Need

    Building a usable AI agent used to require a team to stitch together multiple layers of capability: model invocation, vector retrieval, session management, tool calling, and frontend interaction. The engineering effort was concentrated and highly repetitive. As LLM application development platforms have matured, the industry has generally broken agents down into a set of standardized modules: a model access layer, a prompt and context management layer, a knowledge retrieval layer, a tool and plugin layer, an orchestration layer, and an observability and operations layer.

    The value of a platform is not to replace developers’ thinking. It is to turn these common modules into configurable capabilities, so teams can focus their energy on business logic and data assets.

    It is worth emphasizing that an agent is not the same as a chatbot. A qualified agent typically has four characteristics: it can understand a goal and break down tasks, access external knowledge and tools, execute with conditional branching, and leave traceable run records. Whether these four points are present determines whether it is a “demo” or an “operable system.”

    2. Requirement Breakdown Before Building: Define Boundaries First, Then Choose Capabilities

    The prerequisite for fast development is a narrowed scope. Before starting, it is recommended to clarify the following five items:

    • Task boundary: which part of the workflow the agent is responsible for, and which steps must be handed off to a human.
    • Input/output contract: whether the input is text, files, or structured fields; whether the output needs to be strict JSON for downstream systems to consume.
    • Knowledge scope: whether it relies on enterprise documents, databases, or real-time APIs, and how often the knowledge is updated.
    • Permissions and compliance: which data can enter the model context, and whether masking and auditing are required.
    • Success metrics: quantifiable goals such as accuracy, first-time resolution rate, average latency, and human takeover rate.

    Once the boundaries are clear, capability selection becomes more obvious. For example, an internal policy Q&A scenario focuses on retrieval quality and traceable citations; a ticket routing scenario focuses on tool calling and rule branching; a document generation scenario focuses on long context and template control.

    3. Core Capability Map: Six Layers of Platform-Based Development

    3.1 Model Access and Switching

    Different tasks place different demands on model capabilities: long-text understanding, structured output, low-latency response, and cost-sensitive tasks each have their own preferences. In practice, it is recommended to tier models: a primary model handles complex reasoning, while lightweight models handle high-frequency, simple tasks such as classification, rewriting, and routing. Abstract a model gateway layer that hides differences through unified wrapping, making canary releases and rollbacks easier.

    1. # Example: a unified model invocation wrapper that hides differences between models
    2. def call_model(task_type, prompt, **kwargs):
    3. model = "reasoner" if task_type == "complex" else "lite"
    4. return model_gateway.invoke(model=model, prompt=prompt, **kwargs)

    3.2 Prompt and Context Management

    Prompts should be version-controlled and include a role definition, task description, constraints, output format, and a few examples. There are three key practices: write “format requirements” as a verifiable contract; list “prohibited actions” explicitly; and split long instructions into a system section and a user section to avoid interference. Because the context window is limited, you need to design trimming and summarization strategies that prioritize keeping the fragments most relevant to the current question.

    3.3 Retrieval-Augmented Generation (RAG)

    Retrieval quality sets the upper limit on answer quality. Engineering typically includes document parsing and cleaning, chunking strategy, vectorization, index building, recall and reranking, and citation backfilling. Chunk granularity should match the document structure; tabular and clause-based content should retain structural information. For the recall stage, it is recommended to use a hybrid of “vector recall + keyword recall,” then improve relevance with a reranking model. The final answer should include source fragments for manual verification.

    3.4 Tool and Plugin Invocation

    A tool description is essentially API documentation written for the model to read. It needs to clearly state the purpose, parameters, return structure, and failure semantics. It is recommended to set timeouts, retries, and idempotency constraints for tools, and add a confirmation step for high-risk operations.

    1. {
    2. "name": "query_order_status",
    3. "description": "Query order status by order ID; read-only queries only",
    4. "parameters": {"order_id": "string"},
    5. "returns": {"status": "string", "updated_at": "string"}
    6. }

    3.5 Workflow Orchestration

    Complex tasks are more clearly expressed with a directed graph: a start node, model nodes, conditional branches, code execution, knowledge retrieval, tool calls, and an end node. The value of orchestration is to turn “implicit reasoning” into an “explicit process,” making it testable, diagnosable, and optimizable. For steps with strong determinism, replacing model judgment with rules and code is often more stable and more cost-effective.

    3.6 Observability, Logging, and the Data Loop

    Going live is only the starting point. You need to record the input summary, retrieval hits, tool calls, elapsed time, and result status of each run to form a replayable trace. Use logs to cluster errors and feed failed samples back into an evaluation set and labeled data, driving iteration on prompts and chunking strategies. When sensitive information is involved, logs need to be masked and given a retention period.

    4. Key Data Security and Permission Design Points

    • Minimize data channels: transmit only the fields necessary to complete the task, and mask sensitive fields before they enter the model.
    • Tenant and knowledge base isolation: separate indexes and credentials for different business lines to avoid unauthorized recall.
    • Credential hosting: host model and tool keys centrally; never hardcode them in the frontend or repository.
    • Output-side protection: apply whitelists and secondary confirmation to downstream executable actions to prevent mistakes.
    • Auditing and traceability: keep traceable records of key operations to meet internal audit requirements.

    If you use cloud infrastructure, you can typically combine object storage to hold original documents, a message queue for asynchronous decoupling, a container platform to host inference and orchestration services, and logging and monitoring with alerting to ensure observability, forming a common and replaceable technical foundation.

    5. Common Anti-Patterns and How to Avoid Them

    • Only tuning prompts without evaluation: without a baseline, optimization is all guesswork. Build a small evaluation set first.
    • Using a single chunking strategy for everything: different document structures require different parsing and chunking approaches.
    • Having the model handle deterministic logic: if code and rules can solve it, do not hand it to the model.
    • Answering without citations: a lack of citation backfilling significantly reduces trustworthiness and maintainability.
    • One giant prompt: instructions that are too long and conflict with each other reduce model adherence.

    Complete scenario narrowing and a first draft of the evaluation set in week one; connect model access, knowledge retrieval, and a minimum viable pipeline in week two; add tool calling, branch orchestration, and log observability in week three; and run canary releases, error clustering, and iterative optimization in week four. In related practice, Baidu AI Cloud typically recommends advancing with a “small-scenario closed loop + data feedback” approach: prove value first, then expand horizontally, avoiding a one-time full rollout that leads to out-of-control maintenance costs.

    Overall, the key to building agents quickly is not any single capability, but organizing the model, knowledge, tools, orchestration, and observability into a measurable, iterable engineering pipeline. Once this pipeline is running, adding new scenarios is mostly configuration and data work rather than reinventing the wheel.