LLMMiddleware#

class council.llm.LLMMiddleware(*args, **kwargs)[source]#

Bases: Protocol

Protocol for defining LLM middleware.

Middleware can intercept and modify requests and responses between the client and the LLM, introducing custom logic.

LLMMiddlewareChain#

class council.llm.LLMMiddlewareChain(llm: LLMBase, middlewares: Sequence[LLMMiddleware] | None = None)[source]#

Bases: object

Manages a chain of LLM middlewares and executes requests through them.

add_middleware(middleware: LLMMiddleware) None[source]#

Add middleware to a chain.

execute(request: LLMRequest) LLMResponse[source]#

Execute middleware chain.

LLMLoggingMiddleware#

class council.llm.LLMLoggingMiddleware[source]#

Bases: object

Middleware for logging LLM requests and responses.

LLMFileLoggingMiddleware#

class council.llm.LLMFileLoggingMiddleware(log_file: str, component_name: str)[source]#

Bases: object

Middleware for logging LLM requests and responses into a file.

__init__(log_file: str, component_name: str) None[source]#

Initialize the middleware with the path to the log_file.

LLMRetryMiddleware#

class council.llm.LLMRetryMiddleware(retries: int, delay: float, exception_to_check: type[Exception] | None = None)[source]#

Bases: object

Middleware for implementing retry logic for LLM requests.

Attempts to retry failed requests a specified number of times with a delay between attempts.

LLMRequest#

class council.llm.LLMRequest(context: LLMContext, messages: Sequence[LLMMessage], **kwargs: Any)[source]#

Bases: object

static default(messages: Sequence[LLMMessage], **kwargs: Any) LLMRequest[source]#

Creates a default LLMRequest with an empty context.

LLMResponse#

class council.llm.LLMResponse(request: LLMRequest, result: LLMResult | None, duration: float)[source]#

Bases: object

static empty(request: LLMRequest) LLMResponse[source]#

Creates an empty LLMResponse for a given request.