Skip to content

feat(swarm): Add an optional state update function to support custom state updates during handover #1206

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

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