Skip to content

Conversation

KonghaYao
Copy link

When I was using the handoff feature, I found that my state.current_plan was never updating, no matter what I tried.

Initially, I thought it was my mistake and tried many different ways to set the LangGraph state, but none of them worked.

Later, I examined the source code for createHandOff and discovered that when using a Command to jump to a new Node, the state wasn't being passed along. This caused my current_plan to remain null. So, I made a modification by adding a new parameter to persist the state.

const update_plan = tool(
    async (input, config: ToolRunnableConfig) => {
        return new Command<typeof DeepResearchState.State>({
            update: {
                current_plan: input, // not working
                messages: [
                    new ToolMessage({
                        content: "完成计划更新",
                        tool_call_id: config.toolCall!.id!,
                    }),
                ],
            },
        });
    },
    {
        name: "update_plan",
        description: "Update plan for this chat",
        schema: Plan,
    }
);

const planner_agent = createReactAgent({
    name: "planner",
    llm,
    tools: [
        // SequentialThinkingTool,
        update_plan,
        createHandoffTool({ agentName: "researcher", description: "进行研究" }),
        createHandoffTool({ agentName: "reporter", description: "进行总结" }),
    ],
    prompt: async (state) => {
        const data = await apply_prompt_template("deep_research_planner.md", state as any);
        return [new SystemMessage(data), ...state.messages];
    },
    stateSchema: DeepResearchState,
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant