fix(consult): 申报时段计算改为服务端预跑并走同请求缓存(BUG-957)
窗口计算挂在 agent context 缓存上,模型开口前预跑并注入 packet;工具再调用命中同请求缓存,成功次数仍为 1。
This commit is contained in:
@@ -38,7 +38,7 @@ import { jsonForSupabaseSetupFailure } from "@/lib/api/service-unavailable";
|
||||
import { createAdminSupabaseClient } from "@/lib/supabase/admin";
|
||||
import { createServerSupabaseClient } from "@/lib/supabase/server";
|
||||
import { streamTextResponse } from "@/lib/stream-text-response";
|
||||
import { streamAgentResponse } from "@/lib/stream-agent-response";
|
||||
import { consultationPublicActivityEvent, streamAgentResponse } from "@/lib/stream-agent-response";
|
||||
import type { AgentExecutionReceipt, WorkflowReceipt } from "@/lib/consultation-agent-events";
|
||||
import { consultationComposePrompt, consultationContinuePrompt, natalConsultationThinkingPlan, type PublicThinkingSection } from "@/lib/consultation-thinking-plan";
|
||||
import {
|
||||
@@ -51,6 +51,8 @@ import {
|
||||
consultationWindowPrepareStep,
|
||||
createConsultationAgentContext,
|
||||
createWindowConsultationAgentContext,
|
||||
precomputeWindowConsultation,
|
||||
windowPrecomputedPacketMessage,
|
||||
consultationModelStepTelemetry,
|
||||
consultationStepBudgetReceipt,
|
||||
createConsultationRuntimeHooks,
|
||||
@@ -1039,7 +1041,6 @@ export async function POST(request: Request) {
|
||||
state,
|
||||
});
|
||||
const agent = getWindowJyotishAgent(selectedModel, agentContext);
|
||||
const result = await streamWithOverflowRetry(agent, windowStreamOptions);
|
||||
const retry = async () => {
|
||||
const retried = await agent.stream([
|
||||
...baseMessages,
|
||||
@@ -1096,7 +1097,32 @@ export async function POST(request: Request) {
|
||||
requestId,
|
||||
sideEvent: titleSideEvent,
|
||||
state,
|
||||
stream: result.fullStream,
|
||||
warmup: async (send) => {
|
||||
try {
|
||||
const packet = await precomputeWindowConsultation(agentContext, {
|
||||
question: resolvedQuestion.modelQuestion,
|
||||
writer: {
|
||||
custom: async (chunk) => {
|
||||
if (!chunk || typeof chunk !== "object") return;
|
||||
const value = chunk as { type?: unknown; data?: unknown };
|
||||
if (value.type !== "data-jyotish-activity") return;
|
||||
const event = consultationPublicActivityEvent(value.data);
|
||||
if (event) send(event);
|
||||
},
|
||||
},
|
||||
});
|
||||
baseMessages = [
|
||||
...baseMessages,
|
||||
{ role: "user" as const, content: windowPrecomputedPacketMessage(packet) },
|
||||
];
|
||||
} catch {
|
||||
// Leave the contract red; the model may still call the tool.
|
||||
}
|
||||
},
|
||||
stream: async () => {
|
||||
const streamed = await streamWithOverflowRetry(agent, windowStreamOptions);
|
||||
return streamed.fullStream;
|
||||
},
|
||||
requireTool: true,
|
||||
retry,
|
||||
retryForAnswer,
|
||||
|
||||
Reference in New Issue
Block a user