maitai-python 1.2.32__tar.gz → 1.2.34__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 (127) hide show
  1. {maitai_python-1.2.32 → maitai_python-1.2.34}/PKG-INFO +1 -1
  2. {maitai_python-1.2.32 → maitai_python-1.2.34}/maitai/_config.py +13 -0
  3. {maitai_python-1.2.32 → maitai_python-1.2.34}/maitai/_inference.py +6 -0
  4. {maitai_python-1.2.32 → maitai_python-1.2.34}/maitai/chat/_completions.py +31 -8
  5. {maitai_python-1.2.32 → maitai_python-1.2.34}/maitai/chat/_completions_async.py +29 -8
  6. {maitai_python-1.2.32 → maitai_python-1.2.34}/maitai_common/version.py +1 -1
  7. maitai_python-1.2.34/maitai_models/agent/shadow_recreate.py +111 -0
  8. {maitai_python-1.2.32 → maitai_python-1.2.34}/maitai_models/model.py +5 -0
  9. maitai_python-1.2.34/maitai_models/test_set.py +451 -0
  10. {maitai_python-1.2.32 → maitai_python-1.2.34}/maitai_python.egg-info/PKG-INFO +1 -1
  11. {maitai_python-1.2.32 → maitai_python-1.2.34}/maitai_python.egg-info/SOURCES.txt +9 -1
  12. {maitai_python-1.2.32 → maitai_python-1.2.34}/maitai_python.egg-info/top_level.txt +1 -0
  13. maitai_python-1.2.34/maitai_workflow/__init__.py +27 -0
  14. maitai_python-1.2.34/maitai_workflow/agent_request.py +165 -0
  15. maitai_python-1.2.34/maitai_workflow/context.py +2090 -0
  16. maitai_python-1.2.34/maitai_workflow/datastore/__init__.py +33 -0
  17. maitai_python-1.2.34/maitai_workflow/datastore/filters.py +298 -0
  18. maitai_python-1.2.34/maitai_workflow/profile_nav.py +62 -0
  19. {maitai_python-1.2.32 → maitai_python-1.2.34}/setup.py +4 -0
  20. {maitai_python-1.2.32 → maitai_python-1.2.34}/README.md +0 -0
  21. {maitai_python-1.2.32 → maitai_python-1.2.34}/maitai/__init__.py +0 -0
  22. {maitai_python-1.2.32 → maitai_python-1.2.34}/maitai/_config_listener.py +0 -0
  23. {maitai_python-1.2.32 → maitai_python-1.2.34}/maitai/_context.py +0 -0
  24. {maitai_python-1.2.32 → maitai_python-1.2.34}/maitai/_evaluator.py +0 -0
  25. {maitai_python-1.2.32 → maitai_python-1.2.34}/maitai/_files.py +0 -0
  26. {maitai_python-1.2.32 → maitai_python-1.2.34}/maitai/_logger.py +0 -0
  27. {maitai_python-1.2.32 → maitai_python-1.2.34}/maitai/_maitai.py +0 -0
  28. {maitai_python-1.2.32 → maitai_python-1.2.34}/maitai/_maitai_async.py +0 -0
  29. {maitai_python-1.2.32 → maitai_python-1.2.34}/maitai/_maitai_client.py +0 -0
  30. {maitai_python-1.2.32 → maitai_python-1.2.34}/maitai/_pydantic.py +0 -0
  31. {maitai_python-1.2.32 → maitai_python-1.2.34}/maitai/_types.py +0 -0
  32. {maitai_python-1.2.32 → maitai_python-1.2.34}/maitai/_utils.py +0 -0
  33. {maitai_python-1.2.32 → maitai_python-1.2.34}/maitai/agent/__init__.py +0 -0
  34. {maitai_python-1.2.32 → maitai_python-1.2.34}/maitai/agent/_completions.py +0 -0
  35. {maitai_python-1.2.32 → maitai_python-1.2.34}/maitai/agent/_completions_async.py +0 -0
  36. {maitai_python-1.2.32 → maitai_python-1.2.34}/maitai/agent/_handle.py +0 -0
  37. {maitai_python-1.2.32 → maitai_python-1.2.34}/maitai/agent/_request_wire.py +0 -0
  38. {maitai_python-1.2.32 → maitai_python-1.2.34}/maitai/chat/__init__.py +0 -0
  39. {maitai_python-1.2.32 → maitai_python-1.2.34}/maitai/exceptions.py +0 -0
  40. {maitai_python-1.2.32 → maitai_python-1.2.34}/maitai/integrations/__init__.py +0 -0
  41. {maitai_python-1.2.32 → maitai_python-1.2.34}/maitai/integrations/_observe.py +0 -0
  42. {maitai_python-1.2.32 → maitai_python-1.2.34}/maitai/integrations/_session.py +0 -0
  43. {maitai_python-1.2.32 → maitai_python-1.2.34}/maitai/models/__init__.py +0 -0
  44. {maitai_python-1.2.32 → maitai_python-1.2.34}/maitai/models/agent/__init__.py +0 -0
  45. {maitai_python-1.2.32 → maitai_python-1.2.34}/maitai/models/agent/base.py +0 -0
  46. {maitai_python-1.2.32 → maitai_python-1.2.34}/maitai/models/agent/enum.py +0 -0
  47. {maitai_python-1.2.32 → maitai_python-1.2.34}/maitai/models/agent/extended.py +0 -0
  48. {maitai_python-1.2.32 → maitai_python-1.2.34}/maitai/models/agent_action.py +0 -0
  49. {maitai_python-1.2.32 → maitai_python-1.2.34}/maitai/models/agent_routing.py +0 -0
  50. {maitai_python-1.2.32 → maitai_python-1.2.34}/maitai/models/application.py +0 -0
  51. {maitai_python-1.2.32 → maitai_python-1.2.34}/maitai/models/chat.py +0 -0
  52. {maitai_python-1.2.32 → maitai_python-1.2.34}/maitai/models/config.py +0 -0
  53. {maitai_python-1.2.32 → maitai_python-1.2.34}/maitai/models/event.py +0 -0
  54. {maitai_python-1.2.32 → maitai_python-1.2.34}/maitai/models/inference.py +0 -0
  55. {maitai_python-1.2.32 → maitai_python-1.2.34}/maitai/models/key.py +0 -0
  56. {maitai_python-1.2.32 → maitai_python-1.2.34}/maitai/models/metric.py +0 -0
  57. {maitai_python-1.2.32 → maitai_python-1.2.34}/maitai/models/sentinel.py +0 -0
  58. {maitai_python-1.2.32 → maitai_python-1.2.34}/maitai/models/workflow_chunk.py +0 -0
  59. {maitai_python-1.2.32 → maitai_python-1.2.34}/maitai/tools/__init__.py +0 -0
  60. {maitai_python-1.2.32 → maitai_python-1.2.34}/maitai/transcriptions/__init__.py +0 -0
  61. {maitai_python-1.2.32 → maitai_python-1.2.34}/maitai/transcriptions/_transcriptions.py +0 -0
  62. {maitai_python-1.2.32 → maitai_python-1.2.34}/maitai/transcriptions/_transcriptions_async.py +0 -0
  63. {maitai_python-1.2.32 → maitai_python-1.2.34}/maitai/workflow/__init__.py +0 -0
  64. {maitai_python-1.2.32 → maitai_python-1.2.34}/maitai/workflow/_completions.py +0 -0
  65. {maitai_python-1.2.32 → maitai_python-1.2.34}/maitai/workflow/_completions_async.py +0 -0
  66. {maitai_python-1.2.32 → maitai_python-1.2.34}/maitai/workflow/_local.py +0 -0
  67. {maitai_python-1.2.32 → maitai_python-1.2.34}/maitai/workflow/_stream_http.py +0 -0
  68. {maitai_python-1.2.32 → maitai_python-1.2.34}/maitai_common/__init__.py +0 -0
  69. {maitai_python-1.2.32 → maitai_python-1.2.34}/maitai_common/config/__init__.py +0 -0
  70. {maitai_python-1.2.32 → maitai_python-1.2.34}/maitai_common/config/config_service.py +0 -0
  71. {maitai_python-1.2.32 → maitai_python-1.2.34}/maitai_models/adapter.py +0 -0
  72. {maitai_python-1.2.32 → maitai_python-1.2.34}/maitai_models/agent/__init__.py +0 -0
  73. {maitai_python-1.2.32 → maitai_python-1.2.34}/maitai_models/agent/base.py +0 -0
  74. {maitai_python-1.2.32 → maitai_python-1.2.34}/maitai_models/agent/enum.py +0 -0
  75. {maitai_python-1.2.32 → maitai_python-1.2.34}/maitai_models/agent/extended.py +0 -0
  76. {maitai_python-1.2.32 → maitai_python-1.2.34}/maitai_models/agent/import_manifest.py +0 -0
  77. {maitai_python-1.2.32 → maitai_python-1.2.34}/maitai_models/agent_action.py +0 -0
  78. {maitai_python-1.2.32 → maitai_python-1.2.34}/maitai_models/agent_evaluation.py +0 -0
  79. {maitai_python-1.2.32 → maitai_python-1.2.34}/maitai_models/agent_form.py +0 -0
  80. {maitai_python-1.2.32 → maitai_python-1.2.34}/maitai_models/agent_routing.py +0 -0
  81. {maitai_python-1.2.32 → maitai_python-1.2.34}/maitai_models/application.py +0 -0
  82. {maitai_python-1.2.32 → maitai_python-1.2.34}/maitai_models/assistant_model.py +0 -0
  83. {maitai_python-1.2.32 → maitai_python-1.2.34}/maitai_models/backtest.py +0 -0
  84. {maitai_python-1.2.32 → maitai_python-1.2.34}/maitai_models/billing.py +0 -0
  85. {maitai_python-1.2.32 → maitai_python-1.2.34}/maitai_models/chat.py +0 -0
  86. {maitai_python-1.2.32 → maitai_python-1.2.34}/maitai_models/chat_metadata.py +0 -0
  87. {maitai_python-1.2.32 → maitai_python-1.2.34}/maitai_models/company.py +0 -0
  88. {maitai_python-1.2.32 → maitai_python-1.2.34}/maitai_models/config.py +0 -0
  89. {maitai_python-1.2.32 → maitai_python-1.2.34}/maitai_models/connection.py +0 -0
  90. {maitai_python-1.2.32 → maitai_python-1.2.34}/maitai_models/continuous_learning.py +0 -0
  91. {maitai_python-1.2.32 → maitai_python-1.2.34}/maitai_models/conversation_builder.py +0 -0
  92. {maitai_python-1.2.32 → maitai_python-1.2.34}/maitai_models/dataset.py +0 -0
  93. {maitai_python-1.2.32 → maitai_python-1.2.34}/maitai_models/dataset_import.py +0 -0
  94. {maitai_python-1.2.32 → maitai_python-1.2.34}/maitai_models/deploy.py +0 -0
  95. {maitai_python-1.2.32 → maitai_python-1.2.34}/maitai_models/embedding.py +0 -0
  96. {maitai_python-1.2.32 → maitai_python-1.2.34}/maitai_models/evaluation.py +0 -0
  97. {maitai_python-1.2.32 → maitai_python-1.2.34}/maitai_models/evaluation_enums.py +0 -0
  98. {maitai_python-1.2.32 → maitai_python-1.2.34}/maitai_models/event.py +0 -0
  99. {maitai_python-1.2.32 → maitai_python-1.2.34}/maitai_models/event_subscription.py +0 -0
  100. {maitai_python-1.2.32 → maitai_python-1.2.34}/maitai_models/file.py +0 -0
  101. {maitai_python-1.2.32 → maitai_python-1.2.34}/maitai_models/finetuning.py +0 -0
  102. {maitai_python-1.2.32 → maitai_python-1.2.34}/maitai_models/inference.py +0 -0
  103. {maitai_python-1.2.32 → maitai_python-1.2.34}/maitai_models/infra.py +0 -0
  104. {maitai_python-1.2.32 → maitai_python-1.2.34}/maitai_models/intent.py +0 -0
  105. {maitai_python-1.2.32 → maitai_python-1.2.34}/maitai_models/intent_config_version.py +0 -0
  106. {maitai_python-1.2.32 → maitai_python-1.2.34}/maitai_models/key.py +0 -0
  107. {maitai_python-1.2.32 → maitai_python-1.2.34}/maitai_models/metadata.py +0 -0
  108. {maitai_python-1.2.32 → maitai_python-1.2.34}/maitai_models/metric.py +0 -0
  109. {maitai_python-1.2.32 → maitai_python-1.2.34}/maitai_models/model_drift.py +0 -0
  110. {maitai_python-1.2.32 → maitai_python-1.2.34}/maitai_models/model_profile.py +0 -0
  111. {maitai_python-1.2.32 → maitai_python-1.2.34}/maitai_models/monitor.py +0 -0
  112. {maitai_python-1.2.32 → maitai_python-1.2.34}/maitai_models/notification.py +0 -0
  113. {maitai_python-1.2.32 → maitai_python-1.2.34}/maitai_models/rates.py +0 -0
  114. {maitai_python-1.2.32 → maitai_python-1.2.34}/maitai_models/sandbox.py +0 -0
  115. {maitai_python-1.2.32 → maitai_python-1.2.34}/maitai_models/scheduled_job.py +0 -0
  116. {maitai_python-1.2.32 → maitai_python-1.2.34}/maitai_models/sentinel.py +0 -0
  117. {maitai_python-1.2.32 → maitai_python-1.2.34}/maitai_models/session.py +0 -0
  118. {maitai_python-1.2.32 → maitai_python-1.2.34}/maitai_models/shared_resource.py +0 -0
  119. {maitai_python-1.2.32 → maitai_python-1.2.34}/maitai_models/slack_integration.py +0 -0
  120. {maitai_python-1.2.32 → maitai_python-1.2.34}/maitai_models/tagging.py +0 -0
  121. {maitai_python-1.2.32 → maitai_python-1.2.34}/maitai_models/webhook.py +0 -0
  122. {maitai_python-1.2.32 → maitai_python-1.2.34}/maitai_models/webhook_event.py +0 -0
  123. {maitai_python-1.2.32 → maitai_python-1.2.34}/maitai_models/workflow.py +0 -0
  124. {maitai_python-1.2.32 → maitai_python-1.2.34}/maitai_models/workflow_chunk.py +0 -0
  125. {maitai_python-1.2.32 → maitai_python-1.2.34}/maitai_python.egg-info/dependency_links.txt +0 -0
  126. {maitai_python-1.2.32 → maitai_python-1.2.34}/maitai_python.egg-info/requires.txt +0 -0
  127. {maitai_python-1.2.32 → maitai_python-1.2.34}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: maitai-python
