query_planner_agent
langroid/agent/special/lance_rag/query_planner_agent.py
LanceQueryPlanAgent is a ChatAgent created with a specific document schema.
Given a QUERY, the LLM constructs a Query Plan consisting of:
- filter condition if needed (or empty string if no filter is needed)
- query - a possibly rephrased query that can be used to match the content field
- dataframe_calc - a Pandas-dataframe calculation/aggregation string, possibly empty
- original_query - the original query for reference
This agent has access to two tools:
- QueryPlanTool, which is used to generate the Query Plan, and the handler of
this tool simply passes it on to the RAG agent named in config.doc_agent_name.
- QueryPlanFeedbackTool, which is used to handle feedback on the Query Plan and
Result from the RAG agent. The QueryPlanFeedbackTool is used by
the QueryPlanCritic, who inserts feedback into the feedback field
LanceQueryPlanAgent(config)
¶
Bases: ChatAgent
Source code in langroid/agent/special/lance_rag/query_planner_agent.py
query_plan(msg)
¶
Valid, tool msg, forward chat_doc to RAG Agent. Note this chat_doc will already have the QueryPlanTool in its tool_messages list. We just update the recipient to the doc_agent_name.
Source code in langroid/agent/special/lance_rag/query_planner_agent.py
query_plan_feedback(msg)
¶
Process Critic feedback on QueryPlan + Answer from RAG Agent
Source code in langroid/agent/special/lance_rag/query_planner_agent.py
answer_tool(msg)
¶
Handle AnswerTool received from LanceRagAgent: Construct a QueryPlanAnswerTool with the answer, addressed to the Critic.
The recipient is explicit on purpose. Returning the tool bare leaves it
with no addressee, and Task.step then offers the turn to THIS agent's
own LLM before the Critic sub-task. That reply is accepted when it is
non-null, and since llm_response above sets expecting_query_plan
unconditionally, the LLM is told to produce a query plan again: it
emits a duplicate query_plan, the Critic never receives the answer,
query_plan_feedback never arrives, and the task spins until the
inf-loop guard or max_turns (Task.result() then returns None).
Naming the Critic makes _recipient_mismatch skip our own LLM, so the
handoff is deterministic on any model.
Source code in langroid/agent/special/lance_rag/query_planner_agent.py
handle_message_fallback(msg)
¶
Remind to use QueryPlanTool if we are expecting it.