timbal 2.7.40__tar.gz → 2.7.41__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (309) hide show
  1. {timbal-2.7.40 → timbal-2.7.41}/PKG-INFO +1 -1
  2. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/_version.py +2 -2
  3. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/core/runnable.py +23 -7
  4. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/server/http.py +4 -0
  5. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/state/context.py +59 -14
  6. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/state/tracing/providers/base.py +14 -0
  7. timbal-2.7.41/python/timbal/state/tracing/uploads.py +288 -0
  8. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/types/content/tool_use.py +22 -3
  9. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/voice/session.py +3 -1
  10. {timbal-2.7.40 → timbal-2.7.41}/.gitignore +0 -0
  11. {timbal-2.7.40 → timbal-2.7.41}/LICENSE +0 -0
  12. {timbal-2.7.40 → timbal-2.7.41}/README.md +0 -0
  13. {timbal-2.7.40 → timbal-2.7.41}/docs/api-reference/ace/chat-completions.mdx +0 -0
  14. {timbal-2.7.40 → timbal-2.7.41}/docs/api-reference/ace/create-from-workforce.mdx +0 -0
  15. {timbal-2.7.40 → timbal-2.7.41}/docs/api-reference/ace/jobs/cancel.mdx +0 -0
  16. {timbal-2.7.40 → timbal-2.7.41}/docs/api-reference/ace/jobs/create.mdx +0 -0
  17. {timbal-2.7.40 → timbal-2.7.41}/docs/api-reference/ace/jobs/get.mdx +0 -0
  18. {timbal-2.7.40 → timbal-2.7.41}/docs/api-reference/ace/jobs/list.mdx +0 -0
  19. {timbal-2.7.40 → timbal-2.7.41}/docs/api-reference/ace/jobs/retry.mdx +0 -0
  20. {timbal-2.7.40 → timbal-2.7.41}/docs/api-reference/ace/link.mdx +0 -0
  21. {timbal-2.7.40 → timbal-2.7.41}/docs/api-reference/ace/list-context-vars.mdx +0 -0
  22. {timbal-2.7.40 → timbal-2.7.41}/docs/api-reference/ace/list-policies.mdx +0 -0
  23. {timbal-2.7.40 → timbal-2.7.41}/docs/api-reference/ace/unlink.mdx +0 -0
  24. {timbal-2.7.40 → timbal-2.7.41}/pyproject.toml +0 -0
  25. {timbal-2.7.40 → timbal-2.7.41}/pyrightconfig.json +0 -0
  26. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/__init__.py +0 -0
  27. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/_openai_audio.py +0 -0
  28. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/_slots.py +0 -0
  29. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/codegen/__init__.py +0 -0
  30. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/codegen/__main__.py +0 -0
  31. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/codegen/cli_utils.py +0 -0
  32. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/codegen/cst_utils.py +0 -0
  33. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/codegen/flow.py +0 -0
  34. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/codegen/format.py +0 -0
  35. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/codegen/guardrail_specs.py +0 -0
  36. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/codegen/library.py +0 -0
  37. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/codegen/model_discovery.py +0 -0
  38. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/codegen/test.py +0 -0
  39. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/codegen/tool_discovery.py +0 -0
  40. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/codegen/transformers/__init__.py +0 -0
  41. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/codegen/transformers/add_edge.py +0 -0
  42. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/codegen/transformers/add_guardrail.py +0 -0
  43. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/codegen/transformers/add_mcp.py +0 -0
  44. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/codegen/transformers/add_step.py +0 -0
  45. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/codegen/transformers/add_tool.py +0 -0
  46. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/codegen/transformers/remove_edge.py +0 -0
  47. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/codegen/transformers/remove_guardrail.py +0 -0
  48. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/codegen/transformers/remove_step.py +0 -0
  49. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/codegen/transformers/remove_tool.py +0 -0
  50. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/codegen/transformers/set_config.py +0 -0
  51. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/codegen/transformers/set_param.py +0 -0
  52. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/codegen/transformers/set_position.py +0 -0
  53. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/collectors/__init__.py +0 -0
  54. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/collectors/base.py +0 -0
  55. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/collectors/harmony_leak.py +0 -0
  56. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/collectors/impl/__init__.py +0 -0
  57. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/collectors/impl/anthropic.py +0 -0
  58. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/collectors/impl/default.py +0 -0
  59. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/collectors/impl/message.py +0 -0
  60. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/collectors/impl/openai.py +0 -0
  61. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/collectors/impl/string.py +0 -0
  62. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/collectors/impl/timbal.py +0 -0
  63. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/collectors/registry.py +0 -0
  64. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/core/__init__.py +0 -0
  65. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/core/agent.py +0 -0
  66. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/core/attachment_limit.py +0 -0
  67. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/core/fallback_model.py +0 -0
  68. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/core/llm/__init__.py +0 -0
  69. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/core/llm/auto.py +0 -0
  70. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/core/llm/chat_completions.py +0 -0
  71. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/core/llm/clients.py +0 -0
  72. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/core/llm/messages.py +0 -0
  73. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/core/llm/registry.py +0 -0
  74. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/core/llm/responses.py +0 -0
  75. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/core/llm/retry.py +0 -0
  76. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/core/llm/router.py +0 -0
  77. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/core/mcp.py +0 -0
  78. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/core/memory_compaction.py +0 -0
  79. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/core/models.py +0 -0
  80. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/core/provider_errors.py +0 -0
  81. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/core/skill.py +0 -0
  82. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/core/test_model.py +0 -0
  83. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/core/tool.py +0 -0
  84. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/core/tool_result_offload.py +0 -0
  85. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/core/tool_set.py +0 -0
  86. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/core/workflow.py +0 -0
  87. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/errors.py +0 -0
  88. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/evals/__init__.py +0 -0
  89. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/evals/cli.py +0 -0
  90. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/evals/display.py +0 -0
  91. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/evals/fixtures/agent.py +0 -0
  92. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/evals/fixtures/eval_examples.yaml +0 -0
  93. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/evals/fixtures/eval_flow_validators.yaml +0 -0
  94. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/evals/fixtures/eval_negations.yaml +0 -0
  95. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/evals/fixtures/eval_parallel.yaml +0 -0
  96. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/evals/fixtures/eval_subagent.yaml +0 -0
  97. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/evals/fixtures/eval_transforms.yaml +0 -0
  98. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/evals/fixtures/test_invalid_validator.yaml +0 -0
  99. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/evals/models.py +0 -0
  100. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/evals/reporters.py +0 -0
  101. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/evals/runner.py +0 -0
  102. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/evals/utils.py +0 -0
  103. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/evals/validators/__init__.py +0 -0
  104. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/evals/validators/_spans.py +0 -0
  105. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/evals/validators/base.py +0 -0
  106. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/evals/validators/comparison_base.py +0 -0
  107. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/evals/validators/contains.py +0 -0
  108. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/evals/validators/contains_all.py +0 -0
  109. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/evals/validators/contains_any.py +0 -0
  110. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/evals/validators/context.py +0 -0
  111. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/evals/validators/email.py +0 -0
  112. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/evals/validators/ends_with.py +0 -0
  113. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/evals/validators/eq.py +0 -0
  114. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/evals/validators/gt.py +0 -0
  115. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/evals/validators/gte.py +0 -0
  116. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/evals/validators/json.py +0 -0
  117. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/evals/validators/language.py +0 -0
  118. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/evals/validators/length.py +0 -0
  119. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/evals/validators/llm_base.py +0 -0
  120. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/evals/validators/lt.py +0 -0
  121. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/evals/validators/lte.py +0 -0
  122. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/evals/validators/max_length.py +0 -0
  123. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/evals/validators/min_length.py +0 -0
  124. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/evals/validators/not_null.py +0 -0
  125. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/evals/validators/parallel.py +0 -0
  126. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/evals/validators/pattern.py +0 -0
  127. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/evals/validators/prompt.py +0 -0
  128. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/evals/validators/rubric.py +0 -0
  129. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/evals/validators/semantic.py +0 -0
  130. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/evals/validators/seq.py +0 -0
  131. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/evals/validators/starts_with.py +0 -0
  132. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/evals/validators/type.py +0 -0
  133. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/guardrails/__init__.py +0 -0
  134. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/guardrails/apply.py +0 -0
  135. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/guardrails/builtins/__init__.py +0 -0
  136. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/guardrails/builtins/injection.py +0 -0
  137. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/guardrails/builtins/judge.py +0 -0
  138. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/guardrails/builtins/keywords.py +0 -0
  139. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/guardrails/builtins/length.py +0 -0
  140. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/guardrails/builtins/moderate.py +0 -0
  141. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/guardrails/builtins/pii.py +0 -0
  142. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/guardrails/builtins/secrets.py +0 -0
  143. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/guardrails/builtins/topic.py +0 -0
  144. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/guardrails/judge_llm.py +0 -0
  145. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/guardrails/presets.py +0 -0
  146. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/guardrails/rubric.py +0 -0
  147. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/guardrails/runner.py +0 -0
  148. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/guardrails/testing.py +0 -0
  149. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/guardrails/trace.py +0 -0
  150. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/guardrails/types.py +0 -0
  151. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/logs.py +0 -0
  152. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/models.yaml +0 -0
  153. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/platform/__init__.py +0 -0
  154. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/platform/_http_session.py +0 -0
  155. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/platform/integrations.py +0 -0
  156. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/platform/knowledge_bases/__init__.py +0 -0
  157. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/platform/knowledge_bases/query.py +0 -0
  158. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/platform/tool_proxy.py +0 -0
  159. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/platform/types.py +0 -0
  160. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/platform/utils.py +0 -0
  161. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/server/__init__.py +0 -0
  162. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/server/__main__.py +0 -0
  163. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/server/capacity.py +0 -0
  164. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/server/jobs.py +0 -0
  165. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/server/livekit_call_control.py +0 -0
  166. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/server/livekit_session.py +0 -0
  167. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/server/livekit_sip.py +0 -0
  168. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/server/playground.py +0 -0
  169. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/server/recording_upload.py +0 -0
  170. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/server/rtc.py +0 -0
  171. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/server/single_session.py +0 -0
  172. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/server/telephony.py +0 -0
  173. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/server/voice.html +0 -0
  174. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/server/voice.py +0 -0
  175. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/state/__init__.py +0 -0
  176. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/state/background.py +0 -0
  177. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/state/config.py +0 -0
  178. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/state/config_loader.py +0 -0
  179. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/state/dependency_analyzer.py +0 -0
  180. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/state/tracing/__init__.py +0 -0
  181. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/state/tracing/exporters/__init__.py +0 -0
  182. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/state/tracing/exporters/otel.py +0 -0
  183. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/state/tracing/providers/__init__.py +0 -0
  184. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/state/tracing/providers/in_memory.py +0 -0
  185. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/state/tracing/providers/jsonl.py +0 -0
  186. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/state/tracing/providers/platform.py +0 -0
  187. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/state/tracing/providers/sqlite.py +0 -0
  188. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/state/tracing/span.py +0 -0
  189. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/state/tracing/trace.py +0 -0
  190. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/tools/__init__.py +0 -0
  191. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/tools/_creds.py +0 -0
  192. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/tools/aircall.py +0 -0
  193. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/tools/asana.py +0 -0
  194. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/tools/bash.py +0 -0
  195. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/tools/cala.py +0 -0
  196. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/tools/cloudflare.py +0 -0
  197. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/tools/connectif.py +0 -0
  198. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/tools/covermanager.py +0 -0
  199. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/tools/deepgram.py +0 -0
  200. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/tools/dynamics_business_central.py +0 -0
  201. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/tools/dynamics_sales.py +0 -0
  202. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/tools/edit.py +0 -0
  203. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/tools/elasticsearch.py +0 -0
  204. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/tools/elevenlabs.py +0 -0
  205. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/tools/excel.py +0 -0
  206. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/tools/fal.py +0 -0
  207. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/tools/fathom.py +0 -0
  208. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/tools/firecrawl.py +0 -0
  209. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/tools/freematica.py +0 -0
  210. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/tools/freematica_contracts.py +0 -0
  211. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/tools/freematica_people.py +0 -0
  212. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/tools/freematica_purchasing.py +0 -0
  213. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/tools/freematica_sales.py +0 -0
  214. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/tools/gemini_images.py +0 -0
  215. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/tools/gmail.py +0 -0
  216. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/tools/google_analytics.py +0 -0
  217. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/tools/google_business.py +0 -0
  218. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/tools/google_calendar.py +0 -0
  219. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/tools/google_docs.py +0 -0
  220. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/tools/google_drive.py +0 -0
  221. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/tools/google_maps.py +0 -0
  222. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/tools/google_merchant_center.py +0 -0
  223. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/tools/google_search_console.py +0 -0
  224. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/tools/google_sheets.py +0 -0
  225. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/tools/happy_scribe.py +0 -0
  226. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/tools/higgsfield.py +0 -0
  227. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/tools/hubspot.py +0 -0
  228. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/tools/interaction.py +0 -0
  229. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/tools/jira.py +0 -0
  230. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/tools/klaviyo.py +0 -0
  231. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/tools/knowledge_base.py +0 -0
  232. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/tools/krea.py +0 -0
  233. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/tools/lancedb.py +0 -0
  234. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/tools/linkedin.py +0 -0
  235. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/tools/mongodb.py +0 -0
  236. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/tools/netsuite.py +0 -0
  237. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/tools/onedrive.py +0 -0
  238. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/tools/openai_audio.py +0 -0
  239. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/tools/outlook.py +0 -0
  240. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/tools/parallel.py +0 -0
  241. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/tools/pinecone.py +0 -0
  242. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/tools/powerbi.py +0 -0
  243. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/tools/quiver_ai.py +0 -0
  244. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/tools/read.py +0 -0
  245. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/tools/replicate.py +0 -0
  246. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/tools/resend.py +0 -0
  247. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/tools/salesforce.py +0 -0
  248. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/tools/scraperapi.py +0 -0
  249. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/tools/sharepoint.py +0 -0
  250. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/tools/shopify.py +0 -0
  251. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/tools/slack.py +0 -0
  252. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/tools/stripe.py +0 -0
  253. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/tools/tavily.py +0 -0
  254. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/tools/web_search.py +0 -0
  255. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/tools/write.py +0 -0
  256. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/tools/xai.py +0 -0
  257. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/tools/zendesk.py +0 -0
  258. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/tools/zoho_crm.py +0 -0
  259. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/types/__init__.py +0 -0
  260. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/types/approval.py +0 -0
  261. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/types/content/__init__.py +0 -0
  262. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/types/content/base.py +0 -0
  263. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/types/content/custom.py +0 -0
  264. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/types/content/file.py +0 -0
  265. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/types/content/text.py +0 -0
  266. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/types/content/thinking.py +0 -0
  267. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/types/content/tool_result.py +0 -0
  268. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/types/events/__init__.py +0 -0
  269. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/types/events/approval.py +0 -0
  270. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/types/events/base.py +0 -0
  271. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/types/events/delta.py +0 -0
  272. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/types/events/guardrail.py +0 -0
  273. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/types/events/interaction.py +0 -0
  274. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/types/events/output.py +0 -0
  275. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/types/events/start.py +0 -0
  276. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/types/file.py +0 -0
  277. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/types/message.py +0 -0
  278. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/types/run_status.py +0 -0
  279. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/utils/__init__.py +0 -0
  280. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/utils/import_spec.py +0 -0
  281. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/utils/model.py +0 -0
  282. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/utils/net.py +0 -0
  283. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/utils/schema.py +0 -0
  284. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/utils/serialization.py +0 -0
  285. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/voice/__init__.py +0 -0
  286. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/voice/_whisper_features.py +0 -0
  287. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/voice/ambience.py +0 -0
  288. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/voice/config.py +0 -0
  289. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/voice/deepgram.py +0 -0
  290. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/voice/deepgram_tts.py +0 -0
  291. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/voice/elevenlabs.py +0 -0
  292. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/voice/endpointing.py +0 -0
  293. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/voice/eou.py +0 -0
  294. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/voice/events.py +0 -0
  295. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/voice/fish_audio.py +0 -0
  296. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/voice/livekit.py +0 -0
  297. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/voice/metrics.py +0 -0
  298. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/voice/munsit.py +0 -0
  299. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/voice/namo.py +0 -0
  300. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/voice/openai.py +0 -0
  301. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/voice/playback.py +0 -0
  302. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/voice/providers.py +0 -0
  303. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/voice/realtime.py +0 -0
  304. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/voice/recording.py +0 -0
  305. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/voice/smart_turn.py +0 -0
  306. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/voice/telephony.py +0 -0
  307. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/voice/turn_detection.py +0 -0
  308. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/voice/vad.py +0 -0
  309. {timbal-2.7.40 → timbal-2.7.41}/python/timbal/voice/webrtc.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: timbal
