Clients.BaseLiteLLMClient

Shared base for sync and async LiteLLM-backed AI clients.

Contains all non-I/O logic: settings resolution, env var lookup, message building, usage extraction, tool call serialization, and conversation history management. Subclasses provide sync/async completion() calls.

Shared base for sync and async LiteLLM-backed AI clients.

Contains all non-I/O logic: settings resolution, env var lookup, message building, usage extraction, tool call serialization, and conversation history management. Subclasses provide sync/async completion() calls.

class BaseLiteLLMClient(model_string, config=None, *, api_key=None, api_base=None, api_version=None, system_instructions=None, temperature=None, max_tokens=None, fallbacks=None, retry_config=None, **kwargs)[source]

Bases: object

Mixin providing shared logic for LiteLLM-backed clients.

Subclasses must: - Inherit from this class and FFAIClientBase (or its async variant) - Implement generate_response(), _call_primary(),

_try_fallbacks(), and clone()

Parameters:
  • model_string (str)

  • config (dict[str, Any] | None)

  • api_key (str | None)

  • api_base (str | None)

  • api_version (str | None)

  • system_instructions (str)

  • temperature (float)

  • max_tokens (int)

  • fallbacks (list[str] | None)

  • retry_config (dict[str, Any] | None)

  • kwargs (Any)

system_instructions: str
api_key: str | None
api_base: str | None
api_version: str | None
temperature: float
max_tokens: int
model: str
conversation_history: list[dict[str, Any]]
add_tool_result(tool_call_id, content)[source]

Append a tool result message to the conversation history.

Parameters:
  • tool_call_id (str) – Provider-specific ID of the tool call being answered.

  • content (str) – The tool’s return value as a string.

Return type:

None

clear_conversation()[source]

Remove all messages from the conversation history.

Return type:

None

get_conversation_history()[source]

Return a shallow copy of the conversation history.

Returns:

List of message dictionaries.

Return type:

list[dict[str, Any]]

set_conversation_history(history)[source]

Replace the conversation history with a new list of messages.

Parameters:

history (list[dict[str, Any]]) – List of message dictionaries to set.

Return type:

None

Classes

class BaseLiteLLMClient(model_string, config=None, *, api_key=None, api_base=None, api_version=None, system_instructions=None, temperature=None, max_tokens=None, fallbacks=None, retry_config=None, **kwargs)[source]

Bases: object

Mixin providing shared logic for LiteLLM-backed clients.

Subclasses must: - Inherit from this class and FFAIClientBase (or its async variant) - Implement generate_response(), _call_primary(),

_try_fallbacks(), and clone()

Parameters:
  • model_string (str)

  • config (dict[str, Any] | None)

  • api_key (str | None)

  • api_base (str | None)

  • api_version (str | None)

  • system_instructions (str)

  • temperature (float)

  • max_tokens (int)

  • fallbacks (list[str] | None)

  • retry_config (dict[str, Any] | None)

  • kwargs (Any)

system_instructions: str
api_key: str | None
api_base: str | None
api_version: str | None
temperature: float
max_tokens: int
model: str
conversation_history: list[dict[str, Any]]
add_tool_result(tool_call_id, content)[source]

Append a tool result message to the conversation history.

Parameters:
  • tool_call_id (str) – Provider-specific ID of the tool call being answered.

  • content (str) – The tool’s return value as a string.

Return type:

None

clear_conversation()[source]

Remove all messages from the conversation history.

Return type:

None

get_conversation_history()[source]

Return a shallow copy of the conversation history.

Returns:

List of message dictionaries.

Return type:

list[dict[str, Any]]

set_conversation_history(history)[source]

Replace the conversation history with a new list of messages.

Parameters:

history (list[dict[str, Any]]) – List of message dictionaries to set.

Return type:

None