maitai-python 1.2.29b0__tar.gz → 1.2.30__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 (51) hide show
  1. {maitai_python-1.2.29b0 → maitai_python-1.2.30}/PKG-INFO +1 -1
  2. {maitai_python-1.2.29b0 → maitai_python-1.2.30}/maitai/_maitai.py +7 -10
  3. {maitai_python-1.2.29b0 → maitai_python-1.2.30}/maitai/_maitai_async.py +7 -9
  4. {maitai_python-1.2.29b0 → maitai_python-1.2.30}/maitai/_maitai_client.py +30 -18
  5. {maitai_python-1.2.29b0 → maitai_python-1.2.30}/maitai/agent/_completions.py +2 -2
  6. {maitai_python-1.2.29b0 → maitai_python-1.2.30}/maitai/agent/_completions_async.py +2 -2
  7. {maitai_python-1.2.29b0 → maitai_python-1.2.30}/maitai/models/agent/enum.py +7 -0
  8. {maitai_python-1.2.29b0 → maitai_python-1.2.30}/maitai/models/agent/extended.py +50 -9
  9. {maitai_python-1.2.29b0 → maitai_python-1.2.30}/maitai_common/version.py +1 -1
  10. {maitai_python-1.2.29b0 → maitai_python-1.2.30}/maitai_python.egg-info/PKG-INFO +1 -1
  11. {maitai_python-1.2.29b0 → maitai_python-1.2.30}/README.md +0 -0
  12. {maitai_python-1.2.29b0 → maitai_python-1.2.30}/maitai/__init__.py +0 -0
  13. {maitai_python-1.2.29b0 → maitai_python-1.2.30}/maitai/_config.py +0 -0
  14. {maitai_python-1.2.29b0 → maitai_python-1.2.30}/maitai/_config_listener.py +0 -0
  15. {maitai_python-1.2.29b0 → maitai_python-1.2.30}/maitai/_context.py +0 -0
  16. {maitai_python-1.2.29b0 → maitai_python-1.2.30}/maitai/_evaluator.py +0 -0
  17. {maitai_python-1.2.29b0 → maitai_python-1.2.30}/maitai/_inference.py +0 -0
  18. {maitai_python-1.2.29b0 → maitai_python-1.2.30}/maitai/_pydantic.py +0 -0
  19. {maitai_python-1.2.29b0 → maitai_python-1.2.30}/maitai/_types.py +0 -0
  20. {maitai_python-1.2.29b0 → maitai_python-1.2.30}/maitai/_utils.py +0 -0
  21. {maitai_python-1.2.29b0 → maitai_python-1.2.30}/maitai/agent/__init__.py +0 -0
  22. {maitai_python-1.2.29b0 → maitai_python-1.2.30}/maitai/chat/__init__.py +0 -0
  23. {maitai_python-1.2.29b0 → maitai_python-1.2.30}/maitai/chat/_completions.py +0 -0
  24. {maitai_python-1.2.29b0 → maitai_python-1.2.30}/maitai/chat/_completions_async.py +0 -0
  25. {maitai_python-1.2.29b0 → maitai_python-1.2.30}/maitai/exceptions.py +0 -0
  26. {maitai_python-1.2.29b0 → maitai_python-1.2.30}/maitai/models/__init__.py +0 -0
  27. {maitai_python-1.2.29b0 → maitai_python-1.2.30}/maitai/models/agent/__init__.py +0 -0
  28. {maitai_python-1.2.29b0 → maitai_python-1.2.30}/maitai/models/agent/base.py +0 -0
  29. {maitai_python-1.2.29b0 → maitai_python-1.2.30}/maitai/models/agent_action.py +0 -0
  30. {maitai_python-1.2.29b0 → maitai_python-1.2.30}/maitai/models/agent_routing.py +0 -0
  31. {maitai_python-1.2.29b0 → maitai_python-1.2.30}/maitai/models/application.py +0 -0
  32. {maitai_python-1.2.29b0 → maitai_python-1.2.30}/maitai/models/chat.py +0 -0
  33. {maitai_python-1.2.29b0 → maitai_python-1.2.30}/maitai/models/config.py +0 -0
  34. {maitai_python-1.2.29b0 → maitai_python-1.2.30}/maitai/models/event.py +0 -0
  35. {maitai_python-1.2.29b0 → maitai_python-1.2.30}/maitai/models/inference.py +0 -0
  36. {maitai_python-1.2.29b0 → maitai_python-1.2.30}/maitai/models/key.py +0 -0
  37. {maitai_python-1.2.29b0 → maitai_python-1.2.30}/maitai/models/metric.py +0 -0
  38. {maitai_python-1.2.29b0 → maitai_python-1.2.30}/maitai/models/sentinel.py +0 -0
  39. {maitai_python-1.2.29b0 → maitai_python-1.2.30}/maitai/tools/__init__.py +0 -0
  40. {maitai_python-1.2.29b0 → maitai_python-1.2.30}/maitai/transcriptions/__init__.py +0 -0
  41. {maitai_python-1.2.29b0 → maitai_python-1.2.30}/maitai/transcriptions/_transcriptions.py +0 -0
  42. {maitai_python-1.2.29b0 → maitai_python-1.2.30}/maitai/transcriptions/_transcriptions_async.py +0 -0
  43. {maitai_python-1.2.29b0 → maitai_python-1.2.30}/maitai_common/__init__.py +0 -0
  44. {maitai_python-1.2.29b0 → maitai_python-1.2.30}/maitai_common/config/__init__.py +0 -0
  45. {maitai_python-1.2.29b0 → maitai_python-1.2.30}/maitai_common/config/config_service.py +0 -0
  46. {maitai_python-1.2.29b0 → maitai_python-1.2.30}/maitai_python.egg-info/SOURCES.txt +0 -0
  47. {maitai_python-1.2.29b0 → maitai_python-1.2.30}/maitai_python.egg-info/dependency_links.txt +0 -0
  48. {maitai_python-1.2.29b0 → maitai_python-1.2.30}/maitai_python.egg-info/requires.txt +0 -0
  49. {maitai_python-1.2.29b0 → maitai_python-1.2.30}/maitai_python.egg-info/top_level.txt +0 -0
  50. {maitai_python-1.2.29b0 → maitai_python-1.2.30}/setup.cfg +0 -0
  51. {maitai_python-1.2.29b0 → maitai_python-1.2.30}/setup.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: maitai-python
