mirascope 2.0.0a6__py3-none-any.whl → 2.0.1__py3-none-any.whl

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 (226) hide show
  1. mirascope/api/_generated/__init__.py +186 -5
  2. mirascope/api/_generated/annotations/client.py +38 -6
  3. mirascope/api/_generated/annotations/raw_client.py +366 -47
  4. mirascope/api/_generated/annotations/types/annotations_create_response.py +19 -6
  5. mirascope/api/_generated/annotations/types/annotations_get_response.py +19 -6
  6. mirascope/api/_generated/annotations/types/annotations_list_response_annotations_item.py +22 -7
  7. mirascope/api/_generated/annotations/types/annotations_update_response.py +19 -6
  8. mirascope/api/_generated/api_keys/__init__.py +12 -2
  9. mirascope/api/_generated/api_keys/client.py +107 -6
  10. mirascope/api/_generated/api_keys/raw_client.py +486 -38
  11. mirascope/api/_generated/api_keys/types/__init__.py +7 -1
  12. mirascope/api/_generated/api_keys/types/api_keys_list_all_for_org_response_item.py +40 -0
  13. mirascope/api/_generated/client.py +36 -0
  14. mirascope/api/_generated/docs/raw_client.py +71 -9
  15. mirascope/api/_generated/environment.py +3 -3
  16. mirascope/api/_generated/environments/__init__.py +6 -0
  17. mirascope/api/_generated/environments/client.py +158 -9
  18. mirascope/api/_generated/environments/raw_client.py +620 -52
  19. mirascope/api/_generated/environments/types/__init__.py +10 -0
  20. mirascope/api/_generated/environments/types/environments_get_analytics_response.py +60 -0
  21. mirascope/api/_generated/environments/types/environments_get_analytics_response_top_functions_item.py +24 -0
  22. mirascope/api/_generated/{organizations/types/organizations_credits_response.py → environments/types/environments_get_analytics_response_top_models_item.py} +6 -3
  23. mirascope/api/_generated/errors/__init__.py +6 -0
  24. mirascope/api/_generated/errors/bad_request_error.py +5 -2
  25. mirascope/api/_generated/errors/conflict_error.py +5 -2
  26. mirascope/api/_generated/errors/payment_required_error.py +15 -0
  27. mirascope/api/_generated/errors/service_unavailable_error.py +14 -0
  28. mirascope/api/_generated/errors/too_many_requests_error.py +15 -0
  29. mirascope/api/_generated/functions/__init__.py +10 -0
  30. mirascope/api/_generated/functions/client.py +222 -8
  31. mirascope/api/_generated/functions/raw_client.py +975 -134
  32. mirascope/api/_generated/functions/types/__init__.py +28 -4
  33. mirascope/api/_generated/functions/types/functions_get_by_env_response.py +53 -0
  34. mirascope/api/_generated/functions/types/functions_get_by_env_response_dependencies_value.py +22 -0
  35. mirascope/api/_generated/functions/types/functions_list_by_env_response.py +25 -0
  36. mirascope/api/_generated/functions/types/functions_list_by_env_response_functions_item.py +56 -0
  37. mirascope/api/_generated/functions/types/functions_list_by_env_response_functions_item_dependencies_value.py +22 -0
  38. mirascope/api/_generated/health/raw_client.py +74 -10
  39. mirascope/api/_generated/organization_invitations/__init__.py +33 -0
  40. mirascope/api/_generated/organization_invitations/client.py +546 -0
  41. mirascope/api/_generated/organization_invitations/raw_client.py +1519 -0
  42. mirascope/api/_generated/organization_invitations/types/__init__.py +53 -0
  43. mirascope/api/_generated/organization_invitations/types/organization_invitations_accept_response.py +34 -0
  44. mirascope/api/_generated/organization_invitations/types/organization_invitations_accept_response_role.py +7 -0
  45. mirascope/api/_generated/organization_invitations/types/organization_invitations_create_request_role.py +7 -0
  46. mirascope/api/_generated/organization_invitations/types/organization_invitations_create_response.py +48 -0
  47. mirascope/api/_generated/organization_invitations/types/organization_invitations_create_response_role.py +7 -0
  48. mirascope/api/_generated/organization_invitations/types/organization_invitations_create_response_status.py +7 -0
  49. mirascope/api/_generated/organization_invitations/types/organization_invitations_get_response.py +48 -0
  50. mirascope/api/_generated/organization_invitations/types/organization_invitations_get_response_role.py +7 -0
  51. mirascope/api/_generated/organization_invitations/types/organization_invitations_get_response_status.py +7 -0
  52. mirascope/api/_generated/organization_invitations/types/organization_invitations_list_response_item.py +48 -0
  53. mirascope/api/_generated/organization_invitations/types/organization_invitations_list_response_item_role.py +7 -0
  54. mirascope/api/_generated/organization_invitations/types/organization_invitations_list_response_item_status.py +7 -0
  55. mirascope/api/_generated/organization_memberships/__init__.py +19 -0
  56. mirascope/api/_generated/organization_memberships/client.py +302 -0
  57. mirascope/api/_generated/organization_memberships/raw_client.py +736 -0
  58. mirascope/api/_generated/organization_memberships/types/__init__.py +27 -0
  59. mirascope/api/_generated/organization_memberships/types/organization_memberships_list_response_item.py +33 -0
  60. mirascope/api/_generated/organization_memberships/types/organization_memberships_list_response_item_role.py +7 -0
  61. mirascope/api/_generated/organization_memberships/types/organization_memberships_update_request_role.py +7 -0
  62. mirascope/api/_generated/organization_memberships/types/organization_memberships_update_response.py +31 -0
  63. mirascope/api/_generated/organization_memberships/types/organization_memberships_update_response_role.py +7 -0
  64. mirascope/api/_generated/organizations/__init__.py +26 -2
  65. mirascope/api/_generated/organizations/client.py +442 -20
  66. mirascope/api/_generated/organizations/raw_client.py +1763 -164
  67. mirascope/api/_generated/organizations/types/__init__.py +48 -2
  68. mirascope/api/_generated/organizations/types/organizations_create_payment_intent_response.py +24 -0
  69. mirascope/api/_generated/organizations/types/organizations_preview_subscription_change_request_target_plan.py +7 -0
  70. mirascope/api/_generated/organizations/types/organizations_preview_subscription_change_response.py +47 -0
  71. mirascope/api/_generated/organizations/types/organizations_preview_subscription_change_response_validation_errors_item.py +33 -0
  72. mirascope/api/_generated/organizations/types/organizations_preview_subscription_change_response_validation_errors_item_resource.py +7 -0
  73. mirascope/api/_generated/organizations/types/organizations_router_balance_response.py +24 -0
  74. mirascope/api/_generated/organizations/types/organizations_subscription_response.py +53 -0
  75. mirascope/api/_generated/organizations/types/organizations_subscription_response_current_plan.py +7 -0
  76. mirascope/api/_generated/organizations/types/organizations_subscription_response_payment_method.py +26 -0
  77. mirascope/api/_generated/organizations/types/organizations_subscription_response_scheduled_change.py +34 -0
  78. mirascope/api/_generated/organizations/types/organizations_subscription_response_scheduled_change_target_plan.py +7 -0
  79. mirascope/api/_generated/organizations/types/organizations_update_subscription_request_target_plan.py +7 -0
  80. mirascope/api/_generated/organizations/types/organizations_update_subscription_response.py +35 -0
  81. mirascope/api/_generated/project_memberships/__init__.py +25 -0
  82. mirascope/api/_generated/project_memberships/client.py +437 -0
  83. mirascope/api/_generated/project_memberships/raw_client.py +1039 -0
  84. mirascope/api/_generated/project_memberships/types/__init__.py +29 -0
  85. mirascope/api/_generated/project_memberships/types/project_memberships_create_request_role.py +7 -0
  86. mirascope/api/_generated/project_memberships/types/project_memberships_create_response.py +35 -0
  87. mirascope/api/_generated/project_memberships/types/project_memberships_create_response_role.py +7 -0
  88. mirascope/api/_generated/project_memberships/types/project_memberships_list_response_item.py +33 -0
  89. mirascope/api/_generated/project_memberships/types/project_memberships_list_response_item_role.py +7 -0
  90. mirascope/api/_generated/project_memberships/types/project_memberships_update_request_role.py +7 -0
  91. mirascope/api/_generated/project_memberships/types/project_memberships_update_response.py +35 -0
  92. mirascope/api/_generated/project_memberships/types/project_memberships_update_response_role.py +7 -0
  93. mirascope/api/_generated/projects/raw_client.py +415 -58
  94. mirascope/api/_generated/reference.md +2767 -397
  95. mirascope/api/_generated/tags/__init__.py +19 -0
  96. mirascope/api/_generated/tags/client.py +504 -0
  97. mirascope/api/_generated/tags/raw_client.py +1288 -0
  98. mirascope/api/_generated/tags/types/__init__.py +17 -0
  99. mirascope/api/_generated/tags/types/tags_create_response.py +41 -0
  100. mirascope/api/_generated/tags/types/tags_get_response.py +41 -0
  101. mirascope/api/_generated/tags/types/tags_list_response.py +23 -0
  102. mirascope/api/_generated/tags/types/tags_list_response_tags_item.py +41 -0
  103. mirascope/api/_generated/tags/types/tags_update_response.py +41 -0
  104. mirascope/api/_generated/token_cost/__init__.py +7 -0
  105. mirascope/api/_generated/token_cost/client.py +160 -0
  106. mirascope/api/_generated/token_cost/raw_client.py +264 -0
  107. mirascope/api/_generated/token_cost/types/__init__.py +8 -0
  108. mirascope/api/_generated/token_cost/types/token_cost_calculate_request_usage.py +54 -0
  109. mirascope/api/_generated/token_cost/types/token_cost_calculate_response.py +52 -0
  110. mirascope/api/_generated/traces/__init__.py +20 -0
  111. mirascope/api/_generated/traces/client.py +543 -0
  112. mirascope/api/_generated/traces/raw_client.py +1366 -96
  113. mirascope/api/_generated/traces/types/__init__.py +28 -0
  114. mirascope/api/_generated/traces/types/traces_get_analytics_summary_response.py +6 -0
  115. mirascope/api/_generated/traces/types/traces_get_trace_detail_by_env_response.py +33 -0
  116. mirascope/api/_generated/traces/types/traces_get_trace_detail_by_env_response_spans_item.py +88 -0
  117. mirascope/api/_generated/traces/types/traces_get_trace_detail_response_spans_item.py +0 -2
  118. mirascope/api/_generated/traces/types/traces_list_by_function_hash_response.py +25 -0
  119. mirascope/api/_generated/traces/types/traces_list_by_function_hash_response_traces_item.py +44 -0
  120. mirascope/api/_generated/traces/types/traces_search_by_env_request_attribute_filters_item.py +26 -0
  121. mirascope/api/_generated/traces/types/traces_search_by_env_request_attribute_filters_item_operator.py +7 -0
  122. mirascope/api/_generated/traces/types/traces_search_by_env_request_sort_by.py +7 -0
  123. mirascope/api/_generated/traces/types/traces_search_by_env_request_sort_order.py +7 -0
  124. mirascope/api/_generated/traces/types/traces_search_by_env_response.py +26 -0
  125. mirascope/api/_generated/traces/types/traces_search_by_env_response_spans_item.py +50 -0
  126. mirascope/api/_generated/traces/types/traces_search_response_spans_item.py +10 -1
  127. mirascope/api/_generated/types/__init__.py +32 -2
  128. mirascope/api/_generated/types/bad_request_error_body.py +50 -0
  129. mirascope/api/_generated/types/date.py +3 -0
  130. mirascope/api/_generated/types/immutable_resource_error.py +22 -0
  131. mirascope/api/_generated/types/internal_server_error_body.py +3 -3
  132. mirascope/api/_generated/types/plan_limit_exceeded_error.py +32 -0
  133. mirascope/api/_generated/types/plan_limit_exceeded_error_tag.py +7 -0
  134. mirascope/api/_generated/types/pricing_unavailable_error.py +23 -0
  135. mirascope/api/_generated/types/rate_limit_error.py +31 -0
  136. mirascope/api/_generated/types/rate_limit_error_tag.py +5 -0
  137. mirascope/api/_generated/types/service_unavailable_error_body.py +24 -0
  138. mirascope/api/_generated/types/service_unavailable_error_tag.py +7 -0
  139. mirascope/api/_generated/types/subscription_past_due_error.py +31 -0
  140. mirascope/api/_generated/types/subscription_past_due_error_tag.py +7 -0
  141. mirascope/api/settings.py +19 -1
  142. mirascope/llm/__init__.py +53 -10
  143. mirascope/llm/calls/__init__.py +2 -1
  144. mirascope/llm/calls/calls.py +3 -1
  145. mirascope/llm/calls/decorator.py +21 -7
  146. mirascope/llm/content/tool_output.py +22 -5
  147. mirascope/llm/exceptions.py +284 -71
  148. mirascope/llm/formatting/__init__.py +17 -0
  149. mirascope/llm/formatting/format.py +112 -35
  150. mirascope/llm/formatting/output_parser.py +178 -0
  151. mirascope/llm/formatting/partial.py +80 -7
  152. mirascope/llm/formatting/primitives.py +192 -0
  153. mirascope/llm/formatting/types.py +20 -8
  154. mirascope/llm/messages/__init__.py +3 -0
  155. mirascope/llm/messages/_utils.py +34 -0
  156. mirascope/llm/models/__init__.py +5 -0
  157. mirascope/llm/models/models.py +137 -69
  158. mirascope/llm/{providers/base → models}/params.py +7 -57
  159. mirascope/llm/models/thinking_config.py +61 -0
  160. mirascope/llm/prompts/_utils.py +0 -32
  161. mirascope/llm/prompts/decorator.py +16 -5
  162. mirascope/llm/prompts/prompts.py +131 -68
  163. mirascope/llm/providers/__init__.py +1 -4
  164. mirascope/llm/providers/anthropic/_utils/__init__.py +2 -0
  165. mirascope/llm/providers/anthropic/_utils/beta_decode.py +18 -9
  166. mirascope/llm/providers/anthropic/_utils/beta_encode.py +62 -13
  167. mirascope/llm/providers/anthropic/_utils/decode.py +18 -9
  168. mirascope/llm/providers/anthropic/_utils/encode.py +26 -7
  169. mirascope/llm/providers/anthropic/_utils/errors.py +2 -2
  170. mirascope/llm/providers/anthropic/beta_provider.py +64 -18
  171. mirascope/llm/providers/anthropic/provider.py +91 -33
  172. mirascope/llm/providers/base/__init__.py +0 -4
  173. mirascope/llm/providers/base/_utils.py +55 -6
  174. mirascope/llm/providers/base/base_provider.py +116 -37
  175. mirascope/llm/providers/google/_utils/__init__.py +2 -0
  176. mirascope/llm/providers/google/_utils/decode.py +20 -7
  177. mirascope/llm/providers/google/_utils/encode.py +26 -7
  178. mirascope/llm/providers/google/_utils/errors.py +3 -2
  179. mirascope/llm/providers/google/provider.py +64 -18
  180. mirascope/llm/providers/mirascope/_utils.py +13 -17
  181. mirascope/llm/providers/mirascope/provider.py +49 -18
  182. mirascope/llm/providers/mlx/_utils.py +7 -2
  183. mirascope/llm/providers/mlx/encoding/base.py +5 -2
  184. mirascope/llm/providers/mlx/encoding/transformers.py +5 -2
  185. mirascope/llm/providers/mlx/mlx.py +23 -6
  186. mirascope/llm/providers/mlx/provider.py +42 -13
  187. mirascope/llm/providers/openai/_utils/errors.py +2 -2
  188. mirascope/llm/providers/openai/completions/_utils/encode.py +20 -16
  189. mirascope/llm/providers/openai/completions/base_provider.py +40 -11
  190. mirascope/llm/providers/openai/provider.py +40 -10
  191. mirascope/llm/providers/openai/responses/_utils/__init__.py +2 -0
  192. mirascope/llm/providers/openai/responses/_utils/decode.py +19 -6
  193. mirascope/llm/providers/openai/responses/_utils/encode.py +22 -10
  194. mirascope/llm/providers/openai/responses/provider.py +56 -18
  195. mirascope/llm/providers/provider_registry.py +93 -19
  196. mirascope/llm/responses/__init__.py +6 -1
  197. mirascope/llm/responses/_utils.py +102 -12
  198. mirascope/llm/responses/base_response.py +5 -2
  199. mirascope/llm/responses/base_stream_response.py +115 -25
  200. mirascope/llm/responses/response.py +2 -1
  201. mirascope/llm/responses/root_response.py +89 -17
  202. mirascope/llm/responses/stream_response.py +6 -9
  203. mirascope/llm/tools/decorator.py +9 -4
  204. mirascope/llm/tools/tool_schema.py +12 -6
  205. mirascope/llm/tools/toolkit.py +35 -27
  206. mirascope/llm/tools/tools.py +45 -20
  207. mirascope/ops/__init__.py +4 -0
  208. mirascope/ops/_internal/configuration.py +82 -31
  209. mirascope/ops/_internal/exporters/exporters.py +64 -11
  210. mirascope/ops/_internal/instrumentation/llm/common.py +530 -0
  211. mirascope/ops/_internal/instrumentation/llm/cost.py +190 -0
  212. mirascope/ops/_internal/instrumentation/llm/encode.py +1 -1
  213. mirascope/ops/_internal/instrumentation/llm/llm.py +116 -1242
  214. mirascope/ops/_internal/instrumentation/llm/model.py +1798 -0
  215. mirascope/ops/_internal/instrumentation/llm/response.py +521 -0
  216. mirascope/ops/_internal/instrumentation/llm/serialize.py +300 -0
  217. mirascope/ops/_internal/protocols.py +83 -1
  218. mirascope/ops/_internal/traced_calls.py +4 -0
  219. mirascope/ops/_internal/traced_functions.py +118 -8
  220. mirascope/ops/_internal/tracing.py +78 -1
  221. mirascope/ops/_internal/utils.py +52 -4
  222. {mirascope-2.0.0a6.dist-info → mirascope-2.0.1.dist-info}/METADATA +12 -11
  223. mirascope-2.0.1.dist-info/RECORD +423 -0
  224. {mirascope-2.0.0a6.dist-info → mirascope-2.0.1.dist-info}/licenses/LICENSE +1 -1
  225. mirascope-2.0.0a6.dist-info/RECORD +0 -316
  226. {mirascope-2.0.0a6.dist-info → mirascope-2.0.1.dist-info}/WHEEL +0 -0