3
- Version: 1.2.32
3
+ Version: 1.2.34
4
4
  Summary: Maitai SDK for Python
5
5
  Home-page: https://docs.trymaitai.ai
6
6
  Author: Maitai
@@ -148,6 +148,19 @@ class Config(MaitaiClient):
148
148
  action_type, config_service.get_default_config()
149
149
  )
150
150
 
151
+ def has_application_action_config(
152
+ self, application_ref_name: str, action_type: str
153
+ ) -> bool:
154
+ """Whether a real (locally-fetched) config exists for this intent.
155
+
156
+ ``get_application_action_config`` falls back to a hardcoded default when
157
+ the store is empty, so callers use this to tell "server said this model"
158
+ apart from "no config known — let the server decide".
159
+ """
160
+ return action_type in self._application_action_configs.get(
161
+ application_ref_name, {}
162
+ )
163
+
151
164
  def store_application_metadata(self, applications: List[Application]):
152
165
  for application in applications:
153
166
  for action_type in application.action_types:
@@ -89,6 +89,9 @@ class Inference(MaitaiClient):
89
89
  "x-api-key": self.config.api_key,
90
90
  "User-Agent": version,
91
91
  }
92
+ client_request_id = request_dict.get("request_id")
93
+ if client_request_id:
94
+ headers["X-Request-ID"] = str(client_request_id)
92
95
 
