Skip to content

API Reference parrot_tools.whatif_toolkit

github-actions[bot] edited this page Dec 2, 2026 · 4 revisions

parrot_tools.whatif_toolkit

View source

WhatIf Toolkit — Decomposed What-If Scenario Analysis.

Alias AbstractToolkit

Re-exported from parrot_tools.toolkit.AbstractToolkit.

Class AddActionsInput

Input for add_actions tool.

Fields:

Field Type Default Description
scenario_id str Scenario ID from describe_scenario
actions List[WhatIfAction] Actions to add to the scenario

Class CompareScenariosInput

Input for compare_scenarios tool.

Fields:

Field Type Default Description
scenario_ids List[str] Two or more scenario IDs to compare side by side

Alias DerivedMetric

Re-exported from parrot_tools.whatif.DerivedMetric.

Class DescribeScenarioInput

Input for describe_scenario tool.

Fields:

Field Type Default Description
df_name str Name or alias of the dataset to analyze
scenario_description str Natural language description of the scenario
derived_metrics List[DerivedMetric] Calculated metrics (e.g., ebitda = revenue - expenses)

Alias MetricsCalculator

Re-exported from parrot_tools.whatif.MetricsCalculator.

Class QuickImpactInput

Input for quick_impact tool -- the simple fast-path.

Fields:

Field Type Default Description
df_name str Name or alias of the dataset
action_description str Natural language: 'remove Belkin', 'increase visits by 30%', 'close North region'
action_type str Type: exclude_values, scale_entity, adjust_metric, scale_proportional, close_region
target str Column or entity to act on
parameters Dict[str, Any] Action-specific parameters

Alias ScenarioOptimizer

Re-exported from parrot_tools.whatif.ScenarioOptimizer.

Alias ScenarioResult

Re-exported from parrot_tools.whatif.ScenarioResult.

Class ScenarioState

Internal state for a scenario being built incrementally.

Parameter Type Default Description
id str
description str
df_name str
df pd.DataFrame
derived_metrics List[DerivedMetric]
actions List[Any]
objectives List[Any]
constraints List[Any]
result Optional[ScenarioResult] None
created_at datetime datetime.now()

Fields:

Field Type Default Description
id str
description str
df_name str
df pd.DataFrame
derived_metrics List[DerivedMetric]
actions List[Any]
objectives List[Any]
constraints List[Any]
result Optional[ScenarioResult] None
created_at datetime field(default_factory=datetime.now)

Attributes:

Attribute Type Description
is_ready bool Scenario has at least one action defined.
is_solved bool Scenario has been simulated.

Class SetConstraintsInput

Input for set_constraints tool.

Fields:

Field Type Default Description
scenario_id str Scenario ID from describe_scenario
objectives List[WhatIfObjective] Optimization objectives (minimize, maximize, target)
constraints List[WhatIfConstraint] Constraints to respect (max_change, min_value, max_value, ratio)

Class SimulateInput

Input for simulate tool.

Fields:

Field Type Default Description
scenario_id str Scenario ID from describe_scenario
algorithm str 'greedy' Algorithm: 'greedy' or 'genetic'
max_actions int 5 Maximum actions to apply

Attribute WHATIF_PROMPT_LAYER

Attribute WHATIF_TOOLKIT_SYSTEM_PROMPT

Alias WhatIfAction

Re-exported from parrot_tools.whatif.WhatIfAction.

Alias WhatIfConstraint

Re-exported from parrot_tools.whatif.WhatIfConstraint.

Alias WhatIfDSL

Re-exported from parrot_tools.whatif.WhatIfDSL.

Alias WhatIfObjective

Re-exported from parrot_tools.whatif.WhatIfObjective.

Class WhatIfToolkit

What-If scenario analysis toolkit for simulating hypothetical changes on datasets.

Parameter Type Default Description
dataset_manager Optional[Any] None
pandas_tool Optional[Any] None
**kwargs {}

Method WhatIfToolkit.describe_scenario

Create and validate a what-if scenario on a dataset. Returns scenario ID, column inventory, derived metrics status, and suggested actions. Use this as the first step of a multi-step what-if analysis.

describe_scenario(df_name: str, scenario_description: str, derived_metrics: Optional[List[DerivedMetric]] = None) -> str