@@ -1,58 +1,8 @@
1
1
  """Base parameters for LLM providers."""
2
2
 
3
- from typing import Literal, TypedDict
4
- from typing_extensions import Required
3
+ from typing import TypedDict
5
4
 
6
- ThinkingLevel = Literal["none", "default", "minimal", "low", "medium", "high", "max"]
7
- """Level of effort/reasoning to apply to thinking."""
8
-
9
-
10
- class ThinkingConfig(TypedDict, total=False):
11
- """Configuration for extended reasoning/thinking in LLM responses.
12
-
13
- Thinking is a process where the model spends additional tokens reasoning about
14
- the prompt before generating a response. Providing any `ThinkingConfig` will enable
15
- thinking (unless it is specifically disabled via level="minimal"). Depending on
16
- the provider and model, thinking may always be active regardless of user settings.
17
- """
18
-
19
- level: Required[ThinkingLevel]
20
- """Level of effort/reasoning to apply to thinking.
21
-
22
- - none: Disable thinking entirely. Minimizes cost and latency.
23
- - default: Use the provider's default
24
- - minimal: Use the provider's lowest setting for reasoning
25
- - medium: Use a moderate amount of reasoning tokens
26
- - high: Allow extensive resources for thinking
27
- - max: Uses as much thinking as allowed by the provider.
28
-
29
- Mirascope makes a best effort to apply the chosen thinking level, but exact behavior
30
- varies by provider and model. For example, some models may not support thinking,
31
- while other models may not allow disabling it.
32
- """
33
-
34
- include_summaries: bool
35
- """Whether to generate reasoning summaries (human readable Thoughts) from model output.
36
-
37
- Generally, providers do not return raw model thinking output, but may produce
38
- thought summaries. When `include_summaries` is true, these will be requested from
39
- the provider (if available). Otherwise, they will not be requested.
40
- """
41
-
42
- encode_thoughts_as_text: bool
43
- """Re-encode Thought content as text for model consumption.
44
-
45
- If `True`, when an `AssistantMessage` contains `Thoughts` and is passed back
46
- to an LLM, those `Thoughts` will be encoded as `Text`, ensuring the assistant
47
- can read its prior reasoning. This contrasts with provider defaults which may
48
- ignore prior thoughts, particularly if tool calls are not involved.
49
-
50
- When `True`, Mirascope will re-encode messages rather than reusing raw provider
51
- response content, which may disable provider-specific optimizations like cached
52
- reasoning tokens.
53
-
54
- Defaults to `False` if unset.
55
- """
5
+ from .thinking_config import ThinkingConfig
56
6
 