93
96
  client = self.get_client()
94
97
 
@@ -160,6 +163,9 @@ class Inference(MaitaiClient):
160
163
  "x-api-key": self.config.api_key,
161
164
  "User-Agent": version,
162
165
  }
166
+ client_request_id = request_dict.get("request_id")
167
+ if client_request_id:
168
+ headers["X-Request-ID"] = str(client_request_id)
163
169
 
164
170
  # Log the request being made
165
171
  logger.info(f"Making inference request to {url} with timeout={timeout}")
@@ -100,6 +100,7 @@ class Completions:
100
100
  return_request: bool = False,
101
101
  push_timing_metrics: bool = True,
102
102
  from_workflow: bool = False,
103
+ request_id: Optional[str] = None,
103
104
  # OpenAI Arguments
104
105
  messages: Iterable[openai_chat_types.ChatCompletionMessageParam],
105
106
  model: Union[str, openai_types.ChatModel, openai.NotGiven] = openai.NOT_GIVEN,
@@ -172,6 +173,9 @@ class Completions:
172
173
  if not session_id:
173
174
  session_id = str(uuid.uuid4())
174
175
  maitai_config = self.config.get_application_action_config(application, intent)
176
+ has_local_config = self.config.has_application_action_config(
177
+ application, intent
178
+ )
175
179
  if server_side_inference is None:
176
180
  server_side_inference = (
177
181
  maitai_config.inference_location == InferenceLocations.SERVER
@@ -180,7 +184,12 @@ class Completions:
180
184
  evaluation_enabled = maitai_config.evaluation_enabled
181
185
  if apply_corrections is None:
182
186
  apply_corrections = maitai_config.apply_corrections
183
- defer_to_server = from_workflow and server_side_inference
187
+ # Defer model/param selection to the server when it is doing the
188
+ # inference and we have no locally-known intent config to fill from;
189
+ # otherwise the default config's model would override the intent's.
190
+ defer_to_server = server_side_inference and (
191
+ from_workflow or not has_local_config
192
+ )
184
193
  if model == openai.NOT_GIVEN:
185
194
  if defer_to_server:
186
195
  model = None
@@ -194,7 +203,13 @@ class Completions:
194
203
  response_format = {"type": "text"}
195
204
  if max_completion_tokens and max_completion_tokens != openai.NOT_GIVEN:
196
205
  max_tokens = max_completion_tokens
197
- if not defer_to_server:
206
+ if defer_to_server:
207
+ # Do not inject SDK Config defaults (temperature=1, penalties, …).
208
+ # Send temperature=None explicitly so the backend inherits from the
209
+ # Portal intent instead of treating a missing-vs-default ambiguity.
210
+ if temperature == openai.NOT_GIVEN:
211
+ temperature = None
212
+ else:
198
213
  if temperature == openai.NOT_GIVEN:
199
214
  temperature = maitai_config.temperature
200
215
  if stop == openai.NOT_GIVEN and maitai_config.stop is not None:
@@ -286,6 +301,8 @@ class Completions:
286
301
  "return_request": return_request,
287
302
  "fallback_config": fallback_config,
288
303
  }
304
+ if request_id:
305
+ request_dict["request_id"] = request_id
289
306
 
290
307
  if from_workflow:
291
308
  request_dict["from_workflow"] = True
@@ -303,6 +320,7 @@ class Completions:
303
320
  del retry_args["self"]
304
321
  retry_args["server_side_inference"] = False
305
322
  retry_args["model"] = model
323
+ retry_args["fallback_config"] = fallback_config
306
324
  return self._process_inference_stream(
307
325
  response,
308
326
  retry_args,
@@ -611,12 +629,17 @@ class Completions:
611
629
  if not timing.time_request_end:
612
630
  timing.time_request_end = time.time()
613
631
  except MaitaiConnectionError as e:
614
- if "gpt" not in retry_args.get("model", "") and "gpt" in (
615
- retry_args.get("fallback_model", "") or ""
616
- ):
617
- retry_args["model"] = retry_args["fallback_model"]
618
- if "gpt" in retry_args.get("model", ""):
619
- retry_args["model"] = retry_args["model"].replace("openai:", "")
632
+ fallback_config = retry_args.get("fallback_config")
633
+ fallback_model = (
634
+ fallback_config.get("model")
635
+ if isinstance(fallback_config, dict)
636
+ else None
637
+ )
638
+ model = retry_args.get("model")
639
+ if "gpt" not in (model or "") and "gpt" in (fallback_model or ""):
640
+ model = fallback_model
641
+ if model and "gpt" in model:
642
+ retry_args["model"] = model.replace("openai:", "")
620
643
  response = self.create(**retry_args)
621
644
  for resp in response:
622
645
  yield resp
@@ -101,6 +101,7 @@ class AsyncCompletions:
101
101
  return_request: bool = False,
102
102
  push_timing_metrics: bool = True,
103
103
  from_workflow: bool = False,
104
+ request_id: Optional[str] = None,
104
105
  # OpenAI Arguments
105
106
  messages: Iterable[openai_chat_types.ChatCompletionMessageParam],
106
107
  model: Union[str, openai_types.ChatModel, openai.NotGiven] = openai.NOT_GIVEN,
@@ -173,6 +174,9 @@ class AsyncCompletions:
173
174
  if not session_id:
174
175
  session_id = str(uuid.uuid4())
175
176
  maitai_config = self.config.get_application_action_config(application, intent)
177
+ has_local_config = self.config.has_application_action_config(
178
+ application, intent
179
+ )
176
180
  if server_side_inference is None:
177
181
  server_side_inference = (
178
182
  maitai_config.inference_location == InferenceLocations.SERVER
@@ -181,7 +185,12 @@ class AsyncCompletions:
181
185
  evaluation_enabled = maitai_config.evaluation_enabled
182
186
  if apply_corrections is None:
183
187
  apply_corrections = maitai_config.apply_corrections
184
- defer_to_server = from_workflow and server_side_inference
188
+ # Defer model/param selection to the server when it is doing the
189
+ # inference and we have no locally-known intent config to fill from;
190
+ # otherwise the default config's model would override the intent's.
191
+ defer_to_server = server_side_inference and (
192
+ from_workflow or not has_local_config
193
+ )
185
194
  if model == openai.NOT_GIVEN:
186
195
  if defer_to_server:
187
196
  model = None
@@ -195,7 +204,11 @@ class AsyncCompletions:
195
204
  response_format = {"type": "text"}
196
205
  if max_completion_tokens and max_completion_tokens != openai.NOT_GIVEN:
197
206
  max_tokens = max_completion_tokens
198
- if not defer_to_server:
207
+ if defer_to_server:
208
+ # Do not inject SDK Config defaults (temperature=1, penalties, …).
209
+ if temperature == openai.NOT_GIVEN:
210
+ temperature = None
211
+ else:
199
212
  if temperature == openai.NOT_GIVEN:
200
213
  temperature = maitai_config.temperature
201
214
  if stop == openai.NOT_GIVEN and maitai_config.stop is not None:
@@ -287,6 +300,8 @@ class AsyncCompletions:
287
300
  "return_request": return_request,
288
301
  "fallback_config": fallback_config,
289
302
  }
303
+ if request_id:
304
+ request_dict["request_id"] = request_id
290
305
 
291
306
  if from_workflow:
292
307
  request_dict["from_workflow"] = True
@@ -304,6 +319,7 @@ class AsyncCompletions:
304
319
  del retry_args["self"]
305
320
  retry_args["server_side_inference"] = False
306
321
  retry_args["model"] = model
322
+ retry_args["fallback_config"] = fallback_config
307
323
  return self._process_inference_stream_async(
308
324
  response,
309
325
  retry_args,
@@ -620,12 +636,17 @@ class AsyncCompletions:
620
636
  if not timing.time_request_end:
621
637
  timing.time_request_end = time.time()
622
638
  except MaitaiConnectionError as e:
623
- if "gpt" not in retry_args.get("model", "") and "gpt" in (
624
- retry_args.get("fallback_model", "") or ""
625
- ):
626
- retry_args["model"] = retry_args["fallback_model"]
627
- if "gpt" in retry_args.get("model", ""):
628
- retry_args["model"] = retry_args["model"].replace("openai:", "")
639
+ fallback_config = retry_args.get("fallback_config")
640
+ fallback_model = (
641
+ fallback_config.get("model")
642
+ if isinstance(fallback_config, dict)
643
+ else None
644
+ )
645
+ model = retry_args.get("model")
646
+ if "gpt" not in (model or "") and "gpt" in (fallback_model or ""):
647
+ model = fallback_model
648
+ if model and "gpt" in model:
649
+ retry_args["model"] = model.replace("openai:", "")
629
650
  logger.warning("Maitai issue, retrying on client side")
630
651
  response = await self.create(**retry_args)
631
652
  async for resp in response:
@@ -1,3 +1,3 @@
1
- version = "1.2.32"
1
+ version = "1.2.34"
2
2
  if __name__ == "__main__":
3
3
  print(version)
@@ -0,0 +1,111 @@
1
+ # codegen: frontend
2
+
3
+ """Decision/audit log for recreating an observed external agent as an editable
4
+ Maitai agent.
5
+
6
+ The recreation pipeline (``maitai_back.agent.shadow_recreate_service``) is
7
+ **deterministic-first**: code extracts the agent's structure, tools, and model
8
+ config from recorded observed traces, and the LLM ("Mojo") runner is consulted
9
+ only for judgment calls (naming, prompt-template slotting, tool-description
10
+ synthesis). Every decision — deterministic or judgment — is recorded here with
11
+ its supporting evidence so the whole reconstruction is reproducible and
12
+ auditable from an internal admin page.
13
+
14
+ The full :class:`ShadowRecreateAuditLog` is persisted under a single key on the
15
+ recreated agent's ``meta`` column: ``agent.meta["shadow_recreate"]``.
16
+ """
17
+
18
+ from enum import Enum
19
+ from typing import Any, Dict, List, Optional
20
+
21
+ from pydantic import BaseModel, Field
22
+
23
+
24
+ class DecisionType(str, Enum):
25
+ """Which reconstruction decision a :class:`DecisionLogEntry` records."""
26
+
27
+ AGENT_NAME = "AGENT_NAME"
28
+ INSTRUCTIONS_TEMPLATE = "INSTRUCTIONS_TEMPLATE"
29
+ MODEL_CONFIG = "MODEL_CONFIG"
30
+ TOOL_EXTRACTION = "TOOL_EXTRACTION"
31
+ TOOL_DESCRIPTION = "TOOL_DESCRIPTION"
32
+ SUBAGENT_TREE = "SUBAGENT_TREE"
33
+ EXECUTION_MODE = "EXECUTION_MODE"
34
+ PUBLISH = "PUBLISH"
35
+
36
+
37
+ class MojoCallRecord(BaseModel):
38
+ """One invocation of the Mojo (headless runner) for a judgment decision.
39
+
40
+ Recorded verbatim so a reviewer can see exactly what the model was asked,
41
+ what it returned, and whether we trusted it or fell back to the
42
+ deterministic default (``parsed_ok=False``).
43
+ """
44
+
45
+ runner_session_id: Optional[str] = None
46
+ prompt: str = ""
47
+ output: Optional[str] = None
48
+ # Mirrors HeadlessRunnerResult.status: finished | error | stopped | timeout.
49
+ status: str = ""
50
+ duration_ms: int = 0
51
+ model: Optional[str] = None
52
+ error: Optional[str] = None
53
+ # False when the runner failed/timed out or returned unparseable JSON and
54
+ # we fell back to the deterministic default.
55
+ parsed_ok: bool = True
56
+
57
+
58
+ class DecisionEvidence(BaseModel):
59
+ """The recorded inputs that justify a decision.
60
+
61
+ Deliberately loose so both deterministic and judgment decisions can point
62
+ at whatever proof is relevant (which traces, how many agreed, sample
63
+ values).
64
+ """
65
+
66
+ trace_ids: List[str] = Field(default_factory=list)
67
+ task_ids: List[str] = Field(default_factory=list)
68
+ # e.g. {"unique_prompts": 3, "traces_analyzed": 5, "gpt-4.1": 4, "gpt-4o": 1}
69
+ counts: Dict[str, int] = Field(default_factory=dict)
70
+ # Representative values: deduped prompt hashes, tool names, sample args, etc.
71
+ samples: List[str] = Field(default_factory=list)
72
+ notes: Optional[str] = None
73
+
74
+
75
+ class DecisionLogEntry(BaseModel):
76
+ """A single reconstruction decision plus its evidence.
77
+
78
+ ``deterministic`` drives the UI badge directly (rather than inferring it
79
+ from ``mojo_call is None``); judgment decisions that fell back to the
80
+ deterministic default are still ``deterministic=False`` but carry a
81
+ ``mojo_call`` with ``parsed_ok=False``.
82
+ """
83
+
84
+ sequence: int
85
+ decision_type: DecisionType
86
+ decision: str
87
+ rationale: str = ""
88
+ deterministic: bool = True
89
+ evidence: DecisionEvidence = Field(default_factory=DecisionEvidence)
90
+ mojo_call: Optional[MojoCallRecord] = None
91
+
92
+
93
+ class ShadowRecreateAuditLog(BaseModel):
94
+ """Full audit trail of one recreate-from-traces run.
95
+
96
+ Serialized to ``agent.meta["shadow_recreate"]`` on the recreated agent and
97
+ rendered decision-by-decision on the internal admin page.
98
+ """
99
+
100
+ # Schema version of THIS log format (not the agent version).
101
+ version: str = "1"
102
+ observed_agent_id: int
103
+ recreated_agent_id: Optional[int] = None
104
+ recreated_version: Optional[str] = None
105
+ sessions_scanned: int = 0
106
+ corpus_task_ids: List[str] = Field(default_factory=list)
107
+ decisions: List[DecisionLogEntry] = Field(default_factory=list)
108
+ warnings: List[str] = Field(default_factory=list)
109
+ created_at_ms: int = 0
110
+ # completed | failed
111
+ status: str = "completed"
@@ -32,6 +32,11 @@ class Model(BaseModel):
32
32
  finetune_run_id: Optional[int] = Field(default=None)
33
33
  instance_id: Optional[int] = Field(default=None)
34
34
  region: Optional[str] = Field(default=None)
35
+ # Application this model belongs to. Only populated for finetuned models on
36
+ # the Models listing (derived from the finetune run, falling back to intent);
37
+ # None elsewhere.
38
+ application_id: Optional[int] = Field(default=None)
39
+ application_name: Optional[str] = Field(default=None)
35
40
  supports_logprobs: bool = Field(default=False)
36
41
  chat_template_kwargs: Optional[dict] = Field(default=None)
37
42
  meta: Optional[dict] = Field(default_factory=dict)