Metadata-Version: 2.4
Name: langchain-dns-aid
Version: 0.1.0
Summary: DNS-AID agent discovery middleware for LangChain
Project-URL: Homepage, https://github.com/IngmarVG-IB/langchain-dns-aid
Project-URL: Repository, https://github.com/IngmarVG-IB/langchain-dns-aid
Project-URL: Issues, https://github.com/IngmarVG-IB/langchain-dns-aid/issues
Project-URL: Documentation, https://github.com/IngmarVG-IB/langchain-dns-aid#readme
Author: DNS-AID Contributors
License-Expression: Apache-2.0
License-File: LICENSE
Keywords: agent-discovery,dns,dns-aid,langchain,middleware,multi-agent,svcb
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Internet :: Name Service (DNS)
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Requires-Python: >=3.11
Requires-Dist: dns-aid>=0.14.0
Requires-Dist: langchain-core>=0.3.0
Requires-Dist: langchain>=0.4.0
Provides-Extra: dev
Requires-Dist: pytest-asyncio>=0.23; extra == 'dev'
Requires-Dist: pytest>=8.0; extra == 'dev'
Description-Content-Type: text/markdown

# langchain-dns-aid

DNS-AID agent discovery middleware for LangChain. Enables agents to discover, publish, and unpublish themselves via DNS using the [DNS-AID protocol](https://github.com/nicholasgasior/draft-dns-aid).

## Why middleware instead of tools?

Unlike tool-only integrations (CrewAI, LlamaIndex, etc.), the middleware approach uses LangChain's lifecycle hooks to **auto-publish** the agent on startup and **auto-unpublish** on shutdown. This prevents stale DNS records when agents crash or forget to clean up.

## Install

```bash
pip install langchain-dns-aid
```

## Quick start

```python
from langchain import create_agent, init_chat_model
from langchain_dns_aid import DnsAidMiddleware

agent = create_agent(
    model=init_chat_model("gpt-4o"),
    middleware=[DnsAidMiddleware(
        agent_name="my-assistant",
        domain="agents.example.com",
        endpoint="assistant.example.com",
        capabilities=["code-review", "documentation"],
        backend_name="route53",
    )],
)

# Agent is auto-published to DNS on startup.
# It can discover other agents during conversation.
# On shutdown, it is auto-unpublished.
```

## What it does

| Hook | Action |
|------|--------|
| `before_agent` | Auto-publishes the agent to DNS via SVCB records |
| `after_agent` | Auto-unpublishes the agent, removing DNS records |
| Tools | `dns_aid_discover`, `dns_aid_publish`, `dns_aid_unpublish` |

## Configuration

| Parameter | Default | Description |
|-----------|---------|-------------|
| `agent_name` | `None` | Agent DNS label (required for auto-publish) |
| `domain` | `None` | Domain to publish under (required for auto-publish) |
| `protocol` | `"mcp"` | Protocol: `mcp`, `a2a`, or `https` |
| `endpoint` | `""` | Hostname where agent is reachable |
| `port` | `443` | Port number |
| `capabilities` | `None` | List of agent capabilities |
| `backend_name` | `None` | DNS backend: `route53`, `cloudflare`, `mock`, etc. |
| `auto_publish` | `True` | Auto-publish on agent start |
| `auto_unpublish` | `True` | Auto-unpublish on agent stop |

## Discovery only (no auto-publish)

```python
agent = create_agent(
    model=init_chat_model("gpt-4o"),
    middleware=[DnsAidMiddleware(
        auto_publish=False,
        auto_unpublish=False,
    )],
)
# Agent gets dns_aid_discover tool but doesn't publish itself.
```

## License

Apache-2.0