57
7
 
58
8
  class Params(TypedDict, total=False):
@@ -75,8 +25,8 @@ class Params(TypedDict, total=False):
75
25
 
76
26
  top_p: float
77
27
  """Nucleus sampling parameter (0.0 to 1.0).
78
-
79
- Tokens are selected from the most to least probable until the sum of their
28
+
29
+ Tokens are selected from the most to least probable until the sum of their
80
30
  probabilities equals this value. Use a lower value for less random responses and a
81
31
  higher value for more random responses.
82
32
  """
@@ -93,7 +43,7 @@ class Params(TypedDict, total=False):
93
43
 
94
44
  seed: int
95
45
  """Random seed for reproducibility.
96
-
46
+
97
47
  When ``seed`` is fixed to a specific number, the model makes a best
98
48
  effort to provide the same response for repeated requests.
99
49
 
@@ -102,7 +52,7 @@ class Params(TypedDict, total=False):
102
52
 
103
53
  stop_sequences: list[str]
104
54
  """Stop sequences to end generation.
105
-
55
+
106
56
  The model will stop generating text if one of these strings is encountered in the
107
57
  response.
108
58
  """
@@ -111,7 +61,7 @@ class Params(TypedDict, total=False):
111
61
  """Configuration for extended reasoning/thinking.
