mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-07-24 23:41:10 +02:00
feat(walmart): add chat subagent with scrape and reviews tools
This commit is contained in:
parent
7b5e09c528
commit
f6a8a2a566
6 changed files with 142 additions and 0 deletions
|
|
@ -0,0 +1 @@
|
||||||
|
"""``walmart`` builtin subagent: structured public Walmart product data and reviews."""
|
||||||
|
|
@ -0,0 +1,43 @@
|
||||||
|
"""``walmart`` route: ``SurfSenseSubagentSpec`` builder for deepagents."""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
|
from langchain_core.language_models import BaseChatModel
|
||||||
|
from langchain_core.tools import BaseTool
|
||||||
|
|
||||||
|
from app.agents.chat.multi_agent_chat.subagents.shared.md_file_reader import (
|
||||||
|
read_md_file,
|
||||||
|
)
|
||||||
|
from app.agents.chat.multi_agent_chat.subagents.shared.spec import SurfSenseSubagentSpec
|
||||||
|
from app.agents.chat.multi_agent_chat.subagents.shared.subagent_builder import (
|
||||||
|
pack_subagent,
|
||||||
|
)
|
||||||
|
|
||||||
|
from .tools.index import NAME, RULESET, load_tools
|
||||||
|
|
||||||
|
|
||||||
|
def build_subagent(
|
||||||
|
*,
|
||||||
|
dependencies: dict[str, Any],
|
||||||
|
model: BaseChatModel | None = None,
|
||||||
|
middleware_stack: dict[str, Any] | None = None,
|
||||||
|
mcp_tools: list[BaseTool] | None = None,
|
||||||
|
) -> SurfSenseSubagentSpec:
|
||||||
|
tools = [*load_tools(dependencies=dependencies), *(mcp_tools or [])]
|
||||||
|
description = (
|
||||||
|
read_md_file(__package__, "description").strip()
|
||||||
|
or "Scrapes public Walmart product data and reviews for a URL or search term."
|
||||||
|
)
|
||||||
|
system_prompt = read_md_file(__package__, "system_prompt").strip()
|
||||||
|
return pack_subagent(
|
||||||
|
name=NAME,
|
||||||
|
description=description,
|
||||||
|
system_prompt=system_prompt,
|
||||||
|
tools=tools,
|
||||||
|
ruleset=RULESET,
|
||||||
|
dependencies=dependencies,
|
||||||
|
model=model,
|
||||||
|
middleware_stack=middleware_stack,
|
||||||
|
)
|
||||||
|
|
@ -0,0 +1,2 @@
|
||||||
|
Walmart product specialist: scrapes public Walmart listings and returns structured product data — title, item id (usItemId), brand, price and list price, star rating and review count, availability, images, features, seller, and product variants — plus deep paginated customer reviews (rating, text, author, verified-purchase flag, images, and seller responses). Works from a search term (e.g. "air fryer") or from Walmart product (/ip/...), search, category, or browse URLs, and can pull many reviews per product by item id or URL. Only public, anonymous US Walmart data — no login or seller account.
|
||||||
|
Use it for product research, price tracking, catalog enrichment by item id, and review mining. Triggers include "find X on Walmart", "Walmart price of X", "reviews for this Walmart product", "compare these Walmart products", and "look up this Walmart URL/item id". Not for general web search (use the Google Search specialist), reading an arbitrary non-Walmart page (use the web crawling specialist), or other marketplaces.
|
||||||
|
|
@ -0,0 +1,68 @@
|
||||||
|
You are the SurfSense Walmart sub-agent.
|
||||||
|
You receive delegated instructions from a supervisor agent and return structured results for supervisor synthesis.
|
||||||
|
|
||||||
|
<goal>
|
||||||
|
Answer the delegated question from public Walmart product data and reviews gathered with your verbs, comparing against earlier results already in this conversation when the task calls for it.
|
||||||
|
</goal>
|
||||||
|
|
||||||
|
<available_tools>
|
||||||
|
- `walmart_scrape` — product details and search/category listings
|
||||||
|
- `walmart_reviews` — deep paginated reviews for a product
|
||||||
|
- `read_run` / `search_run` (free readers for stored scrape output)
|
||||||
|
</available_tools>
|
||||||
|
|
||||||
|
<playbook>
|
||||||
|
- Discovering products: call `walmart_scrape` with `search_terms` (e.g. ["air fryer"]).
|
||||||
|
- Specific products: pass Walmart product URLs (/ip/...) or search/category/browse URLs in `urls`.
|
||||||
|
- Faster listings: set `include_details=false` to return card-only results without opening each product page.
|
||||||
|
- Sampled reviews: `walmart_scrape` returns a small on-page review sample by default (`include_reviews_sample=true`); disable it when reviews are irrelevant.
|
||||||
|
- Deep review mining: use `walmart_reviews` with product `urls` or numeric `item_ids` (usItemId); raise `max_reviews` and set `sort_by` (most-recent, most-helpful, rating-high, rating-low) as the task needs. Reviews are billed per review, so keep `max_reviews` to what the task actually requires.
|
||||||
|
- Batch multiple URLs or search terms into one call rather than many single-source calls.
|
||||||
|
<include snippet="run_reader"/>
|
||||||
|
- Comparison requests: pull the current products, compare against prior values already in this conversation's earlier tool results, and report concrete deltas (price up/down, rating change, stock changes).
|
||||||
|
</playbook>
|
||||||
|
|
||||||
|
<tool_policy>
|
||||||
|
- Use only tools in `<available_tools>`.
|
||||||
|
- Report only results present in the tool output. Never invent titles, item ids, prices, ratings, or reviews.
|
||||||
|
- `walmart_scrape`: provide at least one of `urls` or `search_terms`.
|
||||||
|
- `walmart_reviews`: provide at least one of `urls` or `item_ids`.
|
||||||
|
</tool_policy>
|
||||||
|
|
||||||
|
<out_of_scope>
|
||||||
|
- Do not perform general web search — that is the Google Search specialist's job.
|
||||||
|
- Do not read or extract an arbitrary non-Walmart page — return the URL for the web crawling specialist.
|
||||||
|
- Do not generate deliverables or perform connector mutations; return findings for the supervisor to act on.
|
||||||
|
- Only public, anonymous Walmart data — never anything behind a login or seller account.
|
||||||
|
</out_of_scope>
|
||||||
|
|
||||||
|
<safety>
|
||||||
|
- Report uncertainty explicitly when evidence is incomplete or conflicting.
|
||||||
|
- Never present unverified claims as facts.
|
||||||
|
</safety>
|
||||||
|
|
||||||
|
<failure_policy>
|
||||||
|
- Underspecified request — no usable search term, URL, or item id — return `status=blocked` with the missing fields.
|
||||||
|
- Tool failure: return `status=error` with a concise recovery `next_step`.
|
||||||
|
- No useful evidence: return `status=blocked` with a narrower query or the scope you still need.
|
||||||
|
</failure_policy>
|
||||||
|
|
||||||
|
<output_contract>
|
||||||
|
Return **only** one JSON object (no markdown/prose):
|
||||||
|
{
|
||||||
|
"status": "success" | "partial" | "blocked" | "error",
|
||||||
|
"action_summary": string,
|
||||||
|
"evidence": {
|
||||||
|
"findings": string[],
|
||||||
|
"sources": string[],
|
||||||
|
"confidence": "high" | "medium" | "low"
|
||||||
|
},
|
||||||
|
"next_step": string | null,
|
||||||
|
"missing_fields": string[] | null,
|
||||||
|
"assumptions": string[] | null
|
||||||
|
}
|
||||||
|
<include snippet="output_contract_base"/>
|
||||||
|
Route-specific rules:
|
||||||
|
- `evidence.findings`: max 10 entries, each a single sentence stating one distinct product, review theme, or delta. Do not paste raw payloads.
|
||||||
|
- `evidence.sources`: max 10 URLs, one per finding when applicable. List each URL once.
|
||||||
|
</output_contract>
|
||||||
|
|
@ -0,0 +1,28 @@
|
||||||
|
"""``walmart`` sub-agent tools: the Walmart product scrape and reviews verbs."""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
|
from langchain_core.tools import BaseTool
|
||||||
|
|
||||||
|
from app.agents.chat.multi_agent_chat.shared.permissions import Ruleset
|
||||||
|
from app.capabilities.core.access.agent import build_capability_tools
|
||||||
|
from app.capabilities.walmart.reviews.definition import WALMART_REVIEWS
|
||||||
|
from app.capabilities.walmart.scrape.definition import WALMART_SCRAPE
|
||||||
|
|
||||||
|
NAME = "walmart"
|
||||||
|
|
||||||
|
RULESET = Ruleset(origin=NAME, rules=[])
|
||||||
|
|
||||||
|
_CI_VERBS = [WALMART_SCRAPE, WALMART_REVIEWS]
|
||||||
|
|
||||||
|
|
||||||
|
def load_tools(
|
||||||
|
*, dependencies: dict[str, Any] | None = None, **kwargs: Any
|
||||||
|
) -> list[BaseTool]:
|
||||||
|
d = {**(dependencies or {}), **kwargs}
|
||||||
|
return build_capability_tools(
|
||||||
|
workspace_id=d.get("workspace_id"),
|
||||||
|
capabilities=_CI_VERBS,
|
||||||
|
)
|
||||||
Loading…
Add table
Add a link
Reference in a new issue