aidputils.agents.tools.http.response_optimizer

Response Optimizer for HTTP Tool.

Provides LLM token optimization using pluggable parser/optimizer architecture.

exception aidputils.agents.tools.http.response_optimizer.OptimizationError[source]

Bases: ValueError

Exception raised for response optimization errors.

aidputils.agents.tools.http.response_optimizer.optimize_json_response(data: Any, field_containing_data: str = None, include_fields: list = None, exclude_fields: list = None) Any[source]

Optimize JSON response for LLM consumption.

Parameters:
  • data – The JSON data to optimize

  • 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

aidputils.agents.tools.http.response_optimizer.extract_html_content(html: str, css_selector: str = None, strip_tags: bool = False) str[source]

Extract content from HTML using CSS selector.

Parameters:
  • html – The HTML content

  • css_selector – CSS selector to extract

  • strip_tags – Whether to strip HTML tags from result

Returns:

Extracted content

aidputils.agents.tools.http.response_optimizer.truncate_text(text: str, max_characters: int) str[source]

Truncate text to a maximum number of characters.

Parameters:
  • text – The text to truncate

  • max_characters – Maximum characters allowed

Returns:

Truncated text (with ‘…’ if truncated)

aidputils.agents.tools.http.response_optimizer.optimize_response(response_data: Any, content_type: str, optimization_config: Dict[str, Any]) Any[source]

Optimize a response based on configuration using pluggable architecture.

Parameters:
  • response_data – The response data to optimize

  • content_type – Content-Type header value

  • optimization_config – Optimization settings

Returns:

Optimized response data