Build a daily dependency watcher with LangGraph and Amazon Bedrock AgentCore web search

Learn how to build a daily dependency watcher using LangGraph and Amazon Bedrock AgentCore’s Web Search API, keeping search rules in code while agents fetch and cite up‑to‑date security information.

Build a daily dependency watcher with LangGraph and Amazon Bedrock AgentCore web search

Building a Daily Dependency Watcher with LangGraph & Amazon Bedrock AgentCore

Modern security teams need fresh information about open‑source packages, container base images, and other dependencies. Traditional LLMs can’t answer “what changed today” because their training data is static. Amazon Bedrock AgentCore’s Web Search API fills that gap by delivering current, cited web results directly from AWS‑controlled indexes. By combining this API with LangGraph—the orchestration layer for LangChain agents—you can create a reliable, parallelized daily watcher that enforces search policies in code.

---

1. Why Use AgentCore Web Search?

  • Current, cited results – Each hit includes title, URL, publication date, and a relevant excerpt, making it easy to trace findings back to source material.
  • AWS‑native security – Queries are signed with your existing AWS credentials (SigV4) and never leave the AWS environment, preserving internal context.
  • Policy‑driven control – You can whitelist/blacklist domains, restrict date ranges, and cap the number of searches per run, all without exposing these rules to the model.
  • Seamless integration – The `langchain-aws` package provides a ready‑made tool that wraps the Web Search API, exposing a single function call for agents.

---

2. Architecture Overview

``` [Notebook Trigger] → LangGraph Graph │ ├─ fanout → three parallel branches (npm, PyPI, container images) │ │ └─ each branch: │ │ • Calls Anthropic Claude via Bedrock │ │ • Uses a fixed‑rule web‑search tool │ │ • Performs up to 4 searches, respecting blocklist & date window │ │ • Returns structured findings (package, title, CVE, severity, source) │ └─ merge → keepnew (deduplication) → report (cited table) ``` The graph runs entirely in an Amazon Bedrock AgentCore runtime (or via AgentCore Gateway for multi‑team access). All policy enforcement lives in the Python code, guaranteeing that the model cannot override date windows, source blocklists, or search budgets.

---

3. Step‑by‑Step Implementation

Prerequisites

  • AWS account with Bedrock AgentCore Web Search enabled (e.g., `us-east-1`).
  • Python 3.10+, `boto3`, `bedrock-agentcore`, `langchain-aws`, `langchain`, `langgraph` installed.
  • IAM role with `bedrock-agentcore:InvokeWebSearch` on the resource `arn:aws:bedrock-agentcore:*:aws:tool/web-search.v1`.

3.1 Grant the IAM Permission

```json { "Effect": "Allow", "Action": "bedrock-agentcore:InvokeWebSearch", "Resource": "arn:aws:bedrock-agentcore:us-east-1:aws:tool/web-search.v1" } ``` Attach this policy to the role that runs your notebook or Lambda function.

3.2 Create a Fixed‑Rule Search Tool

```python from langchainaws import createwebsearchtoolkit

toolkit, tools = createwebsearchtoolkit( region="us-east-1", excludedomains=BLOCKLIST, # e.g., {"example.com"} publishedafter=windowstart.isoformat(), modelfilters=False, # model sees only the query string maxsearches=4, return_sources=True # gives raw result objects ) ``` The toolkit enforces the blocklist, date floor, and search budget regardless of model prompts.

3.3 Define a Structured Findings Schema

```python from pydantic import BaseModel

class Finding(BaseModel): package: str title: str advisoryid: str | None = None severity: str | None = None exploited: bool | None = None sourceurl: str published_at: str ``` Each branch’s agent returns a list of `Finding` objects, allowing LangGraph to merge and deduplicate reliably.

3.4 Build the LangGraph Nodes

  • `search_branch` – Executes the model, calls the web‑search tool, and parses results into `Finding` objects.
  • `keep_new` – Checks a persistent LangGraph store (e.g., DynamoDB) for already‑reported findings; only new items pass through.
  • `report` – Formats a markdown table with citations for the security team’s daily digest.

Parallel execution is achieved with `fan_out`: ```python from langgraph.graph import Graph

graph = Graph() graph.addnode("npm", searchbranch) graph.addnode("pypi", searchbranch) graph.addnode("container", searchbranch) graph.setentrypoint("fanout") graph.addedge("fanout", ["npm", "pypi", "container"]) graph.addedge(["npm", "pypi", "container"], "keepnew") graph.addedge("keepnew", "report") ``` When the graph is triggered with a watchlist and a window start date, the three branches run concurrently, each performing up to four searches. In testing, the parallel run completed in ~36 seconds versus ~99 seconds sequentially.

3.5 Deploy and Share via AgentCore Gateway

Package the graph as a Bedrock AgentCore runtime image (Docker or Lambda) and register it with AgentCore Gateway. A single source‑policy attached to the gateway governs all agents, simplifying cross‑team access while preserving the same IAM permission model.

---

4. Practical Tips & Considerations

  • Cost awareness – Each search incurs a per‑request charge; a full daily run (max 12 searches) is modest but should be monitored.
  • Result verification – Because the tool returns raw source objects, you can add additional validation (e.g., CVE pattern matching) before reporting.
  • Extensibility – Adding new ecosystems (RubyGems, Maven) only requires another branch node with its own watchlist.
  • Error handling – Wrap API calls in retries with exponential back‑off; Bedrock may throttle under heavy load.

---

Closing Thoughts

By anchoring search policies in code and leveraging LangGraph’s parallel orchestration, you can deliver a dependable, daily dependency watcher that surfaces only the most relevant, verifiable security advisories. The combination of Amazon Bedrock AgentCore’s Web Search API and LangGraph’s flexible graph model provides a powerful pattern for any organization that needs up‑to‑date, cited information without exposing internal context to third‑party search services.

Source

Read original source

Why we picked this

Shows a practical AI tool/integration using LangGraph and Bedrock

← Back to all articles