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
ProSearchContextobject 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?"
)
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
StateGraphwith 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
ToolNodeto 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
messagesso 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.
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:
runtime ¶
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 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:
runtime ¶
Runtime helpers for the top-level quick-search workflow.
quick_search_agent_context
async
¶
Yield a quick-search agent with in-memory or Postgres-backed state.
run_quick_search
async
¶
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.