Search⌘ K
AI Features

Tools and Memory

Explore the integration of tools and memory in LangGraph workflows by building planning and execution nodes. Understand how to route sub-queries to domain-specific knowledge tools, accumulate search results in state, and handle clear versus vague questions. Gain practical experience in designing an AI research assistant that effectively manages multi-domain queries with controlled execution and state management.

The previous lesson gave us a working clarity gate. Vague questions return a clarification response and never reach the downstream pipeline. Clear questions pass through to the planning node, which is still a stub. This lesson replaces that stub and the executor stub with real implementations.

The milestone for this lesson is: clear questions are planned into focused sub-queries, each sub-query is matched to the right knowledge domain, and the search results accumulate in state. The synthesis and formatting nodes remain stubs; the goal is to have something to synthesise before we build the synthesiser.

The three knowledge domains

Before building the planning and execution nodes, we need the tools they will call. Each knowledge domain is a pure Python function with no LangGraph dependency. A production system would replace each function body with a database query or API call. The graph structure and node contracts do not change when that replacement happens.

Product knowledge

The product knowledge tool covers the topics most users ask about: pricing tiers, plan differences, refund terms, shipping options, and API rate limits. It uses a keyword scan over a small dictionary to return the most relevant article.

def search_product_knowledge(query: str) -> str:
articles = {
"pricing": (
"Plans: Starter $9/mo (5 users), Pro $49/mo (25 users + API access), "
"Enterprise $199/mo (unlimited users, dedicated support, SLA guarantee)."
),
"plan": (
"Starter suits individuals and small teams. Pro unlocks the API and "
"advanced analytics. Enterprise adds SSO, audit logs, and a 99.9% uptime SLA."
),
"refund": (
"Refund policy: full refunds within 30 days of purchase. "
"Digital products have a 14-day refund window. Contact support@example.com."
),
"shipping": (
"Physical goods: standard delivery 5–7 business days. "
"Express (2–3 days) costs $9.99. Free shipping on orders over $75."
),
"api": (
"API access is included on Pro and Enterprise plans. "
"Rate limits: 1,000 requests/day (Pro), 10,000 requests/day (Enterprise). "
"Authentication uses Bearer tokens."
),
}
q = query.lower()
for keyword, content in articles.items():
if keyword in q:
return content
return "No specific product information found. Please contact support for details."
Product knowledge base tool
  • Lines 2–26: Five articles covering pricing, plan differences, refund policy, shipping, and API access. Each article is long enough to give the synthesiser meaningful content to work with.

  • Lines 28–31: Keyword scan with a safe default. The default is a useful fallback rather than an empty string, which would cause the synthesiser to produce a content-free response.

Technical documentation

The technical documentation tool handles developer-facing questions: SDK setup, authentication methods, OAuth flows, webhook configuration, and error codes. It follows the same keyword-scan pattern as the product knowledge tool.

def search_technical_docs(query: str) -> str:
docs = {
"sdk": (
"SDKs available: Python (pip install example-sdk), "
"JavaScript (npm install example-sdk), Go (go get example.com/sdk). "
"All SDKs are open source. Minimum Python version: 3.9."
),
"authentication": (
"Authentication: Bearer token in the Authorization header. "
"Generate tokens via the dashboard under Settings → API Keys. "
"Tokens do not expire but can be revoked at any time."
),
"oauth": (
"OAuth 2.0 is supported on Enterprise plans. "
"Supported flows: Authorization Code, Client Credentials. "
"PKCE is required for public clients."
),
"webhook": (
"Webhooks: configure endpoint URLs in the dashboard. "
"Events: payment.completed, subscription.cancelled, user.created. "
"Payloads are signed with HMAC-SHA256. Retry policy: 3 attempts."
),
"error": (
"Common error codes: 400 Bad Request (malformed payload), "
"401 Unauthorized (invalid or missing token), "
"429 Too Many Requests (rate limit exceeded), "
"500 Internal Server Error (contact support with the request ID)."
),
}
q = query.lower()
for keyword, content in docs.items():
if keyword in q:
return content
return "No specific technical documentation found. Check the developer portal for full docs."
Technical documentation tool
  • Lines 2–28: Five entries covering SDK installation, authentication, OAuth, webhooks, and ...