"""Agent adapters for AIOS Search Gateway. All runtime agents should call SearchGatewayAgentAdapter instead of performing ad-hoc network search. This gives consistent provider fallback, profile resolution, evidence capture, audit and event visibility. """ from __future__ import annotations from dataclasses import asdict, dataclass, field from typing import Any from .search_gateway_orchestrator import SearchGatewayOrchestrator @dataclass(frozen=True) class AgentSearchContext: agent: str user_id: str | None = None group_id: str | None = None role: str = "user" group_profile: dict[str, Any] | None = None user_profile: dict[str, Any] | None = None session_profile: dict[str, Any] | None = None authorized_sources: list[str] = field(default_factory=list) def to_dict(self) -> dict[str, Any]: return asdict(self) class SearchGatewayAgentAdapter: def __init__(self, orchestrator: SearchGatewayOrchestrator | None = None): self.orchestrator = orchestrator or SearchGatewayOrchestrator() def search( self, query: str, context: AgentSearchContext, intent: str = "general", region: str | None = None, time_range: str | None = None, data_type: str | None = None, domain_profiles: list[str] | None = None, user_scope: str = "public", correlation_id: str | None = None, ) -> dict[str, Any]: payload = { "query": query, "requester": context.agent, "intent": intent, "region": region, "time_range": time_range, "data_type": data_type, "domain_profiles": domain_profiles or [], "user_scope": user_scope, "authorized_sources": context.authorized_sources, "group_profile": context.group_profile, "user_profile": context.user_profile, "session_profile": context.session_profile, "correlation_id": correlation_id, } return self.orchestrator.execute(payload) class OpenClawSearchClient(SearchGatewayAgentAdapter): def search_public(self, query: str, context: AgentSearchContext, **kwargs) -> dict[str, Any]: return self.search(query, context, user_scope="public", **kwargs) class HermesSearchClient(SearchGatewayAgentAdapter): def delegate_search(self, query: str, context: AgentSearchContext, **kwargs) -> dict[str, Any]: return self.search(query, context, **kwargs) class CodexSearchClient(SearchGatewayAgentAdapter): def technical_search(self, query: str, context: AgentSearchContext, **kwargs) -> dict[str, Any]: return self.search(query, context, intent=kwargs.pop("intent", "software_library"), **kwargs) class CustomGPTSearchClient(SearchGatewayAgentAdapter): def user_search(self, query: str, context: AgentSearchContext, **kwargs) -> dict[str, Any]: return self.search(query, context, **kwargs) __all__ = [ "AgentSearchContext", "SearchGatewayAgentAdapter", "OpenClawSearchClient", "HermesSearchClient", "CodexSearchClient", "CustomGPTSearchClient", ]