Metadata-Version: 2.4
Name: langchain-w2a
Version: 0.1.0
Summary: LangChain integration for the Web2Agent Protocol — turn any W2A-enabled website into LangChain tools
Author-email: W2A Protocol <hello@w2a-protocol.org>
License: Apache-2.0
Project-URL: Homepage, https://w2a-protocol.org
Project-URL: Repository, https://github.com/Nijjwol23/w2a
Project-URL: Documentation, https://w2a-protocol.org/docs
Keywords: langchain,w2a,web2agent,ai-agents,tools,mcp,a2a
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Requires-Python: >=3.9
Description-Content-Type: text/markdown
Requires-Dist: langchain-core>=0.2
Requires-Dist: w2a>=0.1.0
Requires-Dist: pydantic>=2.0
Provides-Extra: dev
Requires-Dist: pytest>=7.0; extra == "dev"
Requires-Dist: pytest-asyncio>=0.21; extra == "dev"
Requires-Dist: langchain>=0.2; extra == "dev"

# langchain-w2a

LangChain integration for the [Web2Agent Protocol](https://w2a-protocol.org).

Turns any W2A-enabled website's declared skills into LangChain tools — one tool per skill, with typed input schemas built from the site's `agents.json`.

```bash
pip install langchain-w2a
```

---

## What is W2A?

W2A is an open standard where websites declare their capabilities at `/.well-known/agents.json`. Instead of crawling 40–50 pages to understand what a site does, your agent reads one file.

```
robots.txt  →  what not to crawl  (1994)
sitemap.xml →  where pages are    (2005)
agents.json →  what a site can do (2026)
```

---

## Quick start

```python
import asyncio
from langchain_w2a import W2AToolkit
from langchain_openai import ChatOpenAI
from langchain.agents import AgentExecutor, create_tool_calling_agent
from langchain_core.prompts import ChatPromptTemplate

async def main():
    # Each W2A skill becomes a typed LangChain tool
    toolkit = await W2AToolkit.from_url("w2a-protocol.org")
    tools = toolkit.get_tools()

    for tool in tools:
        print(f"{tool.name}: {tool.description}")
    # w2a_protocol_validate_manifest: Validate an agents.json...
    # w2a_protocol_check_site: Check whether a website...
    # w2a_discover: Discover what a W2A-enabled website can do.
    # w2a_call_skill: Call a specific skill on a W2A-enabled website.

    llm = ChatOpenAI(model="gpt-4")
    prompt = ChatPromptTemplate.from_messages([
        ("system", "You are a helpful assistant with access to W2A tools."),
        ("human", "{input}"),
        ("placeholder", "{agent_scratchpad}"),
    ])

    agent = create_tool_calling_agent(llm, tools, prompt)
    executor = AgentExecutor(agent=agent, tools=tools, verbose=True)

    result = executor.invoke({"input": "Is stripe.com W2A enabled?"})
    print(result["output"])

asyncio.run(main())
```

---

## Generic discover + call tools

If you don't know the site in advance, use the generic tools:

```python
from langchain_w2a import W2ADiscoverTool, W2ASkillTool

tools = [W2ADiscoverTool(), W2ASkillTool()]

# Agent can now discover any site and call its skills
# Example agent reasoning:
# 1. Call w2a_discover("stripe.com") → see available skills
# 2. Call w2a_call_skill("stripe.com", "search_products", {"q": "..."})
```

---

## Toolkit — one tool per skill

For a known site, the toolkit pre-binds the URL and creates dedicated tools:

```python
from langchain_w2a import W2AToolkit

# Only public skills (no auth required) by default
toolkit = await W2AToolkit.from_url("mysite.com")

# Include auth-required skills (you handle auth via headers)
toolkit = await W2AToolkit.from_url("mysite.com", include_auth_required=True)

# Only specific skills
toolkit = await W2AToolkit.from_url("mysite.com", skill_ids=["search", "checkout"])
```

---

## Requirements

- Python 3.9+
- `langchain-core >= 0.2`
- `w2a >= 0.1.0` (the W2A Python SDK)

---

## License

Apache 2.0 — same as LangChain and A2A.

[w2a-protocol.org](https://w2a-protocol.org) · [github.com/Nijjwol23/w2a](https://github.com/Nijjwol23/w2a)