3
- Version: 1.2.29b0
3
+ Version: 1.2.30
4
4
  Summary: Maitai SDK for Python
5
5
  Home-page: https://docs.trymaitai.ai
6
6
  Author: Maitai
@@ -150,16 +150,13 @@ class Maitai:
150
150
  http_client=http_client,
151
151
  _strict_response_validation=_strict_response_validation,
152
152
  )
153
- if groq_api_key or self.config.auth_keys.groq_api_key:
154
-
155
- self._groq_client = groq.Groq(
156
- api_key=groq_api_key
157
- or (
158
- self.config.auth_keys.groq_api_key.key_value
159
- if self.config.auth_keys.groq_api_key
160
- else None
161
- ),
162
- )
153
+ groq_key_value = groq_api_key or (
154
+ self.config.auth_keys.groq_api_key.key_value
155
+ if self.config.auth_keys.groq_api_key
156
+ else None
157
+ )
158
+ if groq_key_value and groq_key_value.strip():
159
+ self._groq_client = groq.Groq(api_key=groq_key_value)
163
160
 
164
161
  client_params = None
165
162
  if base_url or default_headers or default_query:
@@ -149,15 +149,13 @@ class MaitaiAsync:
149
149
  http_client=http_client,
150
150
  _strict_response_validation=_strict_response_validation,
151
151
  )
152
- if groq_api_key or self.config.auth_keys.groq_api_key:
153
- self._groq_client = groq.AsyncGroq(
154
- api_key=groq_api_key
155
- or (
156
- self.config.auth_keys.groq_api_key.key_value
157
- if self.config.auth_keys.groq_api_key
158
- else None
159
- ),
160
- )
152
+ groq_key_value = groq_api_key or (
153
+ self.config.auth_keys.groq_api_key.key_value
154
+ if self.config.auth_keys.groq_api_key
155
+ else None
156
+ )
157
+ if groq_key_value and groq_key_value.strip():
158
+ self._groq_client = groq.AsyncGroq(api_key=groq_key_value)
161
159
 
162
160
  client_params = None
163
161
  if base_url or default_headers or default_query:
@@ -6,9 +6,12 @@ import httpx
6
6
  from maitai_common.version import version
7
7
 
8
8
  try:
9
- from ddtrace.trace import tracer
9
+ from opentelemetry import trace
10
+
11
+ from maitai_back.instrumentation.tracer import trace_span, tracer
10
12
  except ImportError:
11
13
  tracer = None
14
+ trace = None
12
15
 
13
16
  # Common client settings to ensure consistency