Parameter Type Default Description
df_name str
scenario_description str
derived_metrics Optional[List[DerivedMetric]] None

Returns: str

Method WhatIfToolkit.add_actions

Add possible actions to an existing scenario. Validates each action against the DataFrame schema and reports invalid ones.

add_actions(scenario_id: str, actions: List[WhatIfAction]) -> str

Parameter Type Default Description
scenario_id str
actions List[WhatIfAction]

Returns: str

Method WhatIfToolkit.set_constraints

Define optimization objectives and constraints for a scenario. Validates metric names against columns and registered derived metrics.

set_constraints(scenario_id: str, objectives: Optional[List[WhatIfObjective]] = None, constraints: Optional[List[WhatIfConstraint]] = None) -> str

Parameter Type Default Description
scenario_id str
objectives Optional[List[WhatIfObjective]] None
constraints Optional[List[WhatIfConstraint]] None

Returns: str

Method WhatIfToolkit.simulate

Execute a configured scenario using the WhatIfDSL optimization engine. Registers the result DataFrame in DatasetManager for follow-up analysis.

simulate(scenario_id: str, algorithm: str = 'greedy', max_actions: int = 5) -> str

Parameter Type Default Description
scenario_id str
algorithm str 'greedy'
max_actions int 5

Returns: str

Method WhatIfToolkit.quick_impact

Fast-path for simple what-if queries. Resolves dataset, applies a single action, and returns before/after comparison -- all in one call. Use for questions like 'what if we remove X?' or 'what if we increase Y by Z%?'.

quick_impact(df_name: str, action_description: str, action_type: str, target: str, parameters: Optional[Dict[str, Any]] = None) -> str

Parameter Type Default Description
df_name str
action_description str
action_type str
target str
parameters Optional[Dict[str, Any]] None

Returns: str

Method WhatIfToolkit.compare_scenarios

Compare two or more simulated scenarios side by side. All scenarios must have been simulated (is_solved=True). Returns a comparison matrix that marks the best scenario per metric, ranking each metric by the objective declared for it (via set_constraints). Metrics with no declared objective are shown but left unranked, because "better" is not defined for them.

compare_scenarios(scenario_ids: List[str]) -> str

Parameter Type Default Description
scenario_ids List[str]

Returns: str

Function inject_whatif_system_prompt

Put the toolkit's usage instructions into an agent's system prompt.

Without these instructions the model sees six tools with terse docstrings and no guidance on how they chain, so it tends to fall back to whatever general-purpose tool it already trusts.

Agents assemble their prompt in more than one way, and the mechanisms are not interchangeable: bots driven by a PromptBuilder build from layers and ignore system_prompt_template entirely, so appending to the latter reaches nothing. Each mechanism is therefore tried in order of specificity and the one that applied is reported back, so a caller can tell injection apart from silent failure.

inject_whatif_system_prompt(agent: Any, prompt: str = WHATIF_TOOLKIT_SYSTEM_PROMPT) -> Optional[str]

Parameter Type Default Description
agent Any The agent to inject into.
prompt str WHATIF_TOOLKIT_SYSTEM_PROMPT The instructions to add.

Returns: Optional[str] — The name of the mechanism used, or None if the agent exposes no way to extend its system prompt.

Function integrate_whatif_toolkit

Integrate WhatIfToolkit into an agent.

Resolves DatasetManager and PythonPandasTool from agent if not provided. Registers all 6 tools and adds system prompt.

integrate_whatif_toolkit(agent, dataset_manager: Optional[Any] = None, pandas_tool: Optional[Any] = None) -> WhatIfToolkit

Parameter Type Default Description
agent The agent to integrate with.
dataset_manager Optional[Any] None Optional DatasetManager instance.
pandas_tool Optional[Any] None Optional PythonPandasTool instance.

Returns: WhatIfToolkit — The configured WhatIfToolkit instance.

Architecture

Clients

Bots & Agents

Memory

Knowledge

Tools & Toolkits

Flows

Experts

Skills

Stores & Loaders

MCP & A2A

Server & APIs

Integrations

Outputs & A2UI

Prompts

Security

Operations

Migration

SDD Tooling

LLM Wiki

Deployment

Decisions

API Reference

Clone this wiki locally