Skip to content

Commit

Permalink
fix: Use plain tool calls for reflection generation
Browse files Browse the repository at this point in the history
  • Loading branch information
bracesproul committed Oct 18, 2024
1 parent 6eef340 commit 4eda7c1
Showing 1 changed file with 20 additions and 13 deletions.
33 changes: 20 additions & 13 deletions src/agent/reflection/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,23 @@ export const reflect = async (
? formatReflections(memories.value as Reflections)
: "No reflections found.";

const generateReflectionsSchema = z.object({
styleRules: z
.array(z.string())
.describe("The complete new list of style rules and guidelines."),
content: z
.array(z.string())
.describe("The complete new list of memories/facts about the user."),
});
const generateReflectionTool = {
name: "generate_reflections",
description: "Generate reflections based on the context provided.",
schema: z.object({
styleRules: z
.array(z.string())
.describe("The complete new list of style rules and guidelines."),
content: z
.array(z.string())
.describe("The complete new list of memories/facts about the user."),
}),
};

const model = new ChatAnthropic({
model: "claude-3-5-sonnet-20240620",
temperature: 0,
}).withStructuredOutput(generateReflectionsSchema, {
name: "generate_reflections",
});
}).bindTools([generateReflectionTool]);

const formattedSystemPrompt = REFLECT_SYSTEM_PROMPT.replace(
"{artifact}",
Expand All @@ -65,10 +67,15 @@ export const reflect = async (
content: formattedUserPrompt,
},
]);
const reflectionToolCall = result.tool_calls?.[0];
if (!reflectionToolCall) {
console.error("FAILED TO GENERATE TOOL CALL", result);
throw new Error("Reflection tool call failed.");
}

const newMemories = {
styleRules: result.styleRules,
content: result.content,
styleRules: reflectionToolCall.args.styleRules,
content: reflectionToolCall.args.content,
};

await store.put(memoryNamespace, memoryKey, newMemories);
Expand Down

0 comments on commit 4eda7c1

Please sign in to comment.