agentex-sdk 0.4.22__py3-none-any.whl → 0.4.24__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.
- agentex/__init__.py +3 -1
- agentex/_base_client.py +9 -9
- agentex/_client.py +12 -12
- agentex/_models.py +10 -4
- agentex/_qs.py +7 -7
- agentex/_types.py +18 -11
- agentex/_utils/_transform.py +2 -2
- agentex/_utils/_utils.py +4 -4
- agentex/_version.py +1 -1
- agentex/lib/cli/handlers/deploy_handlers.py +1 -1
- agentex/lib/cli/handlers/run_handlers.py +4 -0
- agentex/lib/cli/templates/temporal/manifest.yaml.j2 +4 -0
- agentex/lib/core/services/adk/providers/openai.py +56 -83
- agentex/lib/core/temporal/workers/worker.py +2 -2
- agentex/lib/core/tracing/processors/sgp_tracing_processor.py +33 -0
- agentex/lib/environment_variables.py +5 -0
- agentex/lib/types/agent_configs.py +5 -0
- agentex/lib/utils/dev_tools/async_messages.py +13 -6
- agentex/resources/agents.py +25 -25
- agentex/resources/events.py +9 -9
- agentex/resources/messages/batch.py +5 -5
- agentex/resources/messages/messages.py +15 -15
- agentex/resources/spans.py +39 -39
- agentex/resources/states.py +15 -15
- agentex/resources/tasks.py +19 -19
- agentex/resources/tracker.py +17 -17
- {agentex_sdk-0.4.22.dist-info → agentex_sdk-0.4.24.dist-info}/METADATA +3 -3
- {agentex_sdk-0.4.22.dist-info → agentex_sdk-0.4.24.dist-info}/RECORD +31 -31
- {agentex_sdk-0.4.22.dist-info → agentex_sdk-0.4.24.dist-info}/WHEEL +0 -0
- {agentex_sdk-0.4.22.dist-info → agentex_sdk-0.4.24.dist-info}/entry_points.txt +0 -0
- {agentex_sdk-0.4.22.dist-info → agentex_sdk-0.4.24.dist-info}/licenses/LICENSE +0 -0
agentex/__init__.py
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
import typing as _t
|
4
4
|
|
5
5
|
from . import types
|
6
|
-
from ._types import NOT_GIVEN, Omit, NoneType, NotGiven, Transport, ProxiesTypes
|
6
|
+
from ._types import NOT_GIVEN, Omit, NoneType, NotGiven, Transport, ProxiesTypes, omit, not_given
|
7
7
|
from ._utils import file_from_path
|
8
8
|
from ._client import (
|
9
9
|
ENVIRONMENTS,
|
@@ -49,7 +49,9 @@ __all__ = [
|
|
49
49
|
"ProxiesTypes",
|
50
50
|
"NotGiven",
|
51
51
|
"NOT_GIVEN",
|
52
|
+
"not_given",
|
52
53
|
"Omit",
|
54
|
+
"omit",
|
53
55
|
"AgentexError",
|
54
56
|
"APIError",
|
55
57
|
"APIStatusError",
|
agentex/_base_client.py
CHANGED
@@ -42,7 +42,6 @@ from . import _exceptions
|
|
42
42
|
from ._qs import Querystring
|
43
43
|
from ._files import to_httpx_files, async_to_httpx_files
|
44
44
|
from ._types import (
|
45
|
-
NOT_GIVEN,
|
46
45
|
Body,
|
47
46
|
Omit,
|
48
47
|
Query,
|
@@ -57,6 +56,7 @@ from ._types import (
|
|
57
56
|
RequestOptions,
|
58
57
|
HttpxRequestFiles,
|
59
58
|
ModelBuilderProtocol,
|
59
|
+
not_given,
|
60
60
|
)
|
61
61
|
from ._utils import is_dict, is_list, asyncify, is_given, lru_cache, is_mapping
|
62
62
|
from ._compat import PYDANTIC_V1, model_copy, model_dump
|
@@ -145,9 +145,9 @@ class PageInfo:
|
|
145
145
|
def __init__(
|
146
146
|
self,
|
147
147
|
*,
|
148
|
-
url: URL | NotGiven =
|
149
|
-
json: Body | NotGiven =
|
150
|
-
params: Query | NotGiven =
|
148
|
+
url: URL | NotGiven = not_given,
|
149
|
+
json: Body | NotGiven = not_given,
|
150
|
+
params: Query | NotGiven = not_given,
|
151
151
|
) -> None:
|
152
152
|
self.url = url
|
153
153
|
self.json = json
|
@@ -595,7 +595,7 @@ class BaseClient(Generic[_HttpxClientT, _DefaultStreamT]):
|
|
595
595
|
# we internally support defining a temporary header to override the
|
596
596
|
# default `cast_to` type for use with `.with_raw_response` and `.with_streaming_response`
|
597
597
|
# see _response.py for implementation details
|
598
|
-
override_cast_to = headers.pop(OVERRIDE_CAST_TO_HEADER,
|
598
|
+
override_cast_to = headers.pop(OVERRIDE_CAST_TO_HEADER, not_given)
|
599
599
|
if is_given(override_cast_to):
|
600
600
|
options.headers = headers
|
601
601
|
return cast(Type[ResponseT], override_cast_to)
|
@@ -825,7 +825,7 @@ class SyncAPIClient(BaseClient[httpx.Client, Stream[Any]]):
|
|
825
825
|
version: str,
|
826
826
|
base_url: str | URL,
|
827
827
|
max_retries: int = DEFAULT_MAX_RETRIES,
|
828
|
-
timeout: float | Timeout | None | NotGiven =
|
828
|
+
timeout: float | Timeout | None | NotGiven = not_given,
|
829
829
|
http_client: httpx.Client | None = None,
|
830
830
|
custom_headers: Mapping[str, str] | None = None,
|
831
831
|
custom_query: Mapping[str, object] | None = None,
|
@@ -1356,7 +1356,7 @@ class AsyncAPIClient(BaseClient[httpx.AsyncClient, AsyncStream[Any]]):
|
|
1356
1356
|
base_url: str | URL,
|
1357
1357
|
_strict_response_validation: bool,
|
1358
1358
|
max_retries: int = DEFAULT_MAX_RETRIES,
|
1359
|
-
timeout: float | Timeout | None | NotGiven =
|
1359
|
+
timeout: float | Timeout | None | NotGiven = not_given,
|
1360
1360
|
http_client: httpx.AsyncClient | None = None,
|
1361
1361
|
custom_headers: Mapping[str, str] | None = None,
|
1362
1362
|
custom_query: Mapping[str, object] | None = None,
|
@@ -1818,8 +1818,8 @@ def make_request_options(
|
|
1818
1818
|
extra_query: Query | None = None,
|
1819
1819
|
extra_body: Body | None = None,
|
1820
1820
|
idempotency_key: str | None = None,
|
1821
|
-
timeout: float | httpx.Timeout | None | NotGiven =
|
1822
|
-
post_parser: PostParser | NotGiven =
|
1821
|
+
timeout: float | httpx.Timeout | None | NotGiven = not_given,
|
1822
|
+
post_parser: PostParser | NotGiven = not_given,
|
1823
1823
|
) -> RequestOptions:
|
1824
1824
|
"""Create a dict of type RequestOptions without keys of NotGiven values."""
|
1825
1825
|
options: RequestOptions = {}
|
agentex/_client.py
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
from __future__ import annotations
|
4
4
|
|
5
5
|
import os
|
6
|
-
from typing import Any, Dict,
|
6
|
+
from typing import Any, Dict, Mapping, cast
|
7
7
|
from typing_extensions import Self, Literal, override
|
8
8
|
|
9
9
|
import httpx
|
@@ -11,13 +11,13 @@ import httpx
|
|
11
11
|
from . import _exceptions
|
12
12
|
from ._qs import Querystring
|
13
13
|
from ._types import (
|
14
|
-
NOT_GIVEN,
|
15
14
|
Omit,
|
16
15
|
Timeout,
|
17
16
|
NotGiven,
|
18
17
|
Transport,
|
19
18
|
ProxiesTypes,
|
20
19
|
RequestOptions,
|
20
|
+
not_given,
|
21
21
|
)
|
22
22
|
from ._utils import is_given, get_async_library
|
23
23
|
from ._version import __version__
|
@@ -69,9 +69,9 @@ class Agentex(SyncAPIClient):
|
|
69
69
|
self,
|
70
70
|
*,
|
71
71
|
api_key: str | None = None,
|
72
|
-
environment: Literal["production", "development"] | NotGiven =
|
73
|
-
base_url: str | httpx.URL | None | NotGiven =
|
74
|
-
timeout:
|
72
|
+
environment: Literal["production", "development"] | NotGiven = not_given,
|
73
|
+
base_url: str | httpx.URL | None | NotGiven = not_given,
|
74
|
+
timeout: float | Timeout | None | NotGiven = not_given,
|
75
75
|
max_retries: int = DEFAULT_MAX_RETRIES,
|
76
76
|
default_headers: Mapping[str, str] | None = None,
|
77
77
|
default_query: Mapping[str, object] | None = None,
|
@@ -172,9 +172,9 @@ class Agentex(SyncAPIClient):
|
|
172
172
|
api_key: str | None = None,
|
173
173
|
environment: Literal["production", "development"] | None = None,
|
174
174
|
base_url: str | httpx.URL | None = None,
|
175
|
-
timeout: float | Timeout | None | NotGiven =
|
175
|
+
timeout: float | Timeout | None | NotGiven = not_given,
|
176
176
|
http_client: httpx.Client | None = None,
|
177
|
-
max_retries: int | NotGiven =
|
177
|
+
max_retries: int | NotGiven = not_given,
|
178
178
|
default_headers: Mapping[str, str] | None = None,
|
179
179
|
set_default_headers: Mapping[str, str] | None = None,
|
180
180
|
default_query: Mapping[str, object] | None = None,
|
@@ -273,9 +273,9 @@ class AsyncAgentex(AsyncAPIClient):
|
|
273
273
|
self,
|
274
274
|
*,
|
275
275
|
api_key: str | None = None,
|
276
|
-
environment: Literal["production", "development"] | NotGiven =
|
277
|
-
base_url: str | httpx.URL | None | NotGiven =
|
278
|
-
timeout:
|
276
|
+
environment: Literal["production", "development"] | NotGiven = not_given,
|
277
|
+
base_url: str | httpx.URL | None | NotGiven = not_given,
|
278
|
+
timeout: float | Timeout | None | NotGiven = not_given,
|
279
279
|
max_retries: int = DEFAULT_MAX_RETRIES,
|
280
280
|
default_headers: Mapping[str, str] | None = None,
|
281
281
|
default_query: Mapping[str, object] | None = None,
|
@@ -376,9 +376,9 @@ class AsyncAgentex(AsyncAPIClient):
|
|
376
376
|
api_key: str | None = None,
|
377
377
|
environment: Literal["production", "development"] | None = None,
|
378
378
|
base_url: str | httpx.URL | None = None,
|
379
|
-
timeout: float | Timeout | None | NotGiven =
|
379
|
+
timeout: float | Timeout | None | NotGiven = not_given,
|
380
380
|
http_client: httpx.AsyncClient | None = None,
|
381
|
-
max_retries: int | NotGiven =
|
381
|
+
max_retries: int | NotGiven = not_given,
|
382
382
|
default_headers: Mapping[str, str] | None = None,
|
383
383
|
set_default_headers: Mapping[str, str] | None = None,
|
384
384
|
default_query: Mapping[str, object] | None = None,
|
agentex/_models.py
CHANGED
@@ -256,7 +256,7 @@ class BaseModel(pydantic.BaseModel):
|
|
256
256
|
mode: Literal["json", "python"] | str = "python",
|
257
257
|
include: IncEx | None = None,
|
258
258
|
exclude: IncEx | None = None,
|
259
|
-
by_alias: bool =
|
259
|
+
by_alias: bool | None = None,
|
260
260
|
exclude_unset: bool = False,
|
261
261
|
exclude_defaults: bool = False,
|
262
262
|
exclude_none: bool = False,
|
@@ -264,6 +264,7 @@ class BaseModel(pydantic.BaseModel):
|
|
264
264
|
warnings: bool | Literal["none", "warn", "error"] = True,
|
265
265
|
context: dict[str, Any] | None = None,
|
266
266
|
serialize_as_any: bool = False,
|
267
|
+
fallback: Callable[[Any], Any] | None = None,
|
267
268
|
) -> dict[str, Any]:
|
268
269
|
"""Usage docs: https://docs.pydantic.dev/2.4/concepts/serialization/#modelmodel_dump
|
269
270
|
|
@@ -295,10 +296,12 @@ class BaseModel(pydantic.BaseModel):
|
|
295
296
|
raise ValueError("context is only supported in Pydantic v2")
|
296
297
|
if serialize_as_any != False:
|
297
298
|
raise ValueError("serialize_as_any is only supported in Pydantic v2")
|
299
|
+
if fallback is not None:
|
300
|
+
raise ValueError("fallback is only supported in Pydantic v2")
|
298
301
|
dumped = super().dict( # pyright: ignore[reportDeprecated]
|
299
302
|
include=include,
|
300
303
|
exclude=exclude,
|
301
|
-
by_alias=by_alias,
|
304
|
+
by_alias=by_alias if by_alias is not None else False,
|
302
305
|
exclude_unset=exclude_unset,
|
303
306
|
exclude_defaults=exclude_defaults,
|
304
307
|
exclude_none=exclude_none,
|
@@ -313,13 +316,14 @@ class BaseModel(pydantic.BaseModel):
|
|
313
316
|
indent: int | None = None,
|
314
317
|
include: IncEx | None = None,
|
315
318
|
exclude: IncEx | None = None,
|
316
|
-
by_alias: bool =
|
319
|
+
by_alias: bool | None = None,
|
317
320
|
exclude_unset: bool = False,
|
318
321
|
exclude_defaults: bool = False,
|
319
322
|
exclude_none: bool = False,
|
320
323
|
round_trip: bool = False,
|
321
324
|
warnings: bool | Literal["none", "warn", "error"] = True,
|
322
325
|
context: dict[str, Any] | None = None,
|
326
|
+
fallback: Callable[[Any], Any] | None = None,
|
323
327
|
serialize_as_any: bool = False,
|
324
328
|
) -> str:
|
325
329
|
"""Usage docs: https://docs.pydantic.dev/2.4/concepts/serialization/#modelmodel_dump_json
|
@@ -348,11 +352,13 @@ class BaseModel(pydantic.BaseModel):
|
|
348
352
|
raise ValueError("context is only supported in Pydantic v2")
|
349
353
|
if serialize_as_any != False:
|
350
354
|
raise ValueError("serialize_as_any is only supported in Pydantic v2")
|
355
|
+
if fallback is not None:
|
356
|
+
raise ValueError("fallback is only supported in Pydantic v2")
|
351
357
|
return super().json( # type: ignore[reportDeprecated]
|
352
358
|
indent=indent,
|
353
359
|
include=include,
|
354
360
|
exclude=exclude,
|
355
|
-
by_alias=by_alias,
|
361
|
+
by_alias=by_alias if by_alias is not None else False,
|
356
362
|
exclude_unset=exclude_unset,
|
357
363
|
exclude_defaults=exclude_defaults,
|
358
364
|
exclude_none=exclude_none,
|
agentex/_qs.py
CHANGED
@@ -4,7 +4,7 @@ from typing import Any, List, Tuple, Union, Mapping, TypeVar
|
|
4
4
|
from urllib.parse import parse_qs, urlencode
|
5
5
|
from typing_extensions import Literal, get_args
|
6
6
|
|
7
|
-
from ._types import
|
7
|
+
from ._types import NotGiven, not_given
|
8
8
|
from ._utils import flatten
|
9
9
|
|
10
10
|
_T = TypeVar("_T")
|
@@ -41,8 +41,8 @@ class Querystring:
|
|
41
41
|
self,
|
42
42
|
params: Params,
|
43
43
|
*,
|
44
|
-
array_format:
|
45
|
-
nested_format:
|
44
|
+
array_format: ArrayFormat | NotGiven = not_given,
|
45
|
+
nested_format: NestedFormat | NotGiven = not_given,
|
46
46
|
) -> str:
|
47
47
|
return urlencode(
|
48
48
|
self.stringify_items(
|
@@ -56,8 +56,8 @@ class Querystring:
|
|
56
56
|
self,
|
57
57
|
params: Params,
|
58
58
|
*,
|
59
|
-
array_format:
|
60
|
-
nested_format:
|
59
|
+
array_format: ArrayFormat | NotGiven = not_given,
|
60
|
+
nested_format: NestedFormat | NotGiven = not_given,
|
61
61
|
) -> list[tuple[str, str]]:
|
62
62
|
opts = Options(
|
63
63
|
qs=self,
|
@@ -143,8 +143,8 @@ class Options:
|
|
143
143
|
self,
|
144
144
|
qs: Querystring = _qs,
|
145
145
|
*,
|
146
|
-
array_format:
|
147
|
-
nested_format:
|
146
|
+
array_format: ArrayFormat | NotGiven = not_given,
|
147
|
+
nested_format: NestedFormat | NotGiven = not_given,
|
148
148
|
) -> None:
|
149
149
|
self.array_format = qs.array_format if isinstance(array_format, NotGiven) else array_format
|
150
150
|
self.nested_format = qs.nested_format if isinstance(nested_format, NotGiven) else nested_format
|
agentex/_types.py
CHANGED
@@ -117,18 +117,21 @@ class RequestOptions(TypedDict, total=False):
|
|
117
117
|
# Sentinel class used until PEP 0661 is accepted
|
118
118
|
class NotGiven:
|
119
119
|
"""
|
120
|
-
|
121
|
-
|
120
|
+
For parameters with a meaningful None value, we need to distinguish between
|
121
|
+
the user explicitly passing None, and the user not passing the parameter at
|
122
|
+
all.
|
123
|
+
|
124
|
+
User code shouldn't need to use not_given directly.
|
122
125
|
|
123
126
|
For example:
|
124
127
|
|
125
128
|
```py
|
126
|
-
def
|
129
|
+
def create(timeout: Timeout | None | NotGiven = not_given): ...
|
127
130
|
|
128
131
|
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
+
create(timeout=1) # 1s timeout
|
133
|
+
create(timeout=None) # No timeout
|
134
|
+
create() # Default timeout behavior
|
132
135
|
```
|
133
136
|
"""
|
134
137
|
|
@@ -140,13 +143,14 @@ class NotGiven:
|
|
140
143
|
return "NOT_GIVEN"
|
141
144
|
|
142
145
|
|
143
|
-
|
146
|
+
not_given = NotGiven()
|
147
|
+
# for backwards compatibility:
|
144
148
|
NOT_GIVEN = NotGiven()
|
145
149
|
|
146
150
|
|
147
151
|
class Omit:
|
148
|
-
"""
|
149
|
-
|
152
|
+
"""
|
153
|
+
To explicitly omit something from being sent in a request, use `omit`.
|
150
154
|
|
151
155
|
```py
|
152
156
|
# as the default `Content-Type` header is `application/json` that will be sent
|
@@ -156,8 +160,8 @@ class Omit:
|
|
156
160
|
# to look something like: 'multipart/form-data; boundary=0d8382fcf5f8c3be01ca2e11002d2983'
|
157
161
|
client.post(..., headers={"Content-Type": "multipart/form-data"})
|
158
162
|
|
159
|
-
# instead you can remove the default `application/json` header by passing
|
160
|
-
client.post(..., headers={"Content-Type":
|
163
|
+
# instead you can remove the default `application/json` header by passing omit
|
164
|
+
client.post(..., headers={"Content-Type": omit})
|
161
165
|
```
|
162
166
|
"""
|
163
167
|
|
@@ -165,6 +169,9 @@ class Omit:
|
|
165
169
|
return False
|
166
170
|
|
167
171
|
|
172
|
+
omit = Omit()
|
173
|
+
|
174
|
+
|
168
175
|
@runtime_checkable
|
169
176
|
class ModelBuilderProtocol(Protocol):
|
170
177
|
@classmethod
|
agentex/_utils/_transform.py
CHANGED
@@ -268,7 +268,7 @@ def _transform_typeddict(
|
|
268
268
|
annotations = get_type_hints(expected_type, include_extras=True)
|
269
269
|
for key, value in data.items():
|
270
270
|
if not is_given(value):
|
271
|
-
# we don't need to include
|
271
|
+
# we don't need to include omitted values here as they'll
|
272
272
|
# be stripped out before the request is sent anyway
|
273
273
|
continue
|
274
274
|
|
@@ -434,7 +434,7 @@ async def _async_transform_typeddict(
|
|
434
434
|
annotations = get_type_hints(expected_type, include_extras=True)
|
435
435
|
for key, value in data.items():
|
436
436
|
if not is_given(value):
|
437
|
-
# we don't need to include
|
437
|
+
# we don't need to include omitted values here as they'll
|
438
438
|
# be stripped out before the request is sent anyway
|
439
439
|
continue
|
440
440
|
|
agentex/_utils/_utils.py
CHANGED
@@ -21,7 +21,7 @@ from typing_extensions import TypeGuard
|
|
21
21
|
|
22
22
|
import sniffio
|
23
23
|
|
24
|
-
from .._types import NotGiven, FileTypes,
|
24
|
+
from .._types import Omit, NotGiven, FileTypes, HeadersLike
|
25
25
|
|
26
26
|
_T = TypeVar("_T")
|
27
27
|
_TupleT = TypeVar("_TupleT", bound=Tuple[object, ...])
|
@@ -63,7 +63,7 @@ def _extract_items(
|
|
63
63
|
try:
|
64
64
|
key = path[index]
|
65
65
|
except IndexError:
|
66
|
-
if
|
66
|
+
if not is_given(obj):
|
67
67
|
# no value was provided - we can safely ignore
|
68
68
|
return []
|
69
69
|
|
@@ -126,8 +126,8 @@ def _extract_items(
|
|
126
126
|
return []
|
127
127
|
|
128
128
|
|
129
|
-
def is_given(obj:
|
130
|
-
return not isinstance(obj, NotGiven)
|
129
|
+
def is_given(obj: _T | NotGiven | Omit) -> TypeGuard[_T]:
|
130
|
+
return not isinstance(obj, NotGiven) and not isinstance(obj, Omit)
|
131
131
|
|
132
132
|
|
133
133
|
# Type safe methods for narrowing types with TypeVars.
|
agentex/_version.py
CHANGED
@@ -389,6 +389,10 @@ def create_agent_environment(manifest: AgentManifest) -> dict[str, str]:
|
|
389
389
|
env_vars["WORKFLOW_NAME"] = temporal_config.name
|
390
390
|
env_vars["WORKFLOW_TASK_QUEUE"] = temporal_config.queue_name
|
391
391
|
|
392
|
+
# Set health check port from temporal config
|
393
|
+
if manifest.agent.temporal and manifest.agent.temporal.health_check_port is not None:
|
394
|
+
env_vars["HEALTH_CHECK_PORT"] = str(manifest.agent.temporal.health_check_port)
|
395
|
+
|
392
396
|
if agent_config.env:
|
393
397
|
for key, value in agent_config.env.items():
|
394
398
|
env_vars[key] = value
|
@@ -89,6 +89,10 @@ agent:
|
|
89
89
|
# Convention: <agent_name>_task_queue
|
90
90
|
queue_name: {{ queue_name }}
|
91
91
|
|
92
|
+
# Optional: Health check port for temporal worker
|
93
|
+
# Defaults to 80 if not specified
|
94
|
+
# health_check_port: 80
|
95
|
+
|
92
96
|
# Optional: Credentials mapping
|
93
97
|
# Maps Kubernetes secrets to environment variables
|
94
98
|
# Common credentials include:
|
@@ -12,12 +12,12 @@ from agents.exceptions import InputGuardrailTripwireTriggered, OutputGuardrailTr
|
|
12
12
|
from openai.types.responses import (
|
13
13
|
ResponseCompletedEvent,
|
14
14
|
ResponseTextDeltaEvent,
|
15
|
+
ResponseFunctionToolCall,
|
15
16
|
ResponseFunctionWebSearch,
|
16
17
|
ResponseOutputItemDoneEvent,
|
17
|
-
ResponseReasoningTextDoneEvent,
|
18
18
|
ResponseCodeInterpreterToolCall,
|
19
|
-
|
20
|
-
|
19
|
+
ResponseReasoningSummaryPartDoneEvent,
|
20
|
+
ResponseReasoningSummaryPartAddedEvent,
|
21
21
|
ResponseReasoningSummaryTextDeltaEvent,
|
22
22
|
)
|
23
23
|
|
@@ -29,7 +29,6 @@ from agentex.lib.utils.temporal import heartbeat_if_in_workflow
|
|
29
29
|
from agentex.lib.core.tracing.tracer import AsyncTracer
|
30
30
|
from agentex.types.task_message_delta import (
|
31
31
|
TextDelta,
|
32
|
-
ReasoningContentDelta,
|
33
32
|
ReasoningSummaryDelta,
|
34
33
|
)
|
35
34
|
from agentex.types.task_message_update import (
|
@@ -691,7 +690,7 @@ class OpenAIService:
|
|
691
690
|
if self.agentex_client is None:
|
692
691
|
raise ValueError("Agentex client must be provided for auto_send methods")
|
693
692
|
|
694
|
-
tool_call_map: dict[str,
|
693
|
+
tool_call_map: dict[str, ResponseFunctionToolCall] = {}
|
695
694
|
|
696
695
|
if self.tracer is None:
|
697
696
|
raise RuntimeError("Tracer not initialized - ensure tracer is provided to OpenAIService")
|
@@ -756,6 +755,8 @@ class OpenAIService:
|
|
756
755
|
|
757
756
|
item_id_to_streaming_context: dict[str, StreamingTaskMessageContext] = {}
|
758
757
|
unclosed_item_ids: set[str] = set()
|
758
|
+
# Simple string to accumulate reasoning summary
|
759
|
+
current_reasoning_summary: str = ""
|
759
760
|
|
760
761
|
try:
|
761
762
|
# Process streaming events with TaskMessage creation
|
@@ -848,37 +849,42 @@ class OpenAIService:
|
|
848
849
|
type="delta",
|
849
850
|
),
|
850
851
|
)
|
851
|
-
|
852
|
-
elif isinstance(event.data,
|
853
|
-
#
|
852
|
+
# Reasoning step one: new summary part added
|
853
|
+
elif isinstance(event.data, ResponseReasoningSummaryPartAddedEvent):
|
854
|
+
# We need to create a new streaming context for this reasoning item
|
854
855
|
item_id = event.data.item_id
|
855
|
-
|
856
|
+
|
857
|
+
# Reset the reasoning summary string
|
858
|
+
current_reasoning_summary = ""
|
859
|
+
|
860
|
+
streaming_context = self.streaming_service.streaming_task_message_context(
|
861
|
+
task_id=task_id,
|
862
|
+
initial_content=ReasoningContent(
|
863
|
+
author="agent",
|
864
|
+
summary=[],
|
865
|
+
content=[],
|
866
|
+
type="reasoning",
|
867
|
+
style="active",
|
868
|
+
),
|
869
|
+
)
|
856
870
|
|
857
|
-
#
|
858
|
-
|
859
|
-
|
860
|
-
|
861
|
-
|
862
|
-
|
863
|
-
|
864
|
-
|
865
|
-
|
866
|
-
|
867
|
-
style="active",
|
868
|
-
),
|
869
|
-
)
|
870
|
-
# Open the streaming context
|
871
|
-
item_id_to_streaming_context[item_id] = await streaming_context.open()
|
872
|
-
unclosed_item_ids.add(item_id)
|
873
|
-
else:
|
874
|
-
streaming_context = item_id_to_streaming_context[item_id]
|
871
|
+
# Replace the existing streaming context (if it exists)
|
872
|
+
# Why do we replace? Cause all the reasoning parts use the same item_id!
|
873
|
+
item_id_to_streaming_context[item_id] = await streaming_context.open()
|
874
|
+
unclosed_item_ids.add(item_id)
|
875
|
+
|
876
|
+
# Reasoning step two: handling summary text delta
|
877
|
+
elif isinstance(event.data, ResponseReasoningSummaryTextDeltaEvent):
|
878
|
+
# Accumulate the delta into the string
|
879
|
+
current_reasoning_summary += event.data.delta
|
880
|
+
streaming_context = item_id_to_streaming_context[item_id]
|
875
881
|
|
876
882
|
# Stream the summary delta through the streaming service
|
877
883
|
await streaming_context.stream_update(
|
878
884
|
update=StreamTaskMessageDelta(
|
879
885
|
parent_task_message=streaming_context.task_message,
|
880
886
|
delta=ReasoningSummaryDelta(
|
881
|
-
summary_index=summary_index,
|
887
|
+
summary_index=event.data.summary_index,
|
882
888
|
summary_delta=event.data.delta,
|
883
889
|
type="reasoning_summary",
|
884
890
|
),
|
@@ -886,65 +892,32 @@ class OpenAIService:
|
|
886
892
|
),
|
887
893
|
)
|
888
894
|
|
889
|
-
|
890
|
-
|
891
|
-
|
892
|
-
|
893
|
-
|
894
|
-
#
|
895
|
-
|
896
|
-
|
897
|
-
|
898
|
-
|
899
|
-
|
900
|
-
|
901
|
-
|
902
|
-
|
903
|
-
|
904
|
-
style="active",
|
905
|
-
),
|
906
|
-
)
|
907
|
-
# Open the streaming context
|
908
|
-
item_id_to_streaming_context[item_id] = await streaming_context.open()
|
909
|
-
unclosed_item_ids.add(item_id)
|
910
|
-
else:
|
911
|
-
streaming_context = item_id_to_streaming_context[item_id]
|
912
|
-
|
913
|
-
# Stream the content delta through the streaming service
|
895
|
+
# Reasoning step three: handling summary text done, closing the streaming context
|
896
|
+
elif isinstance(event.data, ResponseReasoningSummaryPartDoneEvent):
|
897
|
+
# Handle reasoning summary text completion
|
898
|
+
streaming_context = item_id_to_streaming_context[item_id]
|
899
|
+
|
900
|
+
# Create the complete reasoning content with the accumulated summary
|
901
|
+
complete_reasoning_content = ReasoningContent(
|
902
|
+
author="agent",
|
903
|
+
summary=[current_reasoning_summary],
|
904
|
+
content=[],
|
905
|
+
type="reasoning",
|
906
|
+
style="static",
|
907
|
+
)
|
908
|
+
|
909
|
+
# Send a full message update with the complete reasoning content
|
914
910
|
await streaming_context.stream_update(
|
915
|
-
update=
|
911
|
+
update=StreamTaskMessageFull(
|
916
912
|
parent_task_message=streaming_context.task_message,
|
917
|
-
|
918
|
-
|
919
|
-
content_delta=event.data.delta,
|
920
|
-
type="reasoning_content",
|
921
|
-
),
|
922
|
-
type="delta",
|
913
|
+
content=complete_reasoning_content,
|
914
|
+
type="full",
|
923
915
|
),
|
924
916
|
)
|
925
|
-
|
926
|
-
|
927
|
-
|
928
|
-
|
929
|
-
summary_index = event.data.summary_index
|
930
|
-
|
931
|
-
# We do NOT close the streaming context here as there can be multiple
|
932
|
-
# reasoning summaries. The context will be closed when the entire
|
933
|
-
# output item is done (ResponseOutputItemDoneEvent)
|
934
|
-
|
935
|
-
# You would think they would use the event ResponseReasoningSummaryPartDoneEvent
|
936
|
-
# to close the streaming context, but they do!!!
|
937
|
-
# They output both a ResponseReasoningSummaryTextDoneEvent and a ResponseReasoningSummaryPartDoneEvent
|
938
|
-
# I have no idea why they do this.
|
939
|
-
|
940
|
-
elif isinstance(event.data, ResponseReasoningTextDoneEvent):
|
941
|
-
# Handle reasoning content text completion
|
942
|
-
item_id = event.data.item_id
|
943
|
-
content_index = event.data.content_index
|
944
|
-
|
945
|
-
# We do NOT close the streaming context here as there can be multiple
|
946
|
-
# reasoning content texts. The context will be closed when the entire
|
947
|
-
# output item is done (ResponseOutputItemDoneEvent)
|
917
|
+
|
918
|
+
await streaming_context.close()
|
919
|
+
unclosed_item_ids.discard(item_id)
|
920
|
+
|
948
921
|
|
949
922
|
elif isinstance(event.data, ResponseOutputItemDoneEvent):
|
950
923
|
# Handle item completion
|
@@ -112,7 +112,7 @@ class AgentexWorker:
|
|
112
112
|
task_queue,
|
113
113
|
max_workers: int = 10,
|
114
114
|
max_concurrent_activities: int = 10,
|
115
|
-
health_check_port: int =
|
115
|
+
health_check_port: int | None = None,
|
116
116
|
plugins: list = [],
|
117
117
|
):
|
118
118
|
self.task_queue = task_queue
|
@@ -121,7 +121,7 @@ class AgentexWorker:
|
|
121
121
|
self.max_concurrent_activities = max_concurrent_activities
|
122
122
|
self.health_check_server_running = False
|
123
123
|
self.healthy = False
|
124
|
-
self.health_check_port = health_check_port
|
124
|
+
self.health_check_port = health_check_port if health_check_port is not None else EnvironmentVariables.refresh().HEALTH_CHECK_PORT
|
125
125
|
self.plugins = plugins
|
126
126
|
|
127
127
|
@overload
|