Add hindsight-ag2 package providing persistent memory tools for AG2 agents via retain/recall/reflect operations.
32 lines
923 B
Python
32 lines
923 B
Python
"""Shared Hindsight client resolution logic."""
|
|
|
|
from typing import Any, Optional
|
|
|
|
from hindsight_client import Hindsight
|
|
|
|
from .config import get_config
|
|
from .errors import HindsightError
|
|
|
|
|
|
def resolve_client(
|
|
client: Optional[Hindsight],
|
|
hindsight_api_url: Optional[str],
|
|
api_key: Optional[str],
|
|
) -> Hindsight:
|
|
"""Resolve a Hindsight client from explicit args or global config."""
|
|
if client is not None:
|
|
return client
|
|
|
|
config = get_config()
|
|
url = hindsight_api_url or (config.hindsight_api_url if config else None)
|
|
key = api_key or (config.api_key if config else None)
|
|
|
|
if url is None:
|
|
raise HindsightError(
|
|
"No Hindsight API URL configured. Pass client= or hindsight_api_url=, or call configure() first."
|
|
)
|
|
|
|
kwargs: dict[str, Any] = {"base_url": url, "timeout": 30.0}
|
|
if key:
|
|
kwargs["api_key"] = key
|
|
return Hindsight(**kwargs)
|