Replies: 2 comments
-
|
This is fantastic, thank you so much! I really appreciate you taking the time to lay out those suggestions. Based on your input, I've updated the example
Here’s the revised code snippet incorporating your ideas: import re
import time
from typing import Optional
from aid_py import discover, AidError
from zeroconf import ServiceBrowser, Zeroconf # Assumes user has installed this
def resolve_agent_address(domain: str, trust_local: bool = False, timeout: int = 3) -> Optional[str]:
"""
Resolves an agent's address, handling both global (AID)
and local (Zeroconf) discovery.
"""
try:
aid_result = discover(domain)
if aid_result.record.proto == 'zeroconf':
if not trust_local:
print("Warning: Local discovery required but not enabled. Pass trust_local=True to allow.")
return None
uri_match = re.match(r"^zeroconf:(_[a-zA-Z0-9.-]+._tcp)$", aid_result.record.uri)
if not uri_match:
raise ValueError(f"Invalid Zeroconf URI format: {aid_result.record.uri}")
service_type = uri_match.group(1) + ".local."
print(f"Local discovery triggered. Searching for {service_type} for {timeout}s...")
discovered_services = []
zc = Zeroconf()
def on_service_state_change(zc, s_type, name, state_change):
if state_change == "added":
info = zc.get_service_info(s_type, name)
if info:
addresses = [f"http://{addr}:{info.port}" for addr in info.parsed_addresses()]
discovered_services.extend(addresses)
browser = ServiceBrowser(zc, service_type, handlers=[on_service_state_change])
time.sleep(timeout)
zc.close()
if not discovered_services:
raise ConnectionError(f"No local service found for {service_type}")
if len(discovered_services) > 1:
print(f"Warning: Found multiple services: {discovered_services}. Using the first one.")
return discovered_services[0]
else:
return aid_result.record.uri
except AidError as e:
raise e
except Exception as e:
raise ConnectionError(f"Failed to resolve address for {domain}: {e}")Your point about officially locking down the format is crucial for the standard. To make sure we capture this properly and open it up for wider community discussion, I've created an issue for the
In fact, your feedback was so helpful it inspired me to open a few more issues to think about the future of the protocol. I've drafted proposals for adding support for other common protocols like gRPC, WebSockets, and even Bluetooth Low Energy (BLE), all as separate issues. Thanks again for the fantastic input! If any other ideas come up pls just let us know here |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Following some excellent community feedback, I want to start a technical discussion on how to architect a clean bridge between AID and local discovery protocols like Zeroconf/mDNS.
I've written up the high-level "why" in a blog post—the "Two Phonebooks" analogy: [Link to your new blog post]
This thread is for the "how." How can we use the existing
aid-pylibrary to build a client that seamlessly resolves both global and local agents?Here are some concrete implementation proposals to get the ball rolling:
1. Standardizing the
uriforproto=localTo make this interoperable, we need a standard URI scheme within the AID record. I propose we use a format based on the standard DNS-SD service strings.
An AID record for a local Ollama server could look like this:
An application would see this and know it needs to perform a local mDNS query for an
_http._tcpservice, not make a standard web request.2. Application-Level Handling (The Pattern)
The
aid-pylibrary correctly focuses on its core job: performing the DNS lookup and parsing the record. It shouldn't be bloated with mDNS dependencies.Therefore, the responsibility for handling the
localprotocol falls to the application layer. A developer can build a simple resolver function on top ofaid-py.Here is a possible implementation pattern:
3. The Security Boundary
This pattern reinforces a critical security consideration. The application must treat the switch from a globally-trusted resource (a DNSSEC-signed AID record) to a locally-discovered one as a security boundary crossing.
A client application implementing this pattern MUST:
Questions for the community:
zeroconf:<service_type>URI scheme the right approach forproto=local?Looking forward to hearing your thoughts.
Beta Was this translation helpful? Give feedback.
All reactions