Skip to content

Commit 695dbf0

Browse files
fix(ace): Refine reflector to use only input fields (#464)
The AxACE optimizer's reflector was previously using the entire training example as the "question" for reflection, including output fields. This caused confusion, as the reflector was seeing both the inputs and the expected outputs, leading to inaccurate and unhelpful reflections. This commit fixes the issue by ensuring that only the input fields from an example are used as the "question" for the reflector. The code now retrieves the program's signature, identifies the defined input fields, and constructs a `questionContext` object containing only the input key-value pairs from the full example. By providing a clean separation between the input and output, the reflector can now generate more accurate and relevant insights, improving the overall effectiveness of the ACE optimization loop. Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
1 parent d4acef2 commit 695dbf0

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/ax/dsp/optimizers/ace.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -974,8 +974,20 @@ export class AxACE extends AxBaseOptimizer {
974974
severity: (example as { severity?: string })?.severity,
975975
policyHint: (example as { policyHint?: string })?.policyHint,
976976
};
977+
const signature = this.program?.getSignature();
978+
const inputFields = signature?.getInputFields() ?? [];
979+
const questionContext = inputFields.reduce(
980+
(acc, field) => {
981+
if (field.name in example) {
982+
acc[field.name] = example[field.name as keyof typeof example];
983+
}
984+
return acc;
985+
},
986+
{} as Record<string, unknown>
987+
);
988+
977989
const reflectionRaw = await reflector.forward(reflectorAI, {
978-
question: JSON.stringify(example),
990+
question: JSON.stringify(questionContext),
979991
generator_answer: JSON.stringify(generatorOutput.answer),
980992
generator_reasoning: generatorOutput.reasoning,
981993
playbook: JSON.stringify({

0 commit comments

Comments
 (0)