Skip to content

Commit

Permalink
refactor: agent schema
Browse files Browse the repository at this point in the history
  • Loading branch information
hanxiao committed Mar 1, 2025
1 parent 9bf5c20 commit 46fd2d0
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
3 changes: 2 additions & 1 deletion src/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,8 @@ export async function getResponse(question?: string,
messages = [{role: 'user', content: question.trim()}]
}

const SchemaGen = new Schemas(question);
const SchemaGen = new Schemas();
await SchemaGen.setLanguage(question)
const context: TrackerContext = {
tokenTracker: existingContext?.tokenTracker || new TokenTracker(tokenBudget),
actionTracker: existingContext?.actionTracker || new ActionTracker()
Expand Down
5 changes: 3 additions & 2 deletions src/tools/evaluator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ Answer: ${answer}`

function getQuestionEvaluationPrompt(question: string): PromptPair {
return {
system: `You are an evaluator that determines if a question requires freshness, plurality, and/or completeness checks in addition to the required definitiveness check.
system: `You are an evaluator that determines if a question requires freshness, plurality, and/or completeness checks.
<evaluation_types>
1. freshness - Checks if the question is time-sensitive or requires very recent information
Expand Down Expand Up @@ -399,7 +399,7 @@ function getQuestionEvaluationPrompt(question: string): PromptPair {
* Named time periods: "Renaissance and Industrial Revolution"
- Look for explicitly named elements separated by commas, "and", "or", bullets
- Example patterns: "comparing X and Y", "differences between A, B, and C", "both P and Q"
- DO NOT trigger for elements that aren't specifically named
- DO NOT trigger for elements that aren't specifically named
</rules>
<examples>
Expand Down Expand Up @@ -498,6 +498,7 @@ Hier geht's um Investieren in der 'heutigen Wirtschaft', also brauche ich aktuel
</output>
</example-8>
</examples>
`,
user:
`${question}
Expand Down
18 changes: 9 additions & 9 deletions src/utils/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,18 +64,18 @@ export class Schemas {
public languageCode: string = 'en';


constructor(query: string) {
async setLanguage(query: string) {
const generator = new ObjectGeneratorSafe();

generator.generateObject({
const result = await generator.generateObject({
model: 'evaluator',
schema: this.getLanguageSchema(),
prompt: getLanguagePrompt(query.slice(0, 100)),
}).then((result) => {
this.languageCode = result.object.langCode;
this.languageStyle = result.object.langStyle;
console.log(`langauge`, result.object);
});

this.languageCode = result.object.langCode;
this.languageStyle = result.object.langStyle;
console.log(`langauge`, result.object);
}

getLanguagePrompt() {
Expand All @@ -91,10 +91,10 @@ export class Schemas {

getQuestionEvaluateSchema(): z.ZodObject<any> {
return z.object({
needsFreshness: z.boolean().describe('If the question requires freshness check'),
needsPlurality: z.boolean().describe('If the question requires plurality check'),
needsCompleteness: z.boolean().describe('If the question requires completeness check'),
think: z.string().describe(`A very concise explain of why those checks are needed. ${this.getLanguagePrompt()}`).max(500),
needsFreshness: z.boolean(),
needsPlurality: z.boolean(),
needsCompleteness: z.boolean(),
});
}

Expand Down

0 comments on commit 46fd2d0

Please sign in to comment.