14
17
  CLIENT_SETTINGS = {
@@ -82,8 +85,11 @@ class MaitaiClient:
82
85
  return self.maitai_host
83
86
 
84
87
  def _determine_maitai_orchestration_host(self):
85
- if maitai_orchestration_host := os.environ.get("MAITAI_ORCHESTRATION_HOST"):
86
- return maitai_orchestration_host.rstrip("/")
88
+ if maitai_agent_host := os.environ.get("MAITAI_AGENT_HOST"):
89
+ maitai_agent_host = maitai_agent_host.rstrip("/")
90
+ if maitai_agent_host.endswith("/agent"):
91
+ maitai_agent_host = maitai_agent_host[: -len("/agent")]
92
+ return maitai_agent_host.rstrip("/")
87
93
  return self.maitai_host
88
94
 
89
95
  def _determine_maitai_inference_host(self):
@@ -93,7 +99,7 @@ class MaitaiClient:
93
99
 
94
100
  def get_client(self):
95
101
  if tracer:
96
- with tracer.trace("get_client"):
102
+ with tracer.start_as_current_span("get_client"):
97
103
  return self._get_client()
98
104
  return self._get_client()
99
105
 
@@ -107,24 +113,30 @@ class MaitaiClient:
107
113
 
108
114
  def get_async_client(self):
109
115
  if tracer:
110
- with tracer.trace("get_async_client"):
116
+ with tracer.start_as_current_span("get_async_client"):
111
117
  return self._get_async_client()
112
118
  return self._get_async_client()
113
119
 
114
120
  def _get_async_client(self):
115
- span = None
116
121
  if tracer:
117
- span = tracer.trace("create_async_client")
118
- if self._async_client is None:
119
- self._async_client = httpx.AsyncClient(
120
- **CLIENT_SETTINGS,
121
- transport=httpx.AsyncHTTPTransport(
122
- retries=DEFAULT_MAX_RETRIES, http2=True
123
- ),
124
- )
125
- if span:
126
- span.finish()
127
- return self._async_client
122
+ with tracer.start_as_current_span("create_async_client"):
123
+ if self._async_client is None:
124
+ self._async_client = httpx.AsyncClient(
125
+ **CLIENT_SETTINGS,
126
+ transport=httpx.AsyncHTTPTransport(
127
+ retries=DEFAULT_MAX_RETRIES, http2=True
128
+ ),
129
+ )
130
+ return self._async_client
131
+ else:
132
+ if self._async_client is None:
133
+ self._async_client = httpx.AsyncClient(
134
+ **CLIENT_SETTINGS,
135
+ transport=httpx.AsyncHTTPTransport(
136
+ retries=DEFAULT_MAX_RETRIES, http2=True
137
+ ),
138
+ )
139
+ return self._async_client
128
140
 
129
141
  def cleanup(self):
130
142
  try:
@@ -196,7 +208,7 @@ class MaitaiClient:
196
208
 
197
209
  def init_sdk(self, api_key: str, host: str):
198
210
  if tracer:
199
- with tracer.trace("init_sdk"):
211
+ with tracer.start_as_current_span("init_sdk"):
200
212
  return self._init_sdk(api_key, host)
201
213
  return self._init_sdk(api_key, host)
202
214
 
@@ -12,9 +12,9 @@ class Completions(MaitaiClient):
12
12
  def __init__(self, config: Config):
13
13
  super().__init__()
14
14
  self.config = config
15
- # Initialize OpenAI client with Maitai orchestration endpoint
15
+ # Initialize OpenAI client with Maitai agent endpoint
16
16
  self._openai_client = openai.OpenAI(
17
- base_url=f"{self.config.maitai_orchestration_host.rstrip('/')}/orchestration",
17
+ base_url=f"{self.config.maitai_orchestration_host.rstrip('/')}/agent",
18
18
  api_key=self.config.api_key,
19
19
  default_headers={"x-api-key": self.config.api_key},
20
20
  )
@@ -12,9 +12,9 @@ class AsyncCompletions(MaitaiClient):
12
12
  def __init__(self, config: Config):
13
13
  super().__init__()
14
14
  self.config = config
15
- # Initialize OpenAI client with Maitai orchestration endpoint
15
+ # Initialize OpenAI client with Maitai agent endpoint
16
16
  self._openai_client = openai.AsyncOpenAI(
17
- base_url=f"{self.config.maitai_orchestration_host.rstrip('/')}/orchestration",
17
+ base_url=f"{self.config.maitai_orchestration_host.rstrip('/')}/agent",
18
18
  api_key=self.config.api_key,
19
19
  default_headers={"x-api-key": self.config.api_key},
20
20
  )
@@ -66,3 +66,10 @@ class AgentActionInvocationMode(Enum):
66
66
 
67
67
  FOREGROUND = "foreground" # Output is surfaced to the user (response-facing)
68
68
  BACKGROUND = "background" # Updates context/state only (not directly surfaced)
69
+
70
+
71
+ class RebuildMode(Enum):
72
+ """Mode for rebuilding agent strategy."""
73
+
74
+ RESUME = "resume" # Keep completed milestones and append new ones
75
+ RESTART = "restart" # Replace all milestones with fresh ones
@@ -19,7 +19,7 @@ from pydantic import AliasChoices, BaseModel, Field
19
19
  from maitai.models.agent.base import Agent
20
20
  from maitai.models.chat import ChatCompletionParams, ChatCompletionResponse
21
21
 
22
- from .enum import ActionResultType, LoopStatus, ToolType
22
+ from .enum import ActionResultType, LoopStatus, RebuildMode, ToolType
23
23
 
24
24
 
25
25
  class DirectToolResult(BaseModel):
@@ -868,6 +868,18 @@ class Milestone(BaseModel):
868
868
  completed: bool = Field(default=False)
869
869
 
870
870
 
871
+ class RebuildStrategyDecision(BaseModel):
872
+ """Decision result from ProgressManager.should_rebuild_strategy().
873
+
874
+ Encapsulates whether a strategy rebuild is needed, along with
875
+ the feedback and mode to use.
876
+ """
877
+
878
+ should_rebuild: bool = Field(default=False)
879
+ feedback: Optional[str] = Field(default=None)
880
+ mode: RebuildMode = Field(default=RebuildMode.RESUME)
881
+
882
+
871
883
  class Strategy(BaseModel):
872
884
  """Agent strategy information."""
873
885
 
@@ -1028,16 +1040,45 @@ class Strategy(BaseModel):
1028
1040
  feedback: str,
1029
1041
  new_requirements: str,
1030
1042
  scratchpad: str,
1043
+ mode: str = "resume",
1044
+ completed_milestones: Optional[List["Milestone"]] = None,
1031
1045
  ) -> str:
1032
- """Generate a user message for rebuilding the strategy."""
1033
- return dedent(
1034
- f"""
1035
- <original_strategy>\n{original_strategy}\n</original_strategy>
1036
- <feedback>\n{feedback}\n</feedback>
1037
- <new_requirements>\n{new_requirements}\n</new_requirements>
1038
- <scratchpad>\n{scratchpad}\n</scratchpad>
1046
+ """Generate a user message for rebuilding the strategy.
1047
+
1048
+ Args:
1049
+ original_strategy: The original strategy text
1050
+ feedback: Feedback about why rebuild is needed
1051
+ new_requirements: New requirements to incorporate
1052
+ scratchpad: Current scratchpad contents
1053
+ mode: "resume" to keep completed work, "restart" to start fresh
1054
+ completed_milestones: List of completed milestones (for resume mode)
1039
1055
  """
1040
- ).strip()
1056
+ blocks = [
1057
+ f"<original_strategy>\n{original_strategy}\n</original_strategy>",
1058
+ f"<feedback>\n{feedback}\n</feedback>",
1059
+ f"<new_requirements>\n{new_requirements}\n</new_requirements>",
1060
+ f"<scratchpad>\n{scratchpad}\n</scratchpad>",
1061
+ ]
1062
+
1063
+ if mode == "resume" and completed_milestones:
1064
+ completed_text = "\n".join(
1065
+ f"{i}. [✓] {m.title}" for i, m in enumerate(completed_milestones, 1)
1066
+ )
1067
+ blocks.append(
1068
+ f"<completed_milestones>\n{completed_text}\n</completed_milestones>"
1069
+ )
1070
+ blocks.append(
1071
+ "<mode>\nRESUME: The milestones listed in <completed_milestones> have already been completed. "
1072
+ "Generate ONLY the remaining milestones needed to complete the task. "
1073
+ "Do NOT repeat or include any completed work.\n</mode>"
1074
+ )
1075
+ else:
1076
+ blocks.append(
1077
+ "<mode>\nRESTART: Generate a completely new strategy from scratch. "
1078
+ "Ignore any previous milestones.\n</mode>"
1079
+ )
1080
+
1081
+ return "\n".join(blocks)
1041
1082
 
1042
1083
 
1043
1084
  class StrategyPrompts(BaseModel):
@@ -1,3 +1,3 @@
1
- version = "1.2.29b0"
1
+ version = "1.2.30"
2
2
  if __name__ == "__main__":
3
3
  print(version)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: maitai-python
3
- Version: 1.2.29b0
3
+ Version: 1.2.30
4
4
  Summary: Maitai SDK for Python
5
5
  Home-page: https://docs.trymaitai.ai
6
6
  Author: Maitai