AI Workers and Prompts

This is where we manage the LLMs that run our prompts. We use Instructor and LiteLLM to (i) provide a coherent API across vendors; and (ii) to hide configuration and API Keys and credentials from aidoc user(s).

class lbn.aidoc.intelligence.Analytics

Bases: BaseModel

The Master Ledger: A structured Pydantic record of all AI drills.

class Mode

Bases: Enum

ALL = 3
FIRST = 4
MERGED = 1
PROVIDER = 2
add_inference(prompt_name: str, inference: Inference)

Notarise: Strictly replaces the previous entry for the SAME provider.

all_providers() List[str]

Flatten the nested providers across all active stages and return a unique set.

fetch_telemetry(prompt_name: str, provider: str) Dict[str, Any]

The Forensic Bridge: Looks up the target inference, and uses its native, dynamic .telemetry property to lazy-load the metrics block from MLflow.

find(prompt_name: str, mode: Mode = 'Mode.MERGED', provider: str | None = None) Any

Retrieves the merged high-fidelity Pydantic model instance from the ledger. Consistently maps raw primitives back into the true output schema class.

inferences(prompt_name: str | None = None, provider: str | None = None) List[Inference]

Exhale the raw list of Inference object contracts for a specific stage. If a provider string is passed, filters explicitly for that worker identity.

model_config = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

prompts() List[str]

Exhale the list of all prompt names currently in the ledger.

providers(prompt_name: str) List[str]

Exhale the hardware addresses (providers) for a specific prompt.

serialize_prompt_records() Dict[str, Any]

Automated Extraction: Explicitly invokes the native serializer method defined on the Inference instances inside the collection arrays.

stages: Dict[str, List[Inference]]
class lbn.aidoc.intelligence.Inference

Bases: BaseModel

The ‘Contract’: Encapsulates AI conclusion data and local identity tags.

data: Any
property is_tracked: bool
mlflow_run_id: str | None
model_config = {'arbitrary_types_allowed': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

provider: str
raw_content: str
serialize_inference_contract() Dict[str, Any]

The Definitive Serialization Anchor: Safely dumps the nested data field regardless of whether it’s a sub-model or a validated payload primitive.

property span_id
property telemetry: CompletionUsage | None

The Forensic Bridge: Returns our local tracking record, or reaches out across the wire to lazy-load the token schema natively using the Phoenix Client.

property trace_id
usage: CompletionUsage | None
class lbn.aidoc.intelligence.PromptRunner

Bases: object

Coordinates our LLM architecture and runs our Prompt model(s).

__init__(name: str)

named runner

compile(prompt: Prompt, **kwargs) List[Message]

populate the prompt attributes with the kwargs values

compile_uri(prompt, label: str, uri: str, context: Dict[str, Any]) str
run(session: Session, analytics: Analytics, prompts: List[Prompt], context: Dict = None, weight: Weight = None) None

The Sisal Wheel: Iterates prompts, dispatches to workers, and notarises each attempt into the Analytics ledger.