Skip to content

tdfs4ds.impact_agent.consumer_bridge

tdfs4ds.impact_agent.consumer_bridge

Ask the consumer agent a question on behalf of the impact study.

The consumer agent knows the workflow in business words (documentation, definitions, freshness, lineage). :func:ask sends it ONE question:

  • on its own thread id (never a user's conversation) and with no valid time (as_of unset);
  • restricted to read-only intents (no dataset is built);
  • inside :func:tdfs4ds.agent.query_guard.agent_guard, so a data read is EXPLAIN-checked first;
  • with a timeout, and counted against a :class:Budget;
  • holding the app chat's turn lock when the app is loaded (one turn at a time, like the chat).

The answer is evidence ("the consumer agent said"), never a fact that overrides a computed one. Skipped, with the reason, when no instruct model or no vector index is available.

The entry point is tdfs4ds.agent.graph.consumer_agent (reached with importlib: the tdfs4ds.agent package rebinds the names consumer_agent / query_optimizer to functions).

READ_ONLY_INTENTS module-attribute

READ_ONLY_INTENTS = ('SEARCH', 'DEFINITION', 'USAGE', 'FRESHNESS', 'SUMMARY', 'DATA_DOMAINS', 'FEASIBILITY', 'LINEAGE', 'EXPLAIN', 'DATASET', 'RECAP', 'HELP', 'OUT_OF_SCOPE', 'VALUES')

DEFAULT_TIMEOUT module-attribute

DEFAULT_TIMEOUT = 180.0

Budget

At most max_calls questions to the consumer agent.

max_calls instance-attribute

max_calls = max(0, int(max_calls or 0))

used instance-attribute

used = 0

__init__

__init__(max_calls: int)

left

left() -> int

take

take() -> bool

available

available() -> Tuple[bool, Optional[str]]

Whether the consumer agent can answer: an instruct model and a vector index. No call made.

_default_consumer

_default_consumer() -> Callable

ask

ask(question: str, *, domains: Optional[List[str]] = None, thread_id: Optional[str] = None, timeout: Optional[float] = None, budget: Optional[Budget] = None, consumer: Optional[Callable] = None, check_available: bool = True) -> dict

One question to the consumer agent. Never raises.

Returns {"question", "answer", "ok", "skipped_reason", "error", "duration", "thread_id", "trace"}. consumer replaces the consumer agent (tests); then availability is not checked.