112
62
 
113
63
  Pass a `ThinkingConfig` to configure thinking behavior. The `level` field controls
114
- whether thinking is enabled and how much reasoning to use. Level may be one of
64
+ whether thinking is enabled and how much reasoning to use. Level may be one of
115
65
  "minimal", "low", "medium", or "high". If level is unset, then thinking is enabled
116
66
  with a provider-specific default level.
117
67
 
@@ -0,0 +1,61 @@
1
+ """Configuration for extended reasoning/thinking in LLM responses."""
2
+
3
+ from typing import Literal
4
+ from typing_extensions import Required, TypedDict
5
+
6
+ ThinkingLevel = Literal["none", "default", "minimal", "low", "medium", "high", "max"]
7
+ """Level of effort/reasoning to apply to thinking."""
8
+
9
+
10
+ class ThinkingConfig(TypedDict, total=False):
11
+ """Configuration for extended reasoning/thinking in LLM responses.
12
+
13
+ Thinking is a process where the model spends additional tokens reasoning about
14
+ the prompt before generating a response. Providing any `ThinkingConfig` will enable
15
+ thinking (unless it is specifically disabled via level="minimal"). Depending on
16
+ the provider and model, thinking may always be active regardless of user settings.
17
+ """
18
+
19
+ level: Required[ThinkingLevel]
20
+ """Level of effort/reasoning to apply to thinking.
21
+
22
+ - none: Disable thinking entirely. Minimizes cost and latency.
23
+ - default: Use the provider's default
24
+ - minimal: Use the provider's lowest setting for reasoning
25
+ - medium: Use a moderate amount of reasoning tokens
26
+ - high: Allow extensive resources for thinking
27
+ - max: Uses as much thinking as allowed by the provider.
28
+
29
+ Mirascope makes a best effort to apply the chosen thinking level, but exact behavior
30
+ varies by provider and model. For example, some models may not support thinking,
31
+ while other models may not allow disabling it.
32
+ """
33
+
34
+ include_thoughts: bool
35
+ """Whether to include Thought content in the model output.
36
+
37
+ Depending on the model and provider, enabling include_thoughts to true may
38
+ request reasoning summaries (which are not the underlying reasoning tokens,
39
+ but a readable summary produced by another model), or it may be the original
40
+ reasoning tokens.
41
+
42
+ When include_thoughts is false, no summaries will be requested, and thoughts
43
+ will not be included in the output even if they were provided by the provider.
44
+
45
+ Defaults to false.
46
+ """
47
+
48
+ encode_thoughts_as_text: bool
49
+ """Re-encode Thought content as text for model consumption.
50
+
51
+ If `True`, when an `AssistantMessage` contains `Thoughts` and is passed back
52
+ to an LLM, those `Thoughts` will be encoded as `Text`, ensuring the assistant
53
+ can read its prior reasoning. This contrasts with provider defaults which may
54
+ ignore prior thoughts, particularly if tool calls are not involved.
55
+
56
+ When `True`, Mirascope will re-encode messages rather than reusing raw provider
57
+ response content, which may disable provider-specific optimizations like cached
58
+ reasoning tokens.
59
+
60
+ Defaults to `False` if unset.
61
+ """
@@ -1,16 +1,7 @@
1
1
  import inspect
