| 1 | # llm_result.py DOX |
| 2 | |
| 3 | ## Purpose |
| 4 | |
| 5 | - Own canonical LLM result metadata shared by model transports, history, and tool-result processing. |
| 6 | - Preserve Responses API output items, provider response IDs, reasoning text, usage, and capability metadata in a serializable form. |
| 7 | |
| 8 | ## Ownership |
| 9 | |
| 10 | - `llm_result.py` owns the runtime implementation. |
| 11 | - `llm_result.py.dox.md` owns durable notes about responsibilities, contracts, side effects, and verification for that implementation. |
| 12 | - Classes: |
| 13 | - `ResponseItem` |
| 14 | - `ResponseFunctionCall` |
| 15 | - `LLMResult` |
| 16 | - Top-level functions include metadata conversion, function-call output item construction, object normalization, output-text extraction, reasoning extraction, and function-call argument parsing. |
| 17 | |
| 18 | ## Runtime Contracts |
| 19 | |
| 20 | - `LLMResult.metadata()` stores only durable provider state under `RESPONSE_METADATA_KEY`: response IDs, structured output items, provider/mode/state, usage, and capability data. Runtime prompt inputs, raw responses, and duplicated response/reasoning text are not persisted in history. |
| 21 | - `from_response(...)` must preserve provider `response_id`, `previous_response_id`, raw output items, usage, and capability metadata. |
| 22 | - `from_chat(...)` must produce an equivalent chat-completions result with `mode="chat_completions"` and `state="off"`, preserving optional function-call output items and provider usage when the chat transport supplies them. |
| 23 | - Function-call output items must preserve `call_id` and optional acknowledged safety checks. |
| 24 | - Argument parsing must tolerate JSON strings, dictionaries, and malformed values without throwing. |
| 25 | |
| 26 | ## Work Guidance |
| 27 | |
| 28 | - Keep metadata backward-compatible with existing serialized chat history. |
| 29 | - Treat unknown response item types as preserved built-in items unless they are local function calls, message text, or reasoning. |
| 30 | - Avoid provider-specific assumptions in result parsing. |
| 31 | |
| 32 | ## Verification |
| 33 | |
| 34 | - Run `pytest tests/test_responses_architecture.py -q` after changing result metadata behavior. |
| 35 | - Run focused history/tool-processing tests when changing function-call serialization. |
| 36 | |
| 37 | ## Child DOX Index |
| 38 | |
| 39 | No child DOX files. |