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.
- {maitai_python-1.2.29b0 → maitai_python-1.2.30}/PKG-INFO +1 -1
- {maitai_python-1.2.29b0 → maitai_python-1.2.30}/maitai/_maitai.py +7 -10
- {maitai_python-1.2.29b0 → maitai_python-1.2.30}/maitai/_maitai_async.py +7 -9
- {maitai_python-1.2.29b0 → maitai_python-1.2.30}/maitai/_maitai_client.py +30 -18
- {maitai_python-1.2.29b0 → maitai_python-1.2.30}/maitai/agent/_completions.py +2 -2
- {maitai_python-1.2.29b0 → maitai_python-1.2.30}/maitai/agent/_completions_async.py +2 -2
- {maitai_python-1.2.29b0 → maitai_python-1.2.30}/maitai/models/agent/enum.py +7 -0
- {maitai_python-1.2.29b0 → maitai_python-1.2.30}/maitai/models/agent/extended.py +50 -9
- {maitai_python-1.2.29b0 → maitai_python-1.2.30}/maitai_common/version.py +1 -1
- {maitai_python-1.2.29b0 → maitai_python-1.2.30}/maitai_python.egg-info/PKG-INFO +1 -1
- {maitai_python-1.2.29b0 → maitai_python-1.2.30}/README.md +0 -0
- {maitai_python-1.2.29b0 → maitai_python-1.2.30}/maitai/__init__.py +0 -0
- {maitai_python-1.2.29b0 → maitai_python-1.2.30}/maitai/_config.py +0 -0
- {maitai_python-1.2.29b0 → maitai_python-1.2.30}/maitai/_config_listener.py +0 -0
- {maitai_python-1.2.29b0 → maitai_python-1.2.30}/maitai/_context.py +0 -0
- {maitai_python-1.2.29b0 → maitai_python-1.2.30}/maitai/_evaluator.py +0 -0
- {maitai_python-1.2.29b0 → maitai_python-1.2.30}/maitai/_inference.py +0 -0
- {maitai_python-1.2.29b0 → maitai_python-1.2.30}/maitai/_pydantic.py +0 -0
- {maitai_python-1.2.29b0 → maitai_python-1.2.30}/maitai/_types.py +0 -0
- {maitai_python-1.2.29b0 → maitai_python-1.2.30}/maitai/_utils.py +0 -0
- {maitai_python-1.2.29b0 → maitai_python-1.2.30}/maitai/agent/__init__.py +0 -0
- {maitai_python-1.2.29b0 → maitai_python-1.2.30}/maitai/chat/__init__.py +0 -0
- {maitai_python-1.2.29b0 → maitai_python-1.2.30}/maitai/chat/_completions.py +0 -0
- {maitai_python-1.2.29b0 → maitai_python-1.2.30}/maitai/chat/_completions_async.py +0 -0
- {maitai_python-1.2.29b0 → maitai_python-1.2.30}/maitai/exceptions.py +0 -0
- {maitai_python-1.2.29b0 → maitai_python-1.2.30}/maitai/models/__init__.py +0 -0
- {maitai_python-1.2.29b0 → maitai_python-1.2.30}/maitai/models/agent/__init__.py +0 -0
- {maitai_python-1.2.29b0 → maitai_python-1.2.30}/maitai/models/agent/base.py +0 -0
- {maitai_python-1.2.29b0 → maitai_python-1.2.30}/maitai/models/agent_action.py +0 -0
- {maitai_python-1.2.29b0 → maitai_python-1.2.30}/maitai/models/agent_routing.py +0 -0
- {maitai_python-1.2.29b0 → maitai_python-1.2.30}/maitai/models/application.py +0 -0
- {maitai_python-1.2.29b0 → maitai_python-1.2.30}/maitai/models/chat.py +0 -0
- {maitai_python-1.2.29b0 → maitai_python-1.2.30}/maitai/models/config.py +0 -0
- {maitai_python-1.2.29b0 → maitai_python-1.2.30}/maitai/models/event.py +0 -0
- {maitai_python-1.2.29b0 → maitai_python-1.2.30}/maitai/models/inference.py +0 -0
- {maitai_python-1.2.29b0 → maitai_python-1.2.30}/maitai/models/key.py +0 -0
- {maitai_python-1.2.29b0 → maitai_python-1.2.30}/maitai/models/metric.py +0 -0
- {maitai_python-1.2.29b0 → maitai_python-1.2.30}/maitai/models/sentinel.py +0 -0
- {maitai_python-1.2.29b0 → maitai_python-1.2.30}/maitai/tools/__init__.py +0 -0
- {maitai_python-1.2.29b0 → maitai_python-1.2.30}/maitai/transcriptions/__init__.py +0 -0
- {maitai_python-1.2.29b0 → maitai_python-1.2.30}/maitai/transcriptions/_transcriptions.py +0 -0
- {maitai_python-1.2.29b0 → maitai_python-1.2.30}/maitai/transcriptions/_transcriptions_async.py +0 -0
- {maitai_python-1.2.29b0 → maitai_python-1.2.30}/maitai_common/__init__.py +0 -0
- {maitai_python-1.2.29b0 → maitai_python-1.2.30}/maitai_common/config/__init__.py +0 -0
- {maitai_python-1.2.29b0 → maitai_python-1.2.30}/maitai_common/config/config_service.py +0 -0
- {maitai_python-1.2.29b0 → maitai_python-1.2.30}/maitai_python.egg-info/SOURCES.txt +0 -0
- {maitai_python-1.2.29b0 → maitai_python-1.2.30}/maitai_python.egg-info/dependency_links.txt +0 -0
- {maitai_python-1.2.29b0 → maitai_python-1.2.30}/maitai_python.egg-info/requires.txt +0 -0
- {maitai_python-1.2.29b0 → maitai_python-1.2.30}/maitai_python.egg-info/top_level.txt +0 -0
- {maitai_python-1.2.29b0 → maitai_python-1.2.30}/setup.cfg +0 -0
- {maitai_python-1.2.29b0 → maitai_python-1.2.30}/setup.py +0 -0
|
@@ -150,16 +150,13 @@ class Maitai:
|
|
|
150
150
|
http_client=http_client,
|
|
151
151
|
_strict_response_validation=_strict_response_validation,
|
|
152
152
|
)
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
self.
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
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
|
-
|
|
153
|
-
self.
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
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
|
|
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
|
|
86
|
-
|
|
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.
|
|
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.
|
|
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
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
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.
|
|
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
|
|
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('/')}/
|
|
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
|
|
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('/')}/
|
|
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
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
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
|
-
|
|
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):
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{maitai_python-1.2.29b0 → maitai_python-1.2.30}/maitai/transcriptions/_transcriptions_async.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|