Skip to content

How to manage memory of swarm for long conversation #84

@farisnanosoft

Description

@farisnanosoft

https://langchain-ai.github.io/langgraph/agents/memory/#manage-message-history

pre_model_hook parameter is not available for create_swarm. When pre_model_hook is used with individual create_react_agent, the state message change doesn't reflect on swarm state. Kindly resolve this.

Currently as a workaround, have to modify swarm graph to begin with memory management node. Without modification, both nodes runs in parallel during graph start.

    def route_to_active_agent(state: dict):
        return state.get("active_agent", default_active_agent)

    builder.add_conditional_edges(START, route_to_active_agent, path_map=route_to) **-->** _change START to memory management node_
    return builder


def create_swarm(
    agents: list[Pregel],
    *,
    default_active_agent: str,
    state_schema: StateSchemaType = SwarmState,
    config_schema: Type[Any] | None = None,
) -> StateGraph:

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions