一、Agent介绍1、设计目标在传统的大模型应用中LLM 往往只是一个“问答器”输入问题输出答案。但在实际业务中这种模式很难应对复杂任务尤其是涉及多轮交互、决策和执行的场景。因此我们引入 Agent 的概念。Agent 的核心目标是构建一个有状态、可追踪、可控制的智能体用于处理复杂任务。2、定义因此可以把 Agent 理解为一个以 LLM 为核心具备理解、规划与执行能力的智能系统3、本质二、设计技巧1、状态管理——从对话到状态机在多轮交互场景中Agent 不再是无状态的请求-响应而是一个持续演进的状态系统。一种经典建模方式是将 Agent 抽象为有限状态机FSMM (S, I, T, s0)。状态机 伪代码enum State { INIT, ASK_FROM, ASK_TO, ASK_DATE, SEARCH, DONE } class Context { State state State.INIT; String fromCity; String toCity; String date; } class AgentService { private LLMClient llm; private TicketTool ticketTool; public String handle(String userInput, Context ctx) { switch (ctx.state) { case INIT: ctx.state State.ASK_FROM; return 请问您从哪个城市出发; case ASK_FROM: String from llm.extractField(fromCity, userInput, ctx); if (from null) { return 请再说一下出发城市; } ctx.fromCity from; ctx.state State.ASK_TO; return 您要去哪个城市; case ASK_TO: String to llm.extractField(toCity, userInput, ctx); if (to null) { return 请再说一下目的地城市; } ctx.toCity to; ctx.state State.ASK_DATE; return 您计划哪天出发; case ASK_DATE: String date llm.extractField(date, userInput, ctx); if (date null) { return 请再说一下出发日期; } ctx.date date; ctx.state State.SEARCH; return handleSearch(ctx); case SEARCH: return handleSearch(ctx); case DONE: return 流程已完成; default: return 系统异常; } } private String handleSearch(Context ctx) { String result ticketTool.query(ctx.fromCity, ctx.toCity, ctx.date); ctx.state State.DONE; return result; } } interface LLMClient { String extractField(String fieldName, String userInput, Context ctx); } interface TicketTool { String query(String fromCity, String toCity, String date); }2、上下文保持——记忆如何落地