Fix cycle failures on OpenRouter by disabling structured cycle output
This commit is contained in:
@@ -849,21 +849,10 @@ export async function runLangGraphCrmAgentFor(input: {
|
||||
: {}),
|
||||
});
|
||||
|
||||
const agent = useGigachat
|
||||
? createReactAgent({
|
||||
llm: model,
|
||||
tools: [crmTool],
|
||||
})
|
||||
: createReactAgent({
|
||||
llm: model,
|
||||
tools: [crmTool],
|
||||
responseFormat: z.object({
|
||||
answer: z.string().describe("Final assistant answer for the user."),
|
||||
done: z.boolean().describe("Whether objective is complete in this cycle."),
|
||||
progressSummary: z.string().optional().describe("One-line progress note for system trace."),
|
||||
nextStep: z.string().optional().describe("Short next step if not done."),
|
||||
}),
|
||||
});
|
||||
const agent = createReactAgent({
|
||||
llm: model,
|
||||
tools: [crmTool],
|
||||
});
|
||||
|
||||
const maxCycles = Math.max(1, Math.min(Number(process.env.CF_AGENT_MAX_CYCLES ?? "3"), 8));
|
||||
const cycleTimeoutMs = Math.max(5000, Math.min(Number(process.env.CF_AGENT_CYCLE_TIMEOUT_MS ?? "1200000"), 1800000));
|
||||
@@ -924,9 +913,6 @@ export async function runLangGraphCrmAgentFor(input: {
|
||||
};
|
||||
|
||||
const extractResult = (res: any) => {
|
||||
const structured = res?.structuredResponse as
|
||||
| { answer?: string; done?: boolean; progressSummary?: string; nextStep?: string }
|
||||
| undefined;
|
||||
const fallbackText = (() => {
|
||||
const messages = Array.isArray(res?.messages) ? res.messages : [];
|
||||
for (let i = messages.length - 1; i >= 0; i -= 1) {
|
||||
@@ -940,10 +926,7 @@ export async function runLangGraphCrmAgentFor(input: {
|
||||
})();
|
||||
|
||||
return {
|
||||
text: (structured?.answer?.trim() || fallbackText).trim(),
|
||||
done: typeof structured?.done === "boolean" ? structured.done : undefined,
|
||||
progressSummary: (structured?.progressSummary ?? "").trim(),
|
||||
nextStep: (structured?.nextStep ?? "").trim(),
|
||||
text: fallbackText.trim(),
|
||||
};
|
||||
};
|
||||
|
||||
@@ -995,9 +978,7 @@ export async function runLangGraphCrmAgentFor(input: {
|
||||
|
||||
const progressed =
|
||||
toolRuns.length > beforeRuns || dbWrites.length > beforeWrites || pendingChanges.length !== beforePending;
|
||||
if (parsed.progressSummary) {
|
||||
cycleNotes.push(parsed.progressSummary);
|
||||
} else if (progressed) {
|
||||
if (progressed) {
|
||||
cycleNotes.push(`Cycle ${cycle}: updated tools/data state.`);
|
||||
}
|
||||
|
||||
@@ -1011,10 +992,7 @@ export async function runLangGraphCrmAgentFor(input: {
|
||||
consecutiveNoProgress = 0;
|
||||
}
|
||||
|
||||
const done =
|
||||
typeof parsed.done === "boolean"
|
||||
? parsed.done
|
||||
: (!progressed && cycle > 1) || cycle === maxCycles;
|
||||
const done = (!progressed && cycle > 1) || cycle === maxCycles;
|
||||
if (done) {
|
||||
await emitTrace({ text: `Cycle ${cycle}/${maxCycles}: done` });
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user