Skip to content

tdfs4ds.impact_agent.tools

tdfs4ds.impact_agent.tools

The impact agent's tools: typed, named, READ-ONLY functions in one registry.

A tool is registered with the :func:tool decorator::

@tool("feature_readers", "The readers of one feature ...", FeatureArgs)
def feature_readers(state, feature, process_id=None): ...

The registry refuses a tool that is not read-only, when the module is imported: the impact study never applies or runs anything. Every call goes through :func:call_tool, which validates the arguments with the tool's pydantic model and records the call in the study's ledger.

The tools are thin wrappers over existing code: :mod:tdfs4ds.impact (scope, study), :mod:tdfs4ds.impact_features (feature readers and chain), :mod:.footprint (the assistant's footprint), :mod:.consumer_bridge (the consumer agent) and an EXPLAIN-only compilation check.

COST_CLASSES module-attribute

COST_CLASSES = ('free', 'db', 'llm')

REGISTRY module-attribute

REGISTRY: Dict[str, Tool] = {}

_RANK_SEV module-attribute

_RANK_SEV = {'unaffected': 0, 'may_change': 1, 'values_change': 2, 'breaks': 3}

Tool dataclass

name instance-attribute

name: str

description instance-attribute

description: str

args instance-attribute

args: Type[BaseModel]

fn instance-attribute

fn: Callable

read_only class-attribute instance-attribute

read_only: bool = True

cost class-attribute instance-attribute

cost: str = 'db'

source class-attribute instance-attribute

source: str = 'code'

__init__

__init__(name: str, description: str, args: Type[BaseModel], fn: Callable, read_only: bool = True, cost: str = 'db', source: str = 'code') -> None

_NoArgs

Bases: BaseModel

ScopeArgs

Bases: BaseModel

objects class-attribute instance-attribute

objects: List[str] = Field(description='process id, process view, dataset, view or table names')

new_sql class-attribute instance-attribute

new_sql: Optional[str] = Field(None, description='the proposed SELECT of one view')

dataset_change class-attribute instance-attribute

dataset_change: Optional[dict] = Field(None, description='the change of one dataset')

as_of class-attribute instance-attribute

as_of: Optional[str] = Field(None, description='valid time of the catalogs read')

StudyArgs

Bases: BaseModel

max_depth class-attribute instance-attribute

max_depth: int = Field(6, description='reader rounds followed by the feature chain')

FeatureArgs

Bases: BaseModel

feature class-attribute instance-attribute

feature: str = Field(description='a feature of the edited object')

process_id class-attribute instance-attribute

process_id: Optional[str] = Field(None, description='its process, when the name is ambiguous')

FootprintArgs

Bases: BaseModel

include_unaffected class-attribute instance-attribute

include_unaffected: bool = Field(False, description='also the features the change leaves alone')

AskArgs

Bases: BaseModel

question class-attribute instance-attribute

question: str = Field(description='one question for the consumer agent, in business words')

ReviewArgs

Bases: BaseModel

ids class-attribute instance-attribute

ids: Optional[List[str]] = Field(None, description='item ids (R1, R2...) to review; none = every undecided item within the review budget')

CompileArgs

Bases: BaseModel

sql class-attribute instance-attribute

sql: str = Field(description='a SELECT (REPLACE VIEW ... AS header allowed); only EXPLAINed')

describe_args_error

describe_args_error(exc: Exception) -> str

A short, plain wording of a bad-arguments error: missing argument 'feature' / invalid argument 'x': <short> (no pydantic text, no URL).

register

register(t: Tool) -> Tool

Add a tool to the registry; refuses one that is not read-only or reuses a name.

tool

tool(name: str, description: str, args: Optional[Type[BaseModel]] = None, *, read_only: bool = True, cost: str = 'db', source: str = 'code')

Decorator registering a function as a tool (raises at import when read_only is not True).

catalog

catalog() -> List[dict]

[{name, description, args (JSON schema), cost}] of every tool (for a planner prompt).

call_tool

call_tool(name: str, state, args: Optional[dict] = None)

Validate args, run tool name on state and record the call in state.ledger. Raises KeyError for an unknown tool and ValueError for bad arguments (recorded too).

resolve_scope

resolve_scope(state, objects, new_sql=None, dataset_change=None, as_of=None)

study_change

study_change(state, max_depth=6)

feature_readers

feature_readers(state, feature, process_id=None)

feature_chain

feature_chain(state, feature, process_id=None)

assistant_footprint

assistant_footprint(state, include_unaffected=False)

ask_consumer

ask_consumer(state, question)

compare_efficiency

compare_efficiency(state)

check_compile

check_compile(state, sql)

review_findings

review_findings(state, ids=None)