mirror of
https://github.com/BerriAI/litellm.git
synced 2026-11-28 00:00:38 +00:00
4.2 KiB
4.2 KiB
- Target invariants, not completion claims
- This crate owns compatibility for all existing Python callbacks and loggers, including
CustomLogger.mapping.rsis the one table of every publicCustomLoggermethod: the boundary (litellm_host::hooks::CallBoundary) and operations a native call runs it at, or the Python module that still owns it. A test keeps the table equal toCustomLogger's public methods, so a new callback does not compile in until a row says where it runs. A Python-owned entry records an existing path, never permission to invoke it a second time. The native call adapter preserves theLoggingcontract (function_setup, the deployment hooks,pre_call/post_call, the sync and async success and failure fan-out, the deferred proxy release, the argument sharing those callbacks rely on)- Smell test: if a future callback host (
callbacks-v1-python, WASM, in-process Rust) could share a piece of this crate, it does not belong here LegacyLayeris the crate's only composition entry, aHookLayeroverPublicCall: it returns this crate's hooks as one ordered group,Loggingfirst, then the SDK request policy the@clientwrapper applies (credential inheritance, the budget and retry-count limits,preflight.rs), then the resolve edge (resolve.rs). The caller's keyword dict is a legacy fact: callbacks mutate it mid-call, so it never leaves this group. Everything after the edge, the SDK preflight included, sees one resolved dict (the keyword layer laid over the signature base), and nothing outside this crate merges the two- The driver in
litellm-host-python, the routes and core see boxedHooksusing the sharedCallEvent; they never learn which Python objects consume a call
- Smell test: if a future callback host (
- Every litellm Python internal Rust still borrows is a variant of
LegacyPython, grouped by subsystem, with its signature pinned inpython_contract.json- The enum only shrinks: when Rust owns a subsystem, delete its group rather than adding a Rust path beside it
- Calling a user's own callback directly is permanent Python surface and gets its own type outside
LegacyPython
PublicCallis the caller's call asLoggingsees it: the positional arguments, the keyword view as the call rewrites it (setup, deployment hook, preflight, the Messages pre-request fan-out) and the signature base backing omitted keywords; shared bridge composition hands it toLegacyLogging; routes use the neutral call boundary. A route needs a pre-hook view only to admit or decline a call, and reads Python's own binding (NativeCall.resolved) for that- Routes identify a call by the neutral
litellm_host::call::Operation; whatLoggingmakes of it (call types, input description, pass-through stream billing) is this crate'soperation::profiletable and belongs here rather than in shared inference data contracts setupreuses aLoggingpassed aslitellm_logging_obj(the proxy and Router) and otherwise builds one throughfunction_setup; which callbacks run isLogging's decision, never this crate's- Callbacks receive the caller's own objects and may mutate them; this crate alone carries that obligation
- Retain complete boundary arguments, opaque values, aliases, omitted/default distinctions and deliberate copies; preserve the deployment-hook kwargs view
- Before
pre_call, re-alias every body key whose value equals the caller's argument to the caller's own object, resolved throughPublicCall::lookup - Retain body/header roots from
pre_calltopost_call; in-place mutation reaches the wire, envelope field replacement is visible to later callbacks only
- Success and failure handlers receive the exact selected public response or exception
- A failure-handler error cannot suppress the other eligible family or replace the mapped provider error; a cancellation ends the call with no further dispatch
- Dispatch errors never replay provider work or trigger the opposite outcome; the proxy releases deferred success at most once
- Delivery follows the registry, not the callable's type: direct, awaited, executor-submitted, logging-worker and deferred paths stay distinct
- Traverse every retained Python edge;
closeis idempotent and restores the correlation context once