3
- Version: 2.7.40
3
+ Version: 2.7.41
4
4
  Summary: Simple, performant, battle-tested framework for building reliable AI applications
5
5
  Project-URL: Source, https://github.com/timbal-ai/timbal
6
6
  Author-email: Timbal <team@timbal.ai>
@@ -18,7 +18,7 @@ version_tuple: tuple[int | str, ...]
18
18
  commit_id: str | None
19
19
  __commit_id__: str | None
20
20
 
21
- __version__ = version = '2.7.40'
22
- __version_tuple__ = version_tuple = (2, 7, 40)
21
+ __version__ = version = '2.7.41'
22
+ __version_tuple__ = version_tuple = (2, 7, 41)
23
23
 
24
24
  __commit_id__ = commit_id = None
@@ -1768,6 +1768,7 @@ class Runnable(ABC, BaseModel):
1768
1768
 
1769
1769
  async def _bg_handler_execution():
1770
1770
  token = set_background_depth(depth + 1)
1771
+ run_context._live_background += 1
1771
1772
  record = record_box[0]
1772
1773
  # Ambient emits from the detached child must reach its background
1773
1774
  # log — after detach the only copy of its stream — not the finished
@@ -1800,6 +1801,7 @@ class Runnable(ABC, BaseModel):
1800
1801
  bg_emit_sink.close()
