The activity_logging.py module#

Summary#

sanitize_args

Return a logging-safe copy of args.

summarise_result

Compact rendering of a tool’s return payload.

format_iterable_inline

Render an iterable as a compact comma-separated string.

truncate_text

Public truncation helper for one-line stdout/stderr summaries.

Description#

Helpers for compact, redaction-safe logging of tool calls and live session interactions.

Used by:

  • Backend run_code implementations: Logs the snippet that was sent

    to the live solver and the response it produced.

  • An optional higher-level agent layer (when installed): Logs every tool invocation (name, sanitized arguments, latency, and brief result). This package exposes the helpers. It does not import that layer.

All records flow through Python’s logging module on dedicated child loggers under the ansys.cfx.mcp namespace so they are captured by the session log file installed by ansys.cfx.mcp.common.session_logging without callers needing to know that file exists.

Module detail#

activity_logging.sanitize_args(args: Any, *, limit: int = _DEFAULT_VALUE_LIMIT) Any#

Return a logging-safe copy of args.

  • Redacts secret-looking keys.

  • Truncates string values longer than limit.

  • Recursively descends into dictionaries, lists, and tuples.

Other scalar types (int, float, bool, None) are returned as-is.

Parameters:
argsAny

Positional arguments forwarded to the wrapped call.

limitint

Maximum number of items or characters to include.

Returns:
Any

Result produced by the function.

activity_logging.summarise_result(result: Any, *, limit: int = _DEFAULT_VALUE_LIMIT) Any#

Compact rendering of a tool’s return payload.

Tool handlers return a wide variety of dictionaries (some with large nested state, snapshot, or preview blobs). Top-level keys are kept, but values are truncated aggressively so the log line stays under a few kilobytes. Non-dictionary returns are truncated.

Parameters:
resultAny

Result object to summarize for logging.

limitint

Maximum number of items or characters to include.

Returns:
Any

Result produced by the function.

activity_logging.format_iterable_inline(items: Iterable[Any], *, limit: int = 200) str#

Render an iterable as a compact comma-separated string.

Parameters:
itemsIterable[Any]

Items to format or summarize.

limitint

Maximum number of items or characters to include.

Returns:
str

String result produced by the function.

activity_logging.truncate_text(text: str, *, limit: int = _DEFAULT_TEXT_LIMIT) str#

Public truncation helper for one-line stdout/stderr summaries.

Parameters:
textstr

Text value to parse, normalize, or write.

limitint

Maximum number of items or characters to include.

Returns:
str

String result produced by the function.

activity_logging.TOOL_LOGGER#
activity_logging.SESSION_LOGGER#