Agent实战系列:控制 LLM 输出指定格式:Agent 的免微调对齐
LLM 驱动的 Agent 在进行工具使用,与其他系统进行交互时,通常需要输出严格的格式,例如 JSON。但 LLM 的生成结果依赖 prompt,在一些参数量较小的模型上,输出通常也不稳定。格式不正确的生成结果将导致下游任务失败,微调可以缓解这样的问题,但是在所有下游任务上都进行微调对齐的成本很高。本文尝试对 prompt 和 sampling 在 schema 的引导下进行控制,使 LLM 严格输出正确的格式,提升 Agent 调用下的效果。
1.面临常见问题
在 Agent 场景下,我们可能会给出类似这样的 prompt。(例子修改自 AgentBench 的 os-interaction 任务)
- system
You are an assistant that will act like a person, I'will play the role of linux(ubuntu) operating system. Your goal is to implement the operations required by me or answer to the question proposed by me. For each of your turn, you should first think what you should do, and then take exact one of the three actions: