diff --git a/langgraph.json b/langgraph.json index a6cb195..7e1c257 100644 --- a/langgraph.json +++ b/langgraph.json @@ -1,6 +1,5 @@ { "node_version": "20", - "python_version": "3.12", "graphs": { "ingest_data": "./src/agents/ingest-data/ingest-data-graph.ts:graph", "generate_post": "./src/agents/generate-post/generate-post-graph.ts:generatePostGraph", @@ -11,10 +10,9 @@ "verify_reddit_post": "./src/agents/verify-reddit-post/verify-reddit-post-graph.ts:verifyRedditPostGraph", "verify_tweet": "./src/agents/verify-tweet/verify-tweet-graph.ts:verifyTweetGraph", "supervisor": "./src/agents/supervisor/supervisor-graph.ts:supervisorGraph", - "generate_report": "./src/agents/generate-report/index.ts:generateReportGraph", - "memory": "./memory-v2/memory_v2/graph.py:graph" + "generate_report": "./src/agents/generate-report/index.ts:generateReportGraph" }, "env": ".env", - "dependencies": [".", "./memory-v2"], + "dependencies": ["."], "dockerfile_lines": ["RUN npx -y playwright@1.49.1 install --with-deps"] } diff --git a/src/agents/generate-post/nodes/rewrite-post.ts b/src/agents/generate-post/nodes/rewrite-post.ts index cd75884..2fd6ec5 100644 --- a/src/agents/generate-post/nodes/rewrite-post.ts +++ b/src/agents/generate-post/nodes/rewrite-post.ts @@ -21,6 +21,7 @@ Listen to your boss closely, and make the necessary changes to the post. You sho interface RunReflectionsArgs { originalPost: string; + newPost: string; userResponse: string; } @@ -30,6 +31,7 @@ interface RunReflectionsArgs { */ async function runReflections({ originalPost, + newPost, userResponse, }: RunReflectionsArgs) { const client = new Client({ @@ -37,10 +39,13 @@ async function runReflections({ }); const thread = await client.threads.create(); - await client.runs.create(thread.thread_id, "memory", { + await client.runs.create(thread.thread_id, "reflection", { input: { - original_post: originalPost, - user_response: userResponse, + // original_post: originalPost, + // user_response: userResponse, + originalPost, + newPost, + userResponse, }, }); } @@ -85,6 +90,7 @@ export async function rewritePost( await runReflections({ originalPost: state.post, + newPost: revisePostResponse.content as string, userResponse: state.userResponse, }); diff --git a/src/agents/reflection/index.ts b/src/agents/reflection/index.ts index 8c7adf0..af64f13 100644 --- a/src/agents/reflection/index.ts +++ b/src/agents/reflection/index.ts @@ -8,9 +8,8 @@ import { import { z } from "zod"; import { ChatAnthropic } from "@langchain/anthropic"; import { - getReflections, - putReflections, - RULESET_KEY, + getReflectionsPrompt, + putReflectionsPrompt, } from "../../utils/reflections.js"; import { REFLECTION_PROMPT, UPDATE_RULES_PROMPT } from "./prompts.js"; @@ -20,7 +19,7 @@ const newRuleSchema = z.object({ const updateRulesetSchema = z .object({ - updatedRuleset: z.array(z.string()).describe("The updated ruleset."), + updatedRuleset: z.string().describe("The full updated ruleset."), }) .describe("The updated ruleset."); @@ -86,11 +85,11 @@ async function reflection( return {}; } - const existingRules = await getReflections(config); + const existingRules = await getReflectionsPrompt(config); - if (!existingRules?.value?.[RULESET_KEY]?.length) { + if (!existingRules?.length) { // No rules exist yet. Create and return early. - await putReflections(config, [newRule]); + await putReflectionsPrompt(config, newRule); return {}; } @@ -99,7 +98,7 @@ async function reflection( }); const updateRulesetPrompt = UPDATE_RULES_PROMPT.replace( "{EXISTING_RULES}", - existingRules?.value[RULESET_KEY].join("\n") || "", + existingRules, ).replace("{NEW_RULE}", newRule); const updateRulesetResult = await updateRulesetModel.invoke([ { @@ -108,7 +107,7 @@ async function reflection( }, ]); - await putReflections(config, updateRulesetResult.updatedRuleset); + await putReflectionsPrompt(config, updateRulesetResult.updatedRuleset); return {}; } diff --git a/src/utils/reflections.ts b/src/utils/reflections.ts index e9829a5..96a7b1d 100644 --- a/src/utils/reflections.ts +++ b/src/utils/reflections.ts @@ -22,6 +22,26 @@ export async function getReflectionsPrompt( return reflections?.value?.[PROMPT_KEY] || ""; } +/** + * Stores reflection rules in the store + * @param {LangGraphRunnableConfig} config - Configuration object containing the store + * @param {string} reflections - The reflection rules to store + * @throws {Error} When no store is provided in the config + * @returns {Promise} + */ +export async function putReflectionsPrompt( + config: LangGraphRunnableConfig, + reflections: string, +): Promise { + const { store } = config; + if (!store) { + throw new Error("No store provided"); + } + await store.put(NAMESPACE, KEY, { + [PROMPT_KEY]: reflections, + }); +} + /** * Retrieves reflection rules from the store * @param {LangGraphRunnableConfig} config - Configuration object containing the store