core.response_context

Shared prompt attribute history with thread-safe recording.

Shared prompt attribute history with thread-safe recording.

class ResponseContext(shared_prompt_attr_history=None, history_lock=None)[source]

Bases: object

Manages the shared prompt_attr_history list with thread-safe recording.

This class centralises all mutation of the shared prompt-attribute history that PromptBuilder reads from for {{name.response}} interpolation. It replaces the inline history recording previously scattered through FFAI.generate_response() and direct list appends in PlanningRunner / SynthesisRunner.

Parameters:
  • shared_prompt_attr_history (list[dict[str, Any]] | None) – Optional pre-existing list to share. When None a new empty list is created.

  • history_lock (threading.Lock | None) – Optional lock for thread-safe access.

record(prompt, response, model, prompt_name=None, history=None)[source]

Record an interaction to prompt_attr_history.

If response is a dict (JSON response from the LLM), each top-level key-value pair is recorded as a separate entry so that {{key_name.response}} interpolation works.

Parameters:
  • prompt (str) – The original prompt text (or JSON key name).

  • response (Any) – The cleaned response (str, dict, etc.).

  • model (str) – Model identifier used for this call.

  • prompt_name (str | None) – Optional logical name for the prompt.

  • history (list[str] | None) – Optional list of history dependency names.

Return type:

None

record_raw(interaction)[source]

Append a pre-built interaction dict.

Used by PlanningRunner and SynthesisRunner to inject results that were not produced by FFAI.generate_response().

Parameters:

interaction (dict[str, Any]) – A dict with at least prompt, response, prompt_name keys.

Return type:

None

clear()[source]

Clear the shared history list (used by synthesis phase reset).

Return type:

None

property history_lock: threading.Lock | None

The lock used for thread-safe history access.

Classes

class ResponseContext(shared_prompt_attr_history=None, history_lock=None)[source]

Bases: object

Manages the shared prompt_attr_history list with thread-safe recording.

This class centralises all mutation of the shared prompt-attribute history that PromptBuilder reads from for {{name.response}} interpolation. It replaces the inline history recording previously scattered through FFAI.generate_response() and direct list appends in PlanningRunner / SynthesisRunner.

Parameters:
  • shared_prompt_attr_history (list[dict[str, Any]] | None) – Optional pre-existing list to share. When None a new empty list is created.

  • history_lock (threading.Lock | None) – Optional lock for thread-safe access.

record(prompt, response, model, prompt_name=None, history=None)[source]

Record an interaction to prompt_attr_history.

If response is a dict (JSON response from the LLM), each top-level key-value pair is recorded as a separate entry so that {{key_name.response}} interpolation works.

Parameters:
  • prompt (str) – The original prompt text (or JSON key name).

  • response (Any) – The cleaned response (str, dict, etc.).

  • model (str) – Model identifier used for this call.

  • prompt_name (str | None) – Optional logical name for the prompt.

  • history (list[str] | None) – Optional list of history dependency names.

Return type:

None

record_raw(interaction)[source]

Append a pre-built interaction dict.

Used by PlanningRunner and SynthesisRunner to inject results that were not produced by FFAI.generate_response().

Parameters:

interaction (dict[str, Any]) – A dict with at least prompt, response, prompt_name keys.

Return type:

None

clear()[source]

Clear the shared history list (used by synthesis phase reset).

Return type:

None

property history_lock: threading.Lock | None

The lock used for thread-safe history access.