litellm/litellm-rust/crates/callbacks-legacy-python/AGENTS.md
Yujong Lee 336021ecdf refactor(callbacks-legacy-python): name borrowed hooks as Python names them
The shim functions, the contract keys and the Rust variants now carry the
litellm.utils names for the three deployment hook fan-outs, and the
Messages handler's pre-request fan-out gets its own group instead of
sharing the deployment one. Pending states and the facade follow suit.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-09-26 08:16:47 +00:00

3 KiB

  • Target invariants, not completion claims
  • This crate is the legacy @client wrapper as the native call sees it, and nothing else: the Logging contract (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
    • SDK request policy (credential inheritance, the budget and retry-count limits) is the driver's preflight, supplied by python-bridge; this crate only adopts the keyword view it produces
    • The driver in litellm-host-python, the routes and core see one PythonLifecycle; they never learn which Python objects consume a call
  • Rust drives the call; every litellm Python internal it still borrows is a variant of LegacyPython, grouped by the Python owner it borrows from (Wrapper, Logging, DeploymentHooks, MessagesHandler, Streaming), and every borrowed function keeps the name Python gives it
    • 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
  • PublicCall is the caller's call as Logging sees it: the positional arguments, the keyword view as the call rewrites it (setup, deployment hook, preflight) and the bound request object backing omitted keywords; routes hand it over through run_legacy_call and keep no copy
  • setup reuses a Logging passed as litellm_logging_obj (the proxy and Router) and otherwise builds one through function_setup; which callbacks run is Logging'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 through litellm_host_python::lookup
    • Retain body/header roots from pre_call to post_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; close is idempotent and restores the correlation context once