Help in Application Design

Context :

Initial Solution:

One Deep Agent with playwright tools, memory (old selenium scripts), skills ( navigation skills etc )

Given a Natural Language Prompt, it should explore the given website and get enough data from memory and skills and implement the natural Language testcase

From the chat history one final step is to write playwright script for the given Natural Language Prompt

Issues :

  1. LLM stopping before achieving the goal asking user for things which are already present in skills/memory

2. LLM Context window overflow that it forgets initial steps and redoes the first step after a few steps

So, Pivot to a sub agent architecture:

Issues:

  1. Playwright subagent when has a doubt return the control back to main agent, the main agent then consults documentation sub agent and returns with an updated task but here’s the cache : Playwright subagent forgot its initial steps and tries to do everything from start which is very bad

  2. Sometimes while returning playwright subagent lies that the task is done which is bad and main agent has no access to subagent’s chat history so the main agent just believes which is very bad

So the main issue is here how do I handle chat history I need a solution native to langraph not manual system prompting and back and forth of state transfer between agents which makes it indeterministic

Please help me my deadline at a startup is this Monday

Please help . Let me know if any further information is required

Found an example of the same architecture but still the problem persists in this example too
how_to_fix_your_context/notebooks/03-context-quarantine.ipynb at main · langchain-ai/how_to_fix_your_context

Hi @MINEGHOST007

When you’re invoking your main agent, have you double-checked that you’re passing a consistent thread_id?

For example:

agent = create_deep_agent(...)

agent.invoke(
    ...,
    config={"configurable": {"thread_id": "test"}}
)

It would also be helpful if you could share how you’re initializing your agent. Please make sure that the state_schema in create_agent includes the messages key. This is important because sub-agents rely on the messages key to properly return their output to the parent agent.

As long as you are using the messages key during execution, the parent agent will be able to see the sub-agent’s output.

Also note that a SubAgent does not have a concept of ChatHistory since whole idea of SubAgent is to avoid context bloat. Its purpose is to perform a single multi step task and then finish. There is no automatic passing of chat history across multiple runs of a SubAgent. The only way a SubAgent can know about previous runs is if the Parent Agent explicitly passes that information in the task_description.

If needed, you can modify the system_prompt in SubAgentMiddleware to ensure the Parent Agent encodes past steps before calling the SubAgent. You can also adjust the task_description in SubAgentMiddleware to include any relevant prior context.

For more details, please refer to this video:
https://www.youtube.com/watch?v=A3DKwLORVe4

For Deeper Understanding of SubAgents and how to modify the Parameters: Subagents - Docs by LangChain

1 Like