1801
1802
  reset_background_depth(token)
1802
1803
  record.log.close()
1804
+ await run_context._end_background_work()
1803
1805
  return output
1804
1806
 
1805
1807
  task: asyncio.Task | None = None
@@ -1849,6 +1851,7 @@ class Runnable(ABC, BaseModel):
1849
1851
 
1850
1852
  async def _continue_in_background() -> Any:
1851
1853
  token = set_background_depth(depth + 1)
1854
+ run_context._live_background += 1
1852
1855
  output = None
1853
1856
  bg_emit_sink = None
1854
1857
  try:
@@ -1900,8 +1903,10 @@ class Runnable(ABC, BaseModel):
1900
1903
  if bg_emit_sink is not None:
1901
1904
  bg_emit_sink.close()
1902
1905
  span.t1 = int(time.time() * 1000)
1906
+ run_context._live_background -= 1
1903
1907
  try:
1904
- await run_context._save_trace()
1908
+ # The continuation's end: stored before the task finishes, like the end of a root run.
1909
+ await run_context._save_trace(barrier=True)
1905
1910
  finally:
1906
1911
  reset_background_depth(token)
1907
1912
  if record_box:
@@ -2038,6 +2043,13 @@ class Runnable(ABC, BaseModel):
2038
2043
  tracing_provider=self.tracing_provider,
