Initialize onboarding agent scaffold
This commit is contained in:
commit
4294f3c92e
57 files changed
+14388
No files matched your search
@@ -0,0 +1,53 @@
|
||||
import type { ChatMessage } from "@llm/types";
|
||||
import type { DerivedState } from "../state/onboarding-state.js";
|
||||
import type { OnboardingSession, PromptContext } from "../types.js";
|
||||
import {
|
||||
contextLayer,
|
||||
examplesLayer,
|
||||
personaLayer,
|
||||
policyLayer,
|
||||
stateLayer,
|
||||
} from "./layers.js";
|
||||
|
||||
export class PromptBuilder {
|
||||
private constructor(
|
||||
private readonly derived: DerivedState,
|
||||
private readonly session: OnboardingSession | null,
|
||||
private readonly context: PromptContext,
|
||||
) {}
|
||||
|
||||
static forDerived(
|
||||
derived: DerivedState,
|
||||
session: OnboardingSession | null,
|
||||
context: PromptContext,
|
||||
): PromptBuilder {
|
||||
return new PromptBuilder(derived, session, context);
|
||||
}
|
||||
|
||||
build(): ChatMessage[] {
|
||||
const promptHistory = this.context.summary
|
||||
? this.context.conversationHistory.slice(-5)
|
||||
: this.context.conversationHistory;
|
||||
const promptContext: PromptContext = {
|
||||
...this.context,
|
||||
conversationHistory: promptHistory,
|
||||
};
|
||||
|
||||
const systemPrompt = [
|
||||
personaLayer(),
|
||||
policyLayer(this.derived.intent),
|
||||
stateLayer(this.session, this.derived),
|
||||
examplesLayer(this.derived.intent),
|
||||
contextLayer(promptContext),
|
||||
].join("\n\n");
|
||||
|
||||
return [
|
||||
{ role: "system", content: systemPrompt },
|
||||
...promptHistory.map((message) => ({
|
||||
role: message.role,
|
||||
content: message.content,
|
||||
})),
|
||||
{ role: "user", content: this.context.userMessage },
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user