2
- from collections.abc import Sequence
3
2
  from typing_extensions import TypeIs
4
3
 
5
4
  from ..context import DepsT, _utils as _context_utils
6
- from ..messages import (
7
- AssistantMessage,
8
- Message,
9
- SystemMessage,
10
- UserContent,
11
- UserMessage,
12
- user,
13
- )
14
5
  from ..types import P
15
6
  from .protocols import (
16
7
  AsyncContextMessageTemplate,
@@ -20,29 +11,6 @@ from .protocols import (
20
11
  )
21
12
 
22
13
 
23
- def is_messages(
24
- messages_or_content: Sequence[Message] | UserContent,
25
- ) -> TypeIs[Sequence[Message]]:
26
- if isinstance(messages_or_content, list):
27
- if not messages_or_content:
28
- raise ValueError("Empty array may not be used as message content")
29
- return isinstance(
30
- messages_or_content[0], SystemMessage | UserMessage | AssistantMessage
31
- )
32
- return False
33
-
34
-
35
- def promote_to_messages(result: Sequence[Message] | UserContent) -> Sequence[Message]:
36
- """Promote a prompt result to a list of messages.
37
-
38
- If the result is already a list of Messages, returns it as-is.
39
- If the result is UserContent, wraps it in a single user message.
40
- """
41
- if is_messages(result):
42
- return result
43
- return [user(result)]
44
-
45
-
46
14
  def is_context_promptable(
47
15
  fn: ContextMessageTemplate[P, DepsT]
48
16
  | AsyncContextMessageTemplate[P, DepsT]
@@ -4,7 +4,7 @@ from collections.abc import Sequence
4
4
  from typing import Generic, cast, overload
5
5
 
6
6
  from ..context import DepsT
7
- from ..formatting import Format, FormattableT
7
+ from ..formatting import Format, FormattableT, OutputParser
8
8
  from ..tools import (
9
9
  AsyncContextTool,
10
10
  AsyncContextToolkit,
@@ -46,13 +46,18 @@ class PromptDecorator(Generic[ToolT, FormattableT]):
46
46
  tools: Sequence[ToolT] | None
47
47
  """The tools that are included in the prompt, if any."""
48
48
 
49
- format: type[FormattableT] | Format[FormattableT] | None
49
+ format: (
50
+ type[FormattableT] | Format[FormattableT] | OutputParser[FormattableT] | None
51
+ )
50
52
  """The structured output format off the prompt, if any."""
51
53
 
52
54
  def __init__(
53
55
  self,
54
56
  tools: Sequence[ToolT] | None = None,
55
- format: type[FormattableT] | Format[FormattableT] | None = None,
57
+ format: type[FormattableT]
58
+ | Format[FormattableT]
59
+ | OutputParser[FormattableT]
60
+ | None = None,
56
61
  ) -> None:
57
62
  """Initialize the decorator with optional tools and format."""
58
63
  self.tools = tools
@@ -168,7 +173,10 @@ def prompt(
168
173
  def prompt(
169
174
  *,
170
175
  tools: Sequence[ToolT] | None = None,
171
- format: type[FormattableT] | Format[FormattableT] | None = None,
176
+ format: type[FormattableT]
177
+ | Format[FormattableT]
178
+ | OutputParser[FormattableT]
179
+ | None = None,
172
180
  ) -> PromptDecorator[ToolT, FormattableT]:
173
181
  """Create a decorator for Prompt functions with tools and format"""
174
182
 
@@ -181,7 +189,10 @@ def prompt(
181
189
  | None = None,
182
190
  *,
183
191
  tools: Sequence[ToolT] | None = None,
184
- format: type[FormattableT] | Format[FormattableT] | None = None,
192
+ format: type[FormattableT]
193
+ | Format[FormattableT]
194
+ | OutputParser[FormattableT]
195
+ | None = None,
185
196
  ) -> (
186
197
  AsyncContextPrompt[P, DepsT, FormattableT]
187
198
  | ContextPrompt[P, DepsT, FormattableT]