2039
2044
  platform_config=_inherited_platform_config,
2040
2045
  )
2046
+ if _entry_call_id is not None:
2047
+ # Started by a running call's code (an Agent inside a tool or step
2048
+ # body): link the two runs both ways so a trace viewer can follow it.
2049
+ run_context._invoked_by = {"run_id": _entry_run_context.id, "call_id": _entry_call_id}
2050
+ caller_span = _entry_run_context._trace.get(_entry_call_id)
2051
+ if caller_span is not None:
2052
+ caller_span.metadata.setdefault("invoked_runs", []).append(run_context.id)
2041
2053
  # Whether we forked above or kept a caller-provided context whose
2042
2054
  # trace is still empty (e.g. `set_run_context(RunContext(...))`
2043
2055
  # inside a handler, a common platform-bootstrap pattern), the
@@ -2083,12 +2095,15 @@ class Runnable(ABC, BaseModel):
2083
2095
  set_call_id(_new_call_id)
2084
2096
 
2085
2097
  assert _new_call_id not in run_context._trace, f"Call ID {_new_call_id} already exists in trace."
2098
+ metadata = {**self.metadata} # Shallow copy
2099
+ if _new_parent_call_id is None and run_context._invoked_by is not None:
2100
+ metadata["invoked_by"] = run_context._invoked_by
2086
2101
  span = Span(
2087
2102
  path=self._path,
2088
2103
  call_id=_new_call_id,
2089
2104
  parent_call_id=_new_parent_call_id,
2090
2105
  t0=t0,
2091
- metadata={**self.metadata}, # Shallow copy
2106
+ metadata=metadata,
2092
2107
  runnable=self,
2093
2108
  )
2094
2109
  run_context._trace[_new_call_id] = span
@@ -2599,15 +2614,16 @@ class Runnable(ABC, BaseModel):
2599
2614
  output_event._input_dump = span._input_dump
2600
2615
  output_event._output_dump = await dump(handoff_result) if handed_off else span._output_dump
2601
2616
  if handoff_start is None:
2602
- if not await run_context._save_trace():
2603
- # The failure was counted on the span after the event copied its usage.
2604
- output_event.usage = dict(span.usage)
2617
+ # The end of the root run is stored before the caller goes on, even with background work still live.
2618
+ await run_context._save_trace(barrier=span is run_context.root_span())
2619
+ # The save counts on the span (a failure, the tracing counters) after the event copied its usage.
2620
+ output_event.usage = dict(span.usage)
2605
2621
  else:
2606
2622
  # The continuation must not mutate the shared span until the
2607
2623
  # foreground placeholder has been snapshotted for tracing.
2608
2624
  try:
2609
- if not await run_context._save_trace():
2610
- output_event.usage = dict(span.usage)
2625
+ await run_context._save_trace(barrier=True)
2626
+ output_event.usage = dict(span.usage)
2611
2627
  finally:
2612
2628
  handoff_start.set()
2613
2629
  if handoff_control is not None and handoff_result is not None:
@@ -92,6 +92,10 @@ async def lifespan(
92
92
  try:
93
93
  yield
94
94
  finally:
95
+ # Buffered trace saves still pending are stored before the process goes.
96
+ from ..state.tracing.uploads import flush_all
97
+
98
+ await flush_all()
95
99
  if warmup_task is not None and not warmup_task.done():
96
100
  warmup_task.cancel()
97
101
  if livekit_task is not None and not livekit_task.done():
@@ -1,5 +1,6 @@
1
1
  import asyncio
2
2
  import os
3
+ import time
3
4
  from collections import deque
4
5
  from collections.abc import Callable
5
6
  from pathlib import Path
@@ -218,6 +219,11 @@ class RunContext(BaseModel):
218
219
  # suspension_id for a ``suspend()`` call (value is arbitrary).
219
220
  # _used_resume_ids: set — resume ids that matched a gate or ``suspend()``
220
221
  # during this run; used to warn about unrecognized resume values.
222
+ # _invoked_by: dict | None — ``{"run_id", "call_id"}`` of the call whose
223
+ # code started this run (an Agent called inside a tool or step body);
224
+ # stamped on the root span. Not ``parent_id``: that chains turns.
225
+ # _live_background: int — background work (spawned tasks, handed-off
226
+ # continuations) running on this context; it can outlive the root run.
221
227
  # Do not add class-level annotations for them — pydantic would turn any
222
228
  # annotated underscore name back into a (slow) private attribute.
223
229
 
@@ -315,6 +321,8 @@ class RunContext(BaseModel):
315
321
  self._loop: asyncio.AbstractEventLoop | None = None
316
322
  self._resume_values: dict[str, Any] = {}
317
323
  self._used_resume_ids: set[str] = set()
324
+ self._invoked_by: dict[str, str] | None = None
325
+ self._live_background = 0
318
326
  self._trace = Trace()
319
327
  # Inherit the parent session's background-task bag (usually None) so a
320
328
  # finished parent turn can still list/peek/cancel running builders.
@@ -400,7 +408,7 @@ class RunContext(BaseModel):
400
408
  return None
401
409
  return None
402
410
 
403
- async def _save_trace(self) -> bool:
411
+ async def _save_trace(self, *, barrier: bool = False) -> bool:
404
412
  """Save the trace data for the run.
405
413
 
406
414
  INTERNAL METHOD: This method is intended for internal framework use.
@@ -414,8 +422,17 @@ class RunContext(BaseModel):
414
422
  It is logged and counted as ``tracing:save_failed`` in usage.
415
423
  Cancellation still propagates.
416
424
 
425
+ With a buffered provider, a save while the run is still going is
426
+ scheduled instead (:mod:`timbal.state.tracing.uploads`), including
427
+ saves while background work outlives the root run. With an end-only
428
+ provider it is skipped: only barriers store.
429
+ ``barrier=True`` (the end of the root run, a snapshot that must be
430
+ stored before the caller goes on) stores it now, after any upload in
431
+ flight.
432
+
417
433
  Returns:
418
- False when the provider failed to store this snapshot.
434
+ False when the provider failed to store this snapshot. A scheduled
435
+ save returns True; its failures are counted when they happen.
419
436
  """
420
437
  # Sync session data to root span before saving. Skip when the session
421
438
  # was never populated ({} from get_session()) and never synced before —
@@ -426,20 +443,48 @@ class RunContext(BaseModel):
426
443
 
427
444
  root.session = self._session_data
428
445
  root._session_dump = await dump(self._session_data)
429
- if self._tracing_provider is not None:
430
- try:
431
- await self._tracing_provider.put(self)
432
- except Exception as e:
433
- _get_logger().error(
434
- "Trace save failed. The run continues, but this snapshot was not stored...",
435
- run_id=self.id,
436
- parent_id=self.parent_id,
437
- error=str(e),
438
- )
439
- self.update_usage("tracing:save_failed", 1)
440
- return False
446
+ if self._tracing_provider is None:
447
+ return True
448
+ from .tracing import uploads
449
+
450
+ running = root is not None and (root.t1 is None or self._live_background > 0)
451
+ if not barrier and running:
452
+ mode = uploads.durability(self._tracing_provider)
453
+ if mode == "end":
454
+ uploads.count(self, "tracing:saves_coalesced")
455
+ return True
456
+ if mode == "buffered" and uploads.schedule(self):
457
+ return True
458
+ t0 = time.monotonic()
459
+ try:
460
+ await uploads.write_through(self, self._tracing_provider.put)
461
+ except Exception as e:
462
+ _get_logger().error(
463
+ "Trace save failed. The run continues, but this snapshot was not stored...",
464
+ run_id=self.id,
465
+ parent_id=self.parent_id,
466
+ error=str(e),
467
+ )
468
+ self.update_usage("tracing:save_failed", 1)
469
+ return False
470
+ finally:
471
+ uploads.count(self, "tracing:wait_ms", round((time.monotonic() - t0) * 1000))
472
+ uploads.count(self, "tracing:saves")
441
473
  return True
442
474
 
475
+ async def _end_background_work(self) -> None:
476
+ """INTERNAL: one piece of background work on this context finished.
477
+
478
+ After the root run its end is a barrier: what it wrote last (a spawned
479
+ task's real output over its placeholder) and anything buffering left
480
+ pending are stored, and the run's upload state is released. Before
481
+ the root's end, that barrier stores it.
482
+ """
483
+ self._live_background -= 1
484
+ root = self.root_span()
485
+ if root is not None and root.t1 is not None:
486
+ await self._save_trace(barrier=True)
487
+
443
488
  async def get_session(self) -> dict[str, Any]:
444
489
  """Get session data that persists across runs."""
445
490
  if self._session_data is None:
@@ -196,6 +196,20 @@ class TracingProvider(ABC):
196
196
  Runs on span copies — the live run is never mutated. Note that resumed sessions
197
197
  load memory from stored traces, so chained turns see the redacted history."""
198
198
 
199
+ durability: str | None = None
200
+ """``"sync"``: every save is awaited (the default). ``"buffered"``: a save while the run is still going
201
+ is stored in the background, coalesced, and the run waits only at its end and at other barriers (see
202
+ :mod:`timbal.state.tracing.uploads`). ``"end"``: saves while the run is going are skipped; only its end
203
+ and other barriers store. ``None`` reads ``TIMBAL_TRACE_DURABILITY``."""
204
+
205
+ flush_interval_s: float | None = None
206
+ """Buffered mode: the least time between the starts of two background saves of one run. ``None`` reads
207
+ ``TIMBAL_TRACE_FLUSH_INTERVAL_MS``, else 0.5 s."""
208
+
209
+ max_lag_s: float | None = None
210
+ """Buffered mode: how old a run's oldest unsaved change may get before its saves are awaited again
211
+ (uploads failing or falling behind). ``None`` reads ``TIMBAL_TRACE_MAX_LAG_S``, else 30 s."""
212
+
199
213
  @classmethod
200
214
  def configured(cls, **kwargs) -> type["TracingProvider"]:
201
215
  """Return a configured subclass with the given class-level attributes.
@@ -0,0 +1,288 @@
1
+ """Buffered trace persistence: mid-run snapshots are stored in the background, one per run at a time.
2
+
3
+ A run saves its whole trace each time a span finishes. With ``durability="buffered"`` a save while the run
4
+ is still going is scheduled instead of awaited: the run moves on, the provider stores the run's latest
5
+ state once the flush interval since its previous save has passed, and saves requested meanwhile fold into
6
+ that one. Barriers (:func:`write_through`) store synchronously: the end of the root run (including a run
7
+ suspended for approval), a foreground task handed to the background, the end of that background
8
+ continuation, and shutdown (:func:`flush_all`). A run has one write at a time, background or barrier, so a
9
+ write that starts later stores a newer snapshot; a barrier waits for an upload in flight, never for a retry
10
+ backoff.
11
+ Background work that outlives the root run saves the same way: scheduled while it runs, and each piece's
12
+ end is a barrier.
13
+
14
+ The live trace is the buffer, so memory does not grow with pending changes; what grows is the lag, the age
15
+ of the oldest change not yet stored. A run whose uploads fail or fall behind by more than ``max_lag_s``
16
+ goes back to synchronous saves until one succeeds: the state may be the only copy, so it is retried, never
17
+ dropped. Before returning, a run with pending changes stores them at its end barrier; a crash in between
18
+ loses at most the lag.
19
+
20
+ ``durability="end"`` skips mid-run saves altogether: only the barriers store. It suits runs nobody reads
21
+ while they run and that are resumed from their end, such as a subagent or a builder whose progress its caller
22
+ already streams: their traces carry the whole message history, so each mid-run save resends megabytes. A crash
23
+ loses everything since the last barrier.
24
+
25
+ Configure per provider (``Provider.configured(durability="buffered", flush_interval_s=0.5)``) or through
26
+ ``TIMBAL_TRACE_DURABILITY``, ``TIMBAL_TRACE_FLUSH_INTERVAL_MS`` and ``TIMBAL_TRACE_MAX_LAG_S``.
27
+ """
28
+
29
+ from __future__ import annotations
30
+
31
+ import asyncio
32
+ import os
33
+ import time
34
+ from collections.abc import Awaitable, Callable
35
+ from typing import TYPE_CHECKING, Any
36
+
37
+ import structlog
38
+
39
+ if TYPE_CHECKING:
40
+ from ..context import RunContext
41
+ from .providers.base import TracingProvider
42
+
43
+ logger = structlog.get_logger("timbal.state.tracing.uploads")
44
+
45
+ DURABILITY_ENV = "TIMBAL_TRACE_DURABILITY"
46
+ FLUSH_INTERVAL_ENV = "TIMBAL_TRACE_FLUSH_INTERVAL_MS"
47
+ MAX_LAG_ENV = "TIMBAL_TRACE_MAX_LAG_S"
48
+ METRICS_ENV = "TIMBAL_TRACE_METRICS"
49
+ DEFAULT_FLUSH_INTERVAL_S = 0.5
50
+ DEFAULT_MAX_LAG_S = 30.0
51
+ MAX_BACKOFF_S = 30.0
52
+
53
+
54
+ def _env_float(name: str, scale: float = 1.0) -> float | None:
55
+ raw = os.environ.get(name)
56
+ if not raw:
57
+ return None
58
+ try:
59
+ return float(raw) * scale
60
+ except ValueError:
61
+ logger.warning("trace_upload_setting_invalid", setting=name, value=raw)
62
+ return None
63
+
64
+
65
+ def durability(provider: type[TracingProvider]) -> str:
66
+ """``sync`` (the default, and any value it does not know), ``buffered`` or ``end``."""
67
+ mode = (getattr(provider, "durability", None) or os.environ.get(DURABILITY_ENV) or "sync").strip().lower()
68
+ return mode if mode in ("buffered", "end") else "sync"
69
+
70
+
71
+ def buffered(provider: type[TracingProvider]) -> bool:
72
+ return durability(provider) == "buffered"
73
+
74
+
75
+ def metrics_on(provider: type[TracingProvider]) -> bool:
76
+ """Counters go into usage only when asked: they are new usage keys for every run."""
77
+ return durability(provider) != "sync" or os.environ.get(METRICS_ENV, "").strip().lower() in ("1", "true", "yes")
78
+
79
+
80
+ def _flush_interval(provider: type[TracingProvider]) -> float:
81
+ value = getattr(provider, "flush_interval_s", None)
82
+ if value is None:
83
+ value = _env_float(FLUSH_INTERVAL_ENV, 0.001)
84
+ return max(0.0, DEFAULT_FLUSH_INTERVAL_S if value is None else value)
85
+
86
+
87
+ def _max_lag(provider: type[TracingProvider]) -> float:
88
+ value = getattr(provider, "max_lag_s", None)
89
+ if value is None:
90
+ value = _env_float(MAX_LAG_ENV)
91
+ return DEFAULT_MAX_LAG_S if value is None else value
92
+
93
+
94
+ def count(run_context: RunContext, key: str, value: int = 1) -> None:
95
+ if value and metrics_on(run_context._tracing_provider):
96
+ run_context.update_usage(key, int(value))
97
+
98
+
99
+ class _RunUploads:
100
+ __slots__ = (
101
+ "context", "provider", "task", "pending", "sending", "started_at", "unsent_since", "failures",
102
+ "lock", "requests", "writers",
103
+ ) # fmt: skip
104
+
105
+ def __init__(self, context: RunContext, provider: type[TracingProvider]) -> None:
106
+ self.context = context
107
+ self.provider = provider
108
+ self.task: asyncio.Task | None = None
109
+ # A change no save has picked up yet, and when the oldest such change happened.
110
+ self.pending = False
111
+ self.unsent_since: float | None = None
112
+ self.sending = False
113
+ self.started_at = float("-inf")
114
+ self.failures = 0
115
+ # One write per run at a time, background upload or barrier: a write that starts later stores a
116
+ # newer snapshot, so an older one never lands over it.
117
+ self.lock = asyncio.Lock()
118
+ # Saves requested so far; a write that starts after the n-th one covers it.
119
+ self.requests = 0
120
+ # Barrier writes holding or waiting for the lock.
121
+ self.writers = 0
122
+
123
+
124
+ _RUNS: dict[tuple[int, str], _RunUploads] = {}
125
+
126
+
127
+ def _key(run_context: RunContext) -> tuple[int, str]:
128
+ return id(run_context._tracing_provider), run_context.id
129
+
130
+
131
+ def schedule(run_context: RunContext) -> bool:
132
+ """Defer this mid-run save. False: the run is too far behind, and the caller saves synchronously."""
133
+ provider = run_context._tracing_provider
134
+ loop = asyncio.get_running_loop()
135
+ run = _RUNS.get(_key(run_context))
136
+ if run is None:
137
+ run = _RUNS[_key(run_context)] = _RunUploads(run_context, provider)
138
+ now = loop.time()
139
+ if run.unsent_since is not None and now - run.unsent_since > _max_lag(provider):
140
+ count(run_context, "tracing:lag_exceeded")
141
+ return False
142
+ run.requests += 1
143
+ if run.pending:
144
+ count(run_context, "tracing:saves_coalesced")
145
+ else:
146
+ run.pending = True
147
+ if run.unsent_since is None:
148
+ run.unsent_since = now
149
+ if run.task is None or run.task.done():
150
+ run.task = loop.create_task(_drain(run))
151
+ return True
152
+
153
+
154
+ def tracked(run_context: RunContext) -> bool:
155
+ """Whether buffered saves of this run have state here (a save pending, in flight, or spacing out)."""
156
+ return _key(run_context) in _RUNS
157
+
158
+
159
+ async def write_through(run_context: RunContext, put: Callable[[Any], Awaitable[None]]) -> None:
160
+ """Store the run's latest state now, as its next write (a barrier).
161
+
162
+ It waits for an upload in flight or another barrier's write (the root's end and a background task's end
163
+ can overlap), never for a drain waiting out its interval or a retry backoff; saves requested while it
164
+ writes are uploaded after it; what it covers is not uploaded again. Raises what ``put`` raises.
165
+ """
166
+ key = _key(run_context)
167
+ run = _RUNS.get(key)
168
+ if run is None:
169
+ if durability(run_context._tracing_provider) == "sync":
170
+ await put(run_context)
171
+ return
172
+ run = _RUNS[key] = _RunUploads(run_context, run_context._tracing_provider)
173
+ run.writers += 1
174
+ try:
175
+ async with run.lock:
176
+ covered = run.requests
177
+ await put(run_context)
178
+ if run.requests == covered:
179
+ run.pending, run.unsent_since, run.failures = False, None, 0
180
+ finally:
181
+ run.writers -= 1
182
+ _release(run)
183
+
184
+
185
+ def _release(run: _RunUploads, *, draining: bool = False) -> None:
186
+ """Drop a run with nothing left to store, and its drain.
187
+
188
+ After a barrier's write the drain cannot be uploading (the barrier held the lock after it): it is waiting
189
+ out an interval or backoff, or queued for the lock, so cancelling it interrupts no write. ``draining``:
190
+ the drain itself is exiting.
191
+ """
192
+ key = _key(run.context)
193
+ if run.pending or run.writers or run.sending or _RUNS.get(key) is not run:
194
+ return
195
+ if not draining and run.task is not None and not run.task.done():
196
+ run.task.cancel()
197
+ del _RUNS[key]
198
+
199
+
200
+ def _finished(run_context: RunContext) -> bool:
201
+ """The root run has ended and no background work is left on it: nothing will save it again."""
202
+ root = run_context.root_span()
203
+ return root is not None and root.t1 is not None and run_context._live_background == 0
204
+
205
+
206
+ async def flush_all(timeout: float | None = 10.0) -> None:
207
+ """Store every buffered run's latest state now (process shutdown)."""
208
+ runs = list(_RUNS.values())
209
+
210
+ async def flush(run: _RunUploads) -> None:
211
+ try:
212
+ await write_through(run.context, run.provider.put)
213
+ except Exception as e:
214
+ logger.error("trace_flush_failed", run_id=run.context.id, error=str(e))
215
+
216
+ if runs:
217
+ try:
218
+ await asyncio.wait_for(asyncio.gather(*map(flush, runs)), timeout)
219
+ except TimeoutError:
220
+ logger.error("trace_flush_timed_out", runs=[run.context.id for run in runs], timeout_s=timeout)
221
+
222
+
223
+ async def _drain(run: _RunUploads) -> None:
224
+ try:
225
+ await _upload_while_pending(run)
226
+ finally:
227
+ # Nothing saves a finished run again: once its last change is stored (the retry of a failed end
228
+ # barrier, or the upload a cancelled one was waiting on), let it go.
229
+ if _finished(run.context):
230
+ _release(run, draining=True)
231
+
232
+
233
+ async def _upload_while_pending(run: _RunUploads) -> None:
234
+ loop = asyncio.get_running_loop()
235
+ key = _key(run.context)
236
+ interval = _flush_interval(run.provider)
237
+ while run.pending:
238
+ backoff = min(MAX_BACKOFF_S, interval * (2**run.failures)) if run.failures else interval
239
+ wait = run.started_at + backoff - loop.time()
240
+ if wait > 0:
241
+ await asyncio.sleep(wait)
242
+ if _RUNS.get(key) is not run:
243
+ return
244
+ async with run.lock:
245
+ # A barrier may have stored it meanwhile.
246
+ if not run.pending:
247
+ break
248
+ # One is waiting: it stores the latest state, then this re-checks what is still pending.
249
+ if run.writers:
250
+ continue
251
+ covered_since = run.unsent_since
252
+ run.pending, run.unsent_since = False, None
253
+ run.sending, run.started_at = True, loop.time()
254
+ t0 = time.monotonic()
255
+ try:
256
+ await run.provider.put(run.context)
257
+ except Exception as e:
258
+ # The state may be the only copy: retry it, with backoff, until a save or a barrier stores it.
259
+ run.failures += 1
260
+ run.pending = True
261
+ if covered_since is not None:
262
+ run.unsent_since = (
263
+ covered_since if run.unsent_since is None else min(run.unsent_since, covered_since)
264
+ )
265
+ logger.error(
266
+ "Background trace save failed. Retrying...",
267
+ run_id=run.context.id,
268
+ failures=run.failures,
269
+ error=str(e),
270
+ )
271
+ count(run.context, "tracing:save_failed")
272
+ else:
273
+ run.failures = 0
274
+ count(run.context, "tracing:saves")
275
+ finally:
276
+ run.sending = False
277
+ count(run.context, "tracing:save_ms", round((time.monotonic() - t0) * 1000))
278
+
279
+
280
+ def pending_runs() -> list[str]:
281
+ """Run ids with buffered state not yet stored (diagnostics and tests)."""
282
+ return [run.context.id for run in _RUNS.values() if run.pending or run.sending]
283
+
284
+
285
+ def _reset_for_tests() -> dict[Any, Any]:
286
+ previous = dict(_RUNS)
287
+ _RUNS.clear()
288
+ return previous
@@ -13,6 +13,21 @@ from ...utils import coerce_to_dict
13
13
  from .base import BaseContent
14
14
 
15
15
 
16
+ def canonical_input(value: Any) -> Any:
17
+ """``value`` with every object's keys sorted, recursively.
18
+
19
+ A replayed tool input must render the same on every request: storage (e.g. Postgres
20
+ ``jsonb``) does not keep the model's key order, and an input whose keys come back reordered
21
+ breaks the provider's prompt cache from that block on (and, on Claude 5.5 models, the
22
+ prefix binding of every later thinking block).
23
+ """
24
+ if isinstance(value, dict):
25
+ return {key: canonical_input(value[key]) for key in sorted(value)}
26
+ if isinstance(value, list):
27
+ return [canonical_input(item) for item in value]
28
+ return value
29
+
30
+
16
31
  class ToolUseContent(BaseContent):
17
32
  """Tool use content type for chat messages."""
18
33
 
@@ -40,7 +55,7 @@ class ToolUseContent(BaseContent):
40
55
  "call_id": self.id,
41
56
  "type": "function_call",
42
57
  "name": self.name,
43
- "arguments": json.dumps(self.input),
58
+ "arguments": json.dumps(self.input, sort_keys=True),
44
59
  }
