Agent Development in Practice: A Guide to Building a Chinese-Language Handbook

    This article explains why agent projects need a structured handbook and how to build one. It covers core agent concepts and capability boundaries, a layered reference architecture, practical prompt and tool orchestration, memory and context management, and an evaluation, monitoring, and iteration loop. It also lists common pitfalls and acceptance criteria to help teams deliver agent capabilities reliably and at a controlled cost.

    1. Why You Need a Structured Agent Handbook

    In real development work, agent projects often fail not because the model lacks capability, but because the team lacks a shared vocabulary and engineering standards. Terms such as “tool calling,” “memory,” and “planning” are frequently used interchangeably, so requirements reviews turn into people talking past each other and integration work requires repeated rework. A structured handbook makes implicit experience explicit: it serves both as onboarding material for new members and as a checklist for reviews, testing, and release.

    From a content organization perspective, a handbook should cover at least four layers: the concept layer (what an agent is and where its boundaries lie), the architecture layer (how modules are split and how they communicate), the implementation layer (how prompts, tools, and state are put in place), and the operations layer (how evaluation, monitoring, and iteration are carried out). If any of these layers is missing, the handbook degrades into either a “concept primer” or a “collection of code snippets” and cannot support a real project.

    2. Core Agent Concepts and Capability Boundaries

    The widely accepted definition of an agent is a system that uses a model as its decision-making core, can perceive input and perform reasoning and planning, changes the state of the environment by calling external tools, and then continues making decisions based on feedback. The key difference from an ordinary conversational application is the “closed loop”: there is a goal, an action, an observation, and a further decision.

    Boundaries need to be made explicit to avoid overstating capabilities:

    • An agent is not “fully automatic.” It needs guardrails for permissions, cost, and risk.
    • An agent does not have “unlimited memory.” Context length and retrieval quality together determine how much information is usable.
    • An agent is not “necessarily correct.” Both planning and tool calling introduce new failure modes.

    The handbook should describe capabilities with a matrix covering goal understanding, task decomposition, tool selection, argument construction, result validation, and fallback on errors. Each item should be marked “currently supported / planned / not supported” to prevent inaccurate external promises.

    3. Reference Architecture: A Layered, Decoupled Engineering Skeleton

    A maintainable agent system is usually divided into five layers, and the layers communicate through explicit data structures rather than implicit global variables.

    1. Access layer: handles session management, identity and permission checks, and input sanitization.
    2. Orchestration layer: handles task decomposition, step scheduling, tool selection, and retry policies.
    3. Capability layer: wraps tools and retrieval capabilities behind a unified input/output schema.
    4. State layer: stores short-term context and long-term memory, with support for reads, writes, and expiry.
    5. Observability layer: records traces, metrics, and evaluation results to support regression testing and tuning.

    Illustrative interface skeleton (structure only; it does not represent any specific product API):

    1. class AgentContext:
    2. def __init__(self, session_id: str):
    3. self.session_id = session_id
    4. self.short_term = [] # Context for the current task
    5. self.long_term = {} # Structured long-term memory
    6. class Tool:
    7. name: str
    8. schema: dict
    9. def run(self, args: dict) -> dict: ...
    10. class Planner:
    11. def plan(self, goal: str, ctx: AgentContext) -> list[dict]: ...
    12. class Executor:
    13. def step(self, action: dict, ctx: AgentContext) -> dict: ...
    14. class AgentLoop:
    15. def __init__(self, planner, executor, tools, max_steps=8):
    16. self.planner, self.executor = planner, executor
    17. self.tools, self.max_steps = tools, max_steps
    18. def run(self, goal: str, ctx: AgentContext):
    19. for _ in range(self.max_steps):
    20. actions = self.planner.plan(goal, ctx)
    21. for a in actions:
    22. obs = self.executor.step(a, ctx)
    23. ctx.short_term.append({"action": a, "observation": obs})
    24. if self._done(ctx):
    25. break
    26. return ctx.short_term

    The benefit of layering is a low replacement cost: swapping the model only changes the orchestration layer’s policy, swapping retrieval only changes the capability layer’s implementation, and the observability layer stays unchanged.

    4. Practical Points for Prompts and Tool Orchestration

    In agent scenarios, prompt engineering is responsible for “constraints” rather than “performance.” It is advisable to split the prompt into four parts: role and goal, the list of available tools and calling conventions, output format constraints, and failure-handling conventions. The tool list must be generated programmatically to avoid mismatches with the actual registry caused by hand-writing.

    A tool description should state three things clearly: its purpose, the meaning of its parameters, and the shape of its failure return. Parameter validation belongs at the tool entry point; invalid input should return a structured error immediately rather than throwing an exception that interrupts the whole loop.

    1. {
    2. "name": "search_docs",
    3. "description": "Retrieve passages relevant to the question from the internal knowledge base",
    4. "parameters": {
    5. "query": {"type": "string", "required": true},
    6. "top_k": {"type": "integer", "default": 5}
    7. },
    8. "on_error": {"type": "object", "fields": ["code", "message"]}
    9. }

    The orchestration layer should adopt a “small steps, fast iterations” strategy: each step does only one thing and produces a verifiable intermediate result; set a maximum number of steps and a timeout to prevent infinite loops; for write-type tools, add a second confirmation and an idempotency key.

    5. Memory and Context Management

    Short-term context should keep only the fragments strongly related to the current goal, using “summary compression plus key entity retention” to control size. Long-term memory should be stored in a structured way and indexed along three dimensions: user, task, and time. Deduplication and conflict resolution should happen before writing, and reads should be ordered by relevance and freshness.

    It is important to stress that more memory is not better. Incorrect memory keeps polluting decisions, so there must be an explicit forgetting mechanism and a manual correction entry point, and the source of every memory change should be recorded for traceability.

    6. Evaluation, Monitoring, and the Iteration Loop

    Agent evaluation should have three levels: single-tool correctness, single-task completion rate, and end-to-end business metrics. Maintain a fixed test suite that covers four types of scenarios: normal paths, boundary inputs, tool failures, and insufficient permissions. Run a regression on every prompt or tool implementation change.

    Online observability should include at least the step-count distribution, tool call success rate, average latency, human takeover rate, and clustering of failure reasons. When a metric looks abnormal, first determine whether the problem lies in planning, arguments, or the tool, and then decide whether to change the prompt, the tool, or the process.

    For the iteration cadence, run offline evaluation first and roll out gradually afterward. During the gradual rollout, keep a one-click rollback switch to prevent problems from spreading.

    7. Common Pitfalls

    • The tool description does not match the implementation, so the model selects the wrong tool.
    • Context grows without limit, and cost and latency rise along with it.
    • There is no idempotency design, so retries cause duplicate write operations.
    • Test cases cover only the happy path, and things break immediately after release.
    • Permission checks live in the prompt rather than in code, creating a risk of privilege escalation.
    • The handbook describes only concepts and no acceptance criteria, so it cannot be put into practice.

    8. Conclusion

    Treating an agent as an engineering system that needs long-term operation, rather than a one-off demo project, is the key to whether a handbook creates value. With a layered architecture as the skeleton, tool contracts as the boundary, and an evaluation loop as the driver, plus continuously updated documentation, a team can deliver agent capabilities reliably at a controlled cost. If you need underlying resources for memory, logs, and model serving, you can combine general cloud product categories from Baidu AI Cloud as needed, such as object storage, message queues, container platforms, log services, and monitoring and alerting, while keeping the architecture neutral and replaceable.