aidputils.agents.tools.http.optimizers.json_optimizer

JSON response optimizer.

Provides field selection, exclusion, and nested path extraction for JSON responses.

aidputils.agents.tools.http.optimizers.json_optimizer.get_nested_value(data: Any, path: str) Any[source]

Extract a value from nested data using dot-notation path.

Parameters:
  • data – The data structure to extract from

  • path – Dot-notation path (e.g., ‘data.results’, ‘user.profile.name’)

Returns:

The value at the specified path

Raises:

KeyError – If the path doesn’t exist

aidputils.agents.tools.http.optimizers.json_optimizer.filter_dict_fields(data: Dict[str, Any], include_fields: List[str] | None = None, exclude_fields: List[str] | None = None) Dict[str, Any][source]

Filter dictionary fields by include/exclude lists.

Supports dot-notation for nested field access.

Parameters:
  • data – The dictionary to filter

  • include_fields – Fields to include (if specified, only these are kept)

  • exclude_fields – Fields to exclude (removed from result)

Returns:

Filtered dictionary

class aidputils.agents.tools.http.optimizers.json_optimizer.JsonResponseOptimizer[source]

Bases: ResponseOptimizer

Optimizer for JSON responses.

classmethod response_type() str[source]

Return response type this optimizer handles.

optimize(data: Any, config: Dict[str, Any]) Any[source]

Optimize JSON response for LLM consumption.

Parameters:
  • data – The JSON data to optimize

  • config – Optimization configuration with keys: - field_containing_data: Dot-notation path to extract - include_fields: Fields to include in result - exclude_fields: Fields to exclude from result

Returns:

Optimized JSON data