45
60
 
46
61
  @override
@@ -49,7 +64,11 @@ class ToolUseContent(BaseContent):
49
64
  if self.is_server_tool_use:
50
65
  return None # see to_openai_responses_input
51
66
 
52
- data = {"id": self.id, "type": "function", "function": {"arguments": json.dumps(self.input), "name": self.name}}
67
+ data = {
68
+ "id": self.id,
69
+ "type": "function",
70
+ "function": {"arguments": json.dumps(self.input, sort_keys=True), "name": self.name},
71
+ }
53
72
 
54
73
  if self.thought_signature:
55
74
  data["extra_content"] = {"google": {"thought_signature": self.thought_signature}}
@@ -63,5 +82,5 @@ class ToolUseContent(BaseContent):
63
82
  "type": "tool_use" if not self.is_server_tool_use else "server_tool_use",
64
83
  "id": self.id,
65
84
  "name": self.name,
66
- "input": self.input,
85
+ "input": canonical_input(self.input),
67
86
  }
@@ -3077,7 +3077,9 @@ class VoiceSession:
3077
3077
  # turn's own truncation owns the field.
3078
3078
  was_newest = index == len(self._transcript) - 1
3079
3079
  if heard:
3080
- self._greeting_entry = TranscriptEntry(role="assistant", text=heard)
3080
+ self._greeting_entry = TranscriptEntry(
3081
+ role="assistant", text=heard, timestamp=self._greeting_entry.timestamp
3082
+ )
3081
3083
  self._transcript[index] = self._greeting_entry
3082
3084
  else:
3083
3085
  self._transcript.pop(index)
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes