BaseLogger

BaseLogger()

Helper class that provides a standard way to create an ABC using inheritance.

Instance Methods

get_connection

get_connection(self) -> None | Connection

Return a connection to the logging database.


log_chat_completion

log_chat_completion(
    self,
    invocation_id: UUID,
    client_id: int,
    wrapper_id: int,
    source: str | Agent,
    request: dict[str, float | str | list[dict[str, str]]],
    response: str | ChatCompletion,
    is_cached: int,
    cost: float,
    start_time: str
) -> None

Log a chat completion to database.
In AG2, chat completions are somewhat complicated because they are handled by the autogen.oai.OpenAIWrapper class.
One invocation to create can lead to multiple underlying OpenAI calls, depending on the llm_config list used, and any errors or retries.

Parameters:
NameDescription
invocation_idA unique identifier for the invocation to the OpenAIWrapper.create method call

Type: uuid.UUID
client_idA unique identifier for the underlying OpenAI client instance

Type: int
wrapper_idA unique identifier for the OpenAIWrapper instance

Type: int
sourceThe source/creator of the event as a string name or an Agent instance

Type: str | Agent
requestA dictionary representing the request or call to the OpenAI client endpoint

Type: dict[str, float | str | list[dict[str, str]]]
responseThe response from OpenAI

Type: str | ChatCompletion
is_cached1 if the response was a cache hit, 0 otherwise

Type: int
costThe cost for OpenAI response

Type: float
start_timeA string representing the moment the request was initiated

Type: str

log_event

log_event(
    self,
    source: str | Agent,
    name: str,
    **kwargs: dict[str, Any]
) -> None

Log an event for an agent.

Parameters:
NameDescription
sourceThe source/creator of the event as a string name or an Agent instance

Type: str | Agent
nameThe name of the event

Type: str
**kwargsType: dict[str, Any]

log_function_use

log_function_use(
    self,
    source: str | Agent,
    function: F,
    args: dict[str, Any],
    returns: Any
) -> None

Log the use of a registered function (could be a tool)

Parameters:
NameDescription
sourceThe source/creator of the event as a string name or an Agent instance

Type: str | Agent
functionThe function information

Type: F
argsThe function args to log

Type: dict[str, Any]
returnsThe return

Type: Any

log_new_agent

log_new_agent(
    self,
    agent: ConversableAgent,
    init_args: dict[str, Any]
) -> None

Log the birth of a new agent.

Parameters:
NameDescription
agentThe agent to log.

Type: ConversableAgent
init_argsThe arguments passed to the construct the conversable agent

Type: dict[str, Any]

log_new_client

log_new_client(
    self,
    client: AzureOpenAI | OpenAI,
    wrapper: OpenAIWrapper,
    init_args: dict[str, Any]
) -> None

Log the birth of a new OpenAIWrapper.

Parameters:
NameDescription
clientType: AzureOpenAI | OpenAI
wrapperThe OpenAI client to log.

Type: OpenAIWrapper
init_argsThe arguments passed to the construct the client

Type: dict[str, Any]

log_new_wrapper

log_new_wrapper(
    self,
    wrapper: OpenAIWrapper,
    init_args: dict[str, LLMConfig | list[LLMConfig]]
) -> None

Log the birth of a new OpenAIWrapper.

Parameters:
NameDescription
wrapperThe wrapper to log.

Type: OpenAIWrapper
init_argsThe arguments passed to the construct the wrapper

Type: dict[str, LLMConfig | list[LLMConfig]]

start

start(self) -> str

Open a connection to the logging database, and start recording.
Returns:
session_id (str): a unique id for the logging session

Returns:
TypeDescription
strsession_id (str): a unique id for the logging session

stop

stop(self) -> None

Close the connection to the logging database, and stop logging.