Skip to content

Search Workflow Reference

agent

Top-level pro-search workflow wrapper.

Purpose

Provide a small, organized wrapper around the compiled pro-search graph so the workflow can be invoked as a coherent top-level object.

Design
  • Builds and owns the compiled pro-search graph.
  • Accepts a ProSearchContext object at construction time.
  • Exposes sync and async invocation helpers.
  • Runs the full flow: planning, batched search execution, aggregation, and answer synthesis.

Attributes:

Name Type Description
ProSearchAgent

Lightweight wrapper around the compiled pro-search graph.

build_pro_search_agent ProSearchAgent

Factory for the top-level pro-search workflow wrapper.

Examples:

.. code-block:: python

agent = build_pro_search_agent()
result = agent.invoke(
    "What changed recently in the Tavily LangChain integration?"
)

ProSearchAgent dataclass

Lightweight wrapper around the compiled pro-search graph.

ainvoke async

ainvoke(user_question)

Run the pro-search workflow asynchronously.

invoke

invoke(user_question)

Run the pro-search workflow synchronously.

build_pro_search_agent

build_pro_search_agent(*, context=None, checkpointer=None, store=None, debug=False)

Build the top-level pro-search workflow wrapper.

graph

LangGraph workflow for the pro-search graph.

Purpose

Build the deterministic pro-search graph: query generation -> batched Tavily execution via ToolNode -> aggregation -> answer synthesis.

Design
  • Uses StateGraph with explicit workflow nodes.
  • Uses the structured-output query-generation child agent for planning.
  • Uses a deterministic node to convert the query plan into batched Tavily tool calls.
  • Uses ToolNode to execute Tavily search calls in parallel.
  • Uses a deterministic node to aggregate normalized evidence.
  • Uses the structured-output answer child agent to synthesize the final markdown answer.
  • Serializes the answer-agent input payload into a string before placing it into messages so it remains valid LangChain message content.

Attributes:

Name Type Description
build_pro_search_graph Any

Build the compiled pro-search workflow graph.

Examples:

.. code-block:: python

from perplexity_at_home.agents.pro_search.context import ProSearchContext
from perplexity_at_home.agents.pro_search.graph import build_pro_search_graph

context = ProSearchContext()
graph = build_pro_search_graph()

result = graph.invoke(
    {
        "messages": [
            {"role": "user", "content": "What changed recently in Tavily LangChain?"}
        ],
        "user_question": "What changed recently in Tavily LangChain?",
        "planned_queries": [],
        "raw_query_results": [],
        "aggregated_results": [],
        "search_errors": [],
        "search_tool_calls_built": False,
        "is_complete": False,
    },
    context=context,
    config={"configurable": {"thread_id": "pro-search"}},
)

SupportsInvoke

Bases: Protocol

Protocol for child agents invoked by the top-level graph.

invoke

invoke(input, *, context, config)

Invoke the child agent.

build_pro_search_graph

build_pro_search_graph(*, query_agent=None, answer_agent=None, checkpointer=None, store=None, debug=False)

Build the full pro-search graph.

Returns:

Type Description
Any

A compiled LangGraph workflow for planning, batched search execution,

Any

evidence aggregation, and answer synthesis.

Raises:

Type Description
RuntimeError

Propagated if graph construction fails.

Examples:

>>> graph = build_pro_search_graph()
>>> graph is not None
True

runtime

Runtime helpers for the top-level pro-search workflow.

pro_search_agent_context async

pro_search_agent_context(*, persistent=False, setup_persistence=False, context=None, debug=False)

Yield a pro-search agent with in-memory or Postgres-backed state.

run_pro_search(question, *, persistent=False, setup_persistence=False, context=None, debug=False)

Run the top-level pro-search workflow and return its final state.

agent

Quick-search agent construction.

Purpose

Build the main quick-search agent using the Tavily quick tool bundle and the rich quick-search system prompt.

Design
  • Uses the existing Tavily quick bundle from the shared tool layer.
  • Preserves the original rich quick-search prompt.
  • Registers runtime context, short-term state, and structured output.
  • Uses an in-memory checkpointer for short-term conversational continuity.

Attributes:

Name Type Description
build_quick_search_agent object

Factory for the main quick-search agent instance.

Examples:

.. code-block:: python

agent = build_quick_search_agent()
result = agent.invoke(
    {"messages": [{"role": "user", "content": "What is Apple's current price?"}]},
    context=QuickSearchContext(),
)

build_quick_search_agent

build_quick_search_agent(model=None, *, checkpointer=None, store=None, debug=False)

Build the main quick-search agent.

The resulting agent is configured for fast, citation-aware Tavily-backed answers and is intended to be the first end-to-end implementation of the quick-search lane.

Returns:

Name Type Description
object object

A configured LangChain agent instance.

Raises:

Type Description
RuntimeError

Propagated if agent construction fails because of invalid model, tool, or schema configuration.

Examples:

>>> agent = build_quick_search_agent()
>>> agent is not None
True

runtime

Runtime helpers for the top-level quick-search workflow.

quick_search_agent_context async

quick_search_agent_context(*, persistent=False, setup_persistence=False, debug=False)

Yield a quick-search agent with in-memory or Postgres-backed state.

run_quick_search(question, *, thread_id='quick-search', persistent=False, setup_persistence=False, context=None, debug=False)

Run the top-level quick-search workflow and return its final state.