core.async_client_base

Async abstract base class for AI client implementations.

Mirrors FFAIClientBase but with generate_response and clone as async methods. In-memory operations (conversation history get/set, clear) remain synchronous.

Async abstract base class for AI client implementations.

Mirrors FFAIClientBase but with generate_response and clone as async methods. In-memory operations (conversation history get/set, clear) remain synchronous.

class AsyncFFAIClientBase[source]

Bases: FFAIClientBase

Async variant of FFAIClientBase for use with execute_graph.

Subclasses must implement generate_response and clone as async methods. All other methods (clear_conversation, get_conversation_history, set_conversation_history) remain synchronous because they operate on in-memory lists.

abstractmethod async generate_response(prompt, **kwargs)[source]

Generate a response from the AI model.

Parameters:
  • prompt (str) – The user prompt to send to the model.

  • **kwargs (Any) – Additional model-specific parameters.

Returns:

The generated response string.

Return type:

str

abstractmethod async clone()[source]

Create a fresh async clone of this client with empty history.

Returns:

New AsyncFFAIClientBase instance with same config, empty history.

Return type:

AsyncFFAIClientBase

Classes

class AsyncFFAIClientBase[source]

Bases: FFAIClientBase

Async variant of FFAIClientBase for use with execute_graph.

Subclasses must implement generate_response and clone as async methods. All other methods (clear_conversation, get_conversation_history, set_conversation_history) remain synchronous because they operate on in-memory lists.

abstractmethod async generate_response(prompt, **kwargs)[source]

Generate a response from the AI model.

Parameters:
  • prompt (str) – The user prompt to send to the model.

  • **kwargs (Any) – Additional model-specific parameters.

Returns:

The generated response string.

Return type:

str

abstractmethod async clone()[source]

Create a fresh async clone of this client with empty history.

Returns:

New AsyncFFAIClientBase instance with same config, empty history.

Return type:

AsyncFFAIClientBase

add_tool_result(tool_call_id, content)

Add a tool result to the conversation history.

Default implementation appends a tool-role message. Subclasses that manage conversation history differently (e.g. via an external API) should override this method.

Parameters:
  • tool_call_id (str) – The ID of the tool call this result responds to.

  • content (str) – The tool execution result string.

Return type:

None

abstractmethod clear_conversation()

Clear the conversation history.

Return type:

None

configure_retry(retry_config=None)

Configure retry behavior for this client.

Parameters:

retry_config (dict[str, Any] | None) – Optional retry configuration. If None, uses global config.

Return type:

None

abstractmethod get_conversation_history()

Get the conversation history.

Returns:

List of message dictionaries with role and content keys.

Return type:

list[dict[str, Any]]

static get_default_retry_config()

Get default retry configuration from global config.

Returns:

Dictionary with retry configuration parameters.

Return type:

dict[str, Any]

property last_cost_usd: float

Estimated cost in USD from the most recent generate_response() call.

property last_duration_ms: float | None

Wall-clock duration in ms of the most recent generate_response() call.

property last_usage: TokenUsage | None

Token usage from the most recent generate_response() call.

retry_config: dict[str, Any] | None = None
abstractmethod set_conversation_history(history)

Set the conversation history.

Parameters:

history (list[dict[str, Any]]) – List of message dictionaries with role and content keys.

Return type:

None

model: str
